I have obtained region of interests through mouse clicks with OpenCV as
roi = [[(276, 756), (940, 828), 'text', 'name'],
[(1572, 764), (2332, 824), 'text', 'cnic'],
[(1996, 692), (2052, 752), 'box', 'corporate'],
[(2300, 692), (2356, 756), 'box', 'individual']]
where each tuple is obtained from mouse clicks with OpenCV.
roi[0][0]
, which is (276, 756), has (x, y) coordinates, so width for the first field named 'name' is 276:940, and height of first field named 'name' is 756:828.
How do I use a for loop to extract cropping of the image like img[756:828, 276:940]
for all the ROIs?
I found that roi[0][0]
is (276, 756)
and roi[0][0][0]
is 276, but don't know how to implement one loop for all sections.
I will be sending this data to tesseract (OCR).
CodePudding user response:
for pt1, pt2, _, _ in roi:
cropped = img[pt1[1]:pt2[1], pt1[0]:pt2[0]]