繁体   English   中英

图像python opencv中的轮廓检测有缺陷

[英]Flawed contour detection in an image python opencv

我想在下图中检测到巨大的黑色斑点的轮廓:

在此处输入图片说明

因此,我使用Canny边缘检测通过以下代码查找边缘:

edged = cv2.Canny(image, 30, 200)

在此处输入图片说明

然后,当我尝试找到轮廓时,它只给我一半的斑点。

在此处输入图片说明

这是我用来查找轮廓的代码:

# find contours in the edged image, keep only the largest
# ones, and initialize our screen contour
(cnts, _) = cv2.findContours(image.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
cnts = sorted(cnts, key = cv2.contourArea, reverse = True)[:10]

# Scan the contours for largest item
array_sizes = []

for numpoints in cnts:
    array_sizes.append(len(numpoints))

largest = max(array_sizes)
second = second_largest(array_sizes)
index_of_object = array_sizes.index(largest)

# Largest detected contour
screenCnt = cnts[index_of_object] 

我可以对原始图像进行任何更改,以便对大的黑色斑点进行全面,更准确的检测吗? 感谢所有帮助。

问题出在您的工作流程中。

从您的处理中删除Canny运算符。 它将为您提供来自斑点的边缘图像。 一旦使用ContourFinder处理Canny图像,它将把边缘段视为对象。 您最大的轮廓将是最长的边缘段。 如果放大您的Canny图像,您会发现当前结果结束时存在间隙。

要获取斑点的轮廓,请跳过Canny。 如果findContours将白色视为前景,则可能必须反转图像。

请获得对这些方法的一些知识和理解,以免再次遇到此类陷阱。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM