我有一个黑白图像,如何识别输入图像中的楔形,如标记图像所示?
输入图片
在图像上标记的楔形物
答案 0 :(得分:2)
您可以使用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)