1

I am working in OpenCV/Python and I came up with this problem. I have used cv2.minAreaRect() to get the Bounding Box surrounding a set of points. Is there any other function/generic algorithm that can give me the largest rectangle inscribed within a polygon (set of points)? I have a set of points of the polygon and the function should be able to return 4 points of the largest rectangle inscribing the input points.

Here is an example of a similar kind of problem

Thanks. Any help is highly appreciated.

api55
  • 11,070
  • 4
  • 41
  • 57
planet_pluto
  • 742
  • 4
  • 15
  • So the inside points are irrelevant? you just need to find the biggest rectangle inside the polygon (defined by continuous border points)? Try [this answer](https://stackoverflow.com/questions/32674256/how-to-adapt-or-resize-a-rectangle-inside-an-object-without-including-or-with-a/32682512#32682512) (is in c++, but easy to change to python) – api55 Aug 21 '19 at 08:23
  • Thanks for the reply. Yes, the inside points are irrelevant. I have the coordinates of all the points that form the polygon. I will try using this method. – planet_pluto Aug 21 '19 at 08:27
  • follow this link https://d3plus.org/blog/behind-the-scenes/2014/07/08/largest-rect/ – rohit prakash Aug 21 '19 at 08:54
  • https://github.com/pogam/ExtractRect – rohit prakash Aug 21 '19 at 08:57

1 Answers1

0

I can provide you with those set of conditions which can lead you to your desired result but can't provide you with the code at present because it's very time taking for me. so you have to code for yourself in the mean time. here are the conditions to follow.

Filter all the coordinates of the polygon for all 4 set of coordinates which satisfy these below mentioned condition for coordinates: [(a,b),(c,d),(e,f),(g,h)]

1.(a-c)=(e-g) as opposite sides should be equal

2.(b-f)=(d-h) as opposite sides should be equal

3.(d-f)^2+(c-e)^ = (b-h)^2+(a-g)^2 as diagonals should be equal

 if these conditions are satisfied you will get all the set of four 
 coordinates which are rectangles.After that

4.Filter out all the coordinates received by checking if any polygonal coordinate is falling inside the rectangle, that's easy.

 now you are left with all the possible inbound rectangles, now all you have 
 to do is
  1. list all the areas possible

  2. max out the list for maximum area.