python - 发现轮廓不准确

标签 python opencv

我有一个问题要查找该图像的轮廓,我使用了 findcontour 不是很准确,我做错了吗?

Here's my result but its not accurate.

Here's the image I've used

gs = cv2.cvtColor(img,cv2.COLOR_RGB2GRAY)
blur = cv2.GaussianBlur(gs, (3,3),0)
ret_otsu,im_bw_otsu = cv2.threshold(blur,0,255,cv2.THRESH_BINARY_INV+cv2.THRESH_OTSU)

kernel = np.ones((50,50),np.uint8)
closing = cv2.morphologyEx(im_bw_otsu, cv2.MORPH_CLOSE, kernel)
_, contours, hierarchy = cv2.findContours(closing,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)

plottedContour = cv2.drawContours(gs,contours,-1,(0,255,0),2)
cv2.imshow('CONTOUR',plottedContour)

最佳答案

看起来您可能想查看其他轮廓,

cv2.drawContours(gs,contours,-1,(0,255,0),2)
cv2.drawContours(gs,contours,0,(0,255,0),2)
cv2.drawContours(gs,contours,1,(0,255,0),2)
cv2.drawContours(gs,contours,2,(0,255,0),2)
...

关于python - 发现轮廓不准确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60178751/

相关文章:

python - 等效于 Python 的 OpenCV 中的 FileNotFoundError

python - 使用像素坐标 (OpenCV) 在图像上绘制多个标记

python - OpenCV Python : Draw minAreaRect ( RotatedRect not implemented)

python - 使用 pandas df 旋转 sns 热图

python - 如何唯一化大文本文件内容

python - 如何连接从 python permutations() 返回的数字?

python - tkinter columconfigure 和 rowconfigure

python - 使用 mplfinance/matplotlib 时可能出现内存泄漏。如何解决?

opencv - 使用 cvSetMouseCallback 处理鼠标事件

python - 在python中从数独难题中提取网格