Ask Your Question

want to detect rectangle in a image using opencv-python?

asked 2019-01-21 04:49:24 -0500

ganesh gravatar image

here, i tried to detect rectangle from an image and want to save it,but image has two rectangles what i need to save is the bigger one for each image here the smaller one is saving as new image. How to get the bigger one.

edit retag flag offensive close merge delete



you have width and heigh of rect - so it should be easy to decide which one is bigger - essentially what berak posted with computing the area of the rect.

holger gravatar imageholger ( 2019-01-22 10:43:48 -0500 )edit

Absolutely, holger.

supra56 gravatar imagesupra56 ( 2019-01-22 14:47:32 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2019-01-22 01:27:19 -0500

berak gravatar image

you filter them by area:

largest_rect = None
for r in rects:
    a = cv2.contourArea(r)
    if a > largest_area:
         largest_area = a
         largest_rect = r
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2019-01-21 04:49:24 -0500

Seen: 58 times

Last updated: Jan 22