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

时间:2019-06-14 15:08:23

标签: python opencv image-processing

我有一个黑白图像,如何识别输入图像中的楔形,如标记图像所示?

输入图片

Input image

在图像上标记的楔形物

Wedges marked on image

1 个答案:

答案 0 :(得分:2)

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)