首先,我检测到图像右侧的20个黑框,然后将x和宽度添加到列表中:image = cv2.imread(args["image"])
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
(_, thresh) = cv2.threshold(gray, 220, 255,cv2.THRESH_BINARY)
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (1, 1))
closed = cv2.morphologyEx(thresh, cv2.MORPH_CLOSE, kernel)
dilation = cv2.dilate(closed,None,iterations = 5)
(_,contours,_)=cv2.findContours(dilation.copy(),cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)
sorted_rows = sorted(contours, key = cv2.contourArea, reverse = True)[1:21]
for idx,row in enumerate(sorted_rows):
(_x,y,w,h) = cv2.boundingRect(row)
rows.append([(y),(y+h)])
然后我检测到五列:(_, thresh) = cv2.threshold(gray, 127, 255,cv2.THRESH_BINARY)
closed = cv2.erode(thresh, None, iterations = 4)
(_,contours,_)=cv2.