Sascha Mayr
Sascha Mayr

Reputation: 341

How to find the largest empty rectangle using OpenCV?

I need to find the coordinates of the largest empty rectangle in a PNG image. The rectangle should consist of light colors (if that is too difficult, white pixels only are fine) and should be axis-oriented.

I am new to computer vision and I found out about OpenCV, I am currently using the python interface to it and started tackling this problem with the SimpleBlobDetector interface, but it gives me only the center of the Blob with a certain radius.

Can anyone point me in the right direction for this?

EDIT: I need to do this with a regular colored PNG image, not a binary matrix

Upvotes: 4

Views: 1059

Answers (1)

Alexander Leon VI
Alexander Leon VI

Reputation: 509

You can use a contour extractor, with the given point list you can check the size of the rectangle by checking the sizes of the lists, assuming that all the rectangles are parallel to the cardinal axis. If not you need to compute the distance of a pixel and the next for all the pixels in the contour list by using the x and y coordinates on each.

Upvotes: 1

Related Questions