Created
September 27, 2019 14:40
-
-
Save santhalakshminarayana/a67e29f5924cd220e73fa71d01a8476e to your computer and use it in GitHub Desktop.
Medium:Imagetopdf find and fit contours
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Find contours in image using (tree retrival method) for hierarchy | |
image_conts=[] | |
for img in thsh_images: | |
contours,_=cv2.findContours(img.copy(),cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE) | |
image_conts.append(contours) | |
#Look for maximum area contour which describes page/rectangle structure in image | |
max_area_conts=[] | |
for contour in image_conts: | |
max_ind,max_area=None,0 | |
for ind,cnt in enumerate(contour): | |
area=cv2.contourArea(cnt) | |
if area > max_area: | |
max_area=area | |
max_ind=ind | |
max_area_conts.append(max_ind) | |
#Fit contour of maximum area | |
for ind,contour in enumerate(image_conts): | |
img=images_read[ind].copy() | |
img=cv2.drawContours(img,contour,3,(0,255,0),4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment