python opencv 凸包
【摘要】
# -*- coding: UTF-8 -*-import datetime import cv2import numpy as npimport os def get_convexHull(src2): h,w=src2.shape[:2] gray = cv2.cvtColor(src2, cv2.COLOR_BGR2GRAY) # 二值化 ret, ...
# -*- coding: UTF-8 -*-
import datetime
import cv2
import numpy as np
import os
def get_convexHull(src2):
h,w=src2.shape[:2]
gray = cv2.cvtColor(src2, cv2.COLOR_BGR2GRAY)
# 二值化
ret, binary = cv2.threshold(gray, 125, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)
# 获取结构元素
k = cv2.getStructuringElement(cv2.MORPH_RECT, (3, 3))
# 开操作
binary = cv2.morphologyEx(binary, cv2.MORPH_OPEN, k)
cv2.imshow("binary", binary)
# 轮廓发现
contours, hierarchy = cv2.findContours(binary, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
for c in range(len(contours)):
# 是否为凸包
ret = cv2.isContourConvex(contours[c])
if not ret:
# 凸包检测
points = cv2.convexHull(contours[c])
hull_area = cv2.contourArea(points)
if hull_area<100*100:
continue
if hull_area>(0.3*w*h):
co
文章来源: blog.csdn.net,作者:网奇,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/jacke121/article/details/109683201
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)