我正在使用Canny边缘检测,并希望在检测到的边缘周围创建一个边界框,以便每个单词都被单个边界框覆盖。
Canny Edge输出-
Canny边缘输出周围的边界框-
我已经尝试过以下方法
contours,hierarchy=cv2.findContours(edged,cv2.RETR_LIST,cv2.CHAIN_APPROX_NONE)
boundRect = [None]*len(contours)
for i, c in enumerate(contours):
contours_poly = cv2.approxPolyDP(c, 3, True)
boundRect[i] = cv2.boundingRect(contours_poly)
for i in range(len(contours)):
cv2.rectangle(image, (int(boundRect[i][0]), int(boundRect[i][1])), (int(boundRect[i][0]+boundRect[i][2]), int(boundRect[i][1]+boundRect[i][3])), (0,0,0), 2)
但是,通过这种方法,每个字母分别获得边界框。
您可能需要找到轮廓,然后应用边界框以下链接可以帮助