admin管理员组文章数量:1388835
I would like to make a detection of some blackspots of a surface I have. But after trying to detect contours, I capture small blackspots (you can see them in the output as little white points) and not the biggers ones as needed too. The advantage of this algorithm is that it does not detect the contours of the frame as it may happen with some images I have. But still, I have to detect the big blackspots too. Can someone help me please how to rectify to detect all the blackspots ? Here is a snippet of my solution:
for idx, im, path in zip(range(len(images)), images, paths): # (786, 1044)
# apply thresholding
_, binary_global = cv2.threshold(im, 127, 255, cv2.THRESH_BINARY)
mask = np.zeros(im.shape, dtype=im.dtype)
cont = cv2.findContours(binary_global, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
cont = cont[0] if len(cont) == 2 else cont[1]
# print(cont)
for c in cont:
area = cv2.contourArea(c)
if area < 500:
cv2.drawContours(mask, [c], -1, (255, 255, 255), -1)
print(mask.shape)
removed_border = cv2.bitwise_and(im, im, mask=mask)
cv2.imshow("Result", removed_border)
cv2.waitKey(0)
本文标签: pythonEdge detection problem about the size of targetStack Overflow
版权声明:本文标题:python - Edge detection: problem about the size of target - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744544618a2611822.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论