Python查找轮廓并绘制轮廓函数错误

问题描述 投票:0回答:1

我目前正在研究检测图像上的缺陷的项目。“在我应用阈值函数后的图像”

轮廓未连接...我不知道为什么它们是离散点

“轮廓”

这是我的代码:

   ret, thresh1 = cv2.threshold(img, 95, 255, cv2.THRESH_BINARY)
   cnts= cv2.findContours(thresh1,cv2.RETR_LIST, cv2.CHAIN_APPROX_NONE)[-2]
   cv2.drawContours(img, cnts, -1, (255,255,0), 3)

同样len(cnts)功能没有返回正确数量的白点...

python opencv image-processing contour
1个回答
0
投票

[发现轮廓也可能在挖孔。试试这个,看看是否能解决您的问题。

ret, thresh1 = cv2.threshold(img, 95, 255, cv2.THRESH_BINARY)
cnts= cv2.findContours(thresh1,cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)[-2]
cv2.drawContours(img, cnts, -1, (255,255,0), 3)
© www.soinside.com 2019 - 2024. All rights reserved.