Ask Your Question
0

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

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

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

Comments

1

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 -0600 )edit

Absolutely, holger.

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

1 answer

Sort by ยป oldest newest most voted
0

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

berak gravatar image

you filter them by area:

largest_area=0
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

Question Tools

1 follower

Stats

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

Seen: 1,532 times

Last updated: Jan 22 '19