我正在尝试查找/计算下一张图像中的轮廓区域:
目标是删除您在图像中可以看到的所有点,因此斑点的轮廓面积小于我给出的值。
我该如何设置这个?
这是我使用的代码...
import cv2
im = cv2.imread('source.png')
imgray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
ret,thresh = cv2.threshold(imgray,127,255,0)
image, contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
img = cv2.drawContours(im, contours, -1, (0,255,0), 1)
cv2.imshow('contour',img)
cv2.waitKey(0)
cv2.imwrite('contour.png',img)
Run Code Online (Sandbox Code Playgroud)
...这是源图像:
谢谢
您可以使用cv2.contourArea()来决定绘制哪一个:
for contour in contours:
if cv2.contourArea(contour) < 80:
cv2.drawContours(im, contour, -1, (255, 255, 255), 3)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
20521 次 |
| 最近记录: |