我的工作:
在这一点上,我想我可以通过使用层次结构和轮廓找到它:下面是我的工作
for i in range (len( contours_region)): #I already have X,Y,W,H of the checkbox through
#print(i) #cv2.connectedComponentsWithStats
x = contours_region[i][0][1] #when detecting checkbox
x_1 = contours_region[i][2][1]
y = contours_region[i][0][0]
y_1 = contours_region[i][2][0]
image_copy= image.copy()
X,Y,W,H = contours_info[i]
cv2.drawContours(image_copy, [numpy.array([[[X,Y]],[[X+W,Y]],[[X+W,Y+H]],[[X,Y+H]]])], 0, (0,0,255),2)
gray = cv2.cvtColor(image_copy, cv2.COLOR_BGR2GRAY)
ret,bw = cv2.threshold(gray,220,255,cv2.THRESH_BINARY_INV)
contours,hierarchy = cv2.findContours(bw[x:x_1, y:y_1], cv2.RETR_CCOMP,1)
print('-----Hierarchy-----')
print(hierarchy)
print('-----Number of Contours : '+ str(len(contours)))
cv2.imshow('a', image_copy)
cv2.waitKey(0)
Run Code Online (Sandbox Code Playgroud)
我得到了这个结果(一些高轮廓,一些高层次)
Run Code Online (Sandbox Code Playgroud)-----Hierarchy----- [[[-1 -1 1 -1] [ 2 -1 -1 0] …