enter image description hereI have been trying to identify the check-boxes in a form. I am able to find the contours of the check-boxes and extract them. I want them to have an order such that they move in a left to right and top to bottom fashion.
I cropped the contours that matched the check-boxes in the form. I want to identify the check-boxes with the key associated.
This sort the contours
def sort_contours(cnts, method="left-to-right"):
# initialize the reverse flag and sort index
reverse = False
i = 0
# handle if we need to sort in reverse
if method == "right-to-left" or method == "bottom-to-top":
reverse = True
# handle if we are sorting against the y-coordinate rather than
# the x-coordinate of the bounding box
if method == "top-to-bottom" or method == "bottom-to-top":
i = 1
# construct the list of bounding boxes and sort them from top to
# bottom
boundingBoxes = [cv2.boundingRect(c) for c in cnts]
(cnts, boundingBoxes) = zip(*sorted(zip(cnts, boundingBoxes),
key=lambda b: b[1][i], reverse=reverse))
# return the list of sorted contours
return cnts
THIS GIVES THE CONTOURS IN THE IMAGE
[for c in sorted_cnts :
peri = cv2.arcLength(c, True)
approx = cv2.approxPolyDP(c, 0.035 * peri, True)
(x, y, w, h) = cv2.boundingRect(approx)
aspect_ratio = w / float(h)
area = cv2.contourArea(c)
if area < threshold_max_area and area > threshold_min_area and (aspect_ratio >= 0.9 and aspect_ratio <= 1):
cv2.drawContours(original_image,\[c\], 0, (0,255,0), 3)
x,y,w,h = cv2.boundingRect(c)
roi=original_image\[y:y+h,x:x+w\]
cv2.imwrite(str(idx) + '.jpg', roi)
print(x,y,w,h)
checkbox_contours.append(c)][1]
I am trying to find the key along with checkbox and its status
Aucun commentaire:
Enregistrer un commentaire