Python 如何使convexHull在较小的间隔内工作?

Python 如何使convexHull在较小的间隔内工作?,python,opencv,convex-hull,convexity-defects,Python,Opencv,Convex Hull,Convexity Defects,我想找出一个边缘缺陷。我正在使用预先制作的函数convxhull,但它跳过了我正在搜索的缺陷。像这样: 我希望convexHull函数以较小的间隔运行,这样它就不会跳过轮廓上可能存在的缺陷。像这样: 简而言之,我的代码是这样的: import cv2 image = cv2.imread("path to where you store the picture") image2 = image.copy() imgray = cv2.cvtColor(image, cv2.COLOR_B

我想找出一个边缘缺陷。我正在使用预先制作的函数convxhull,但它跳过了我正在搜索的缺陷。像这样:

我希望convexHull函数以较小的间隔运行,这样它就不会跳过轮廓上可能存在的缺陷。像这样:

简而言之,我的代码是这样的:

import cv2

image = cv2.imread("path to where you store the picture")
image2 = image.copy()

imgray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) 
ret, thresh = cv2.threshold(imgray, 70, 255, 0) 
im2, contours, hierarchy = cv2.findContours(mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)


# This is where the problem begins - after the outermost contour of the picture is found:

cnt = contours[0]
hull = cv2.convexHull(cnt, returnPoints=False)
defects = cv2.convexityDefects(cnt, hull)
for x in range(defects.shape[0]):
    s, e, f, d = defects[x, 0]
    if 900 <= d:
        far = tuple(cnt[f][0])
        cv2.circle(image2, far, 40, [0, 0, 255], 5)
        start = tuple(cnt[s][0])
        end = tuple(cnt[e][0])
        cv2.line(image2, start, end, [0, 255, 0], 2)
    else:
        continue
导入cv2
image=cv2.imread(“存储图片的路径”)
image2=image.copy()
imgray=cv2.cvt颜色(图像,cv2.COLOR\u bgr2灰色)
ret,thresh=cv2。阈值(imgray,70255,0)
im2,轮廓,层次=cv2.findContours(掩码,cv2.RETR\u树,cv2.CHAIN\u近似值\u简单)
#这就是问题开始的地方-在找到图片的最外轮廓后:
cnt=等高线[0]
外壳=cv2.凸形外壳(cnt,返回点=假)
缺陷=cv2.凸面缺陷(碳纳米管、外壳)
对于范围内的x(缺陷形状[0]):
s、 e,f,d=缺陷[x,0]
如果这不是一个-,您不显示什么是
main\u程序.helpers
,也不包括可以测试它的样本输入。这不是一个-,您不显示什么是
main\u程序.helpers,也不包括可以测试它的样本输入。