Opencv findContours()在没有轮廓的地方绘制轮廓线

时间:2020-05-29 18:48:32

标签: python opencv image-processing

我是计算机视觉的新手。由于某种原因,findContours函数会在没有轮廓的地方绘制所有这些弯曲的线。

这是我的代码和输出:

gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(gray, (9, 9), 0)
retval, thresh = cv2.threshold(blurred, thresh_val, 255, cv2.THRESH_BINARY)

contours, hierarchy = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
cv2.drawContours(crop, contours, -1, (0, 255, 0), 2)

所以我输入了这张裁剪的图像: inputted image

然后添加阈值: thresholding

当我尝试绘制轮廓时,它会输出以下信息: contours

我尝试使用cv2.morphologyEx(thresh, cv2.MORPH_OPEN, kernel),它输出: countours with morph

有人知道如何解决这个问题并摆脱那些杂散的轮廓吗?在我看来,阈值非常清晰。谢谢!

0 个答案:

没有答案