使用OpenCV从二进制图像中分割楔形。

3

我有一张黑白图片,如何识别输入图像中的楔形部分,就像标记的图像那样?

输入图像

输入图像

标记在图片上的楔形部分

标记在图片上的楔形部分

1个回答

1

enter image description here

你可以使用findContours()函数来检测边界框和轮廓。
import cv2
import numpy as np

image = cv2.imread('2.png')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

# Find contours
cnts = cv2.findContours(gray, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if len(cnts) == 2 else cnts[1]

for c in cnts:
    cv2.drawContours(image,[c], 0, (0,255,0), 2)

cv2.imshow('image', image)
cv2.imwrite('image.png', image)
cv2.waitKey(0)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接