Calculate minimum area rectangle for a polygon

2019-04-10 08:19发布

I have a need to calculate the minimum area rectangle (smallest possible rectangle) around the polygon.

The only input i have is the number of points in polygon.

I have the co-ordinates of the points also.

5条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-04-10 08:48

This is called Minimum Bounding Box, it's most basic algorithm used in OCR packages. You can find an implementation using Rotating Calipers from the OpenCV package. Once you get the source code, check out this file,

cv/src/cvrotcalipers.cpp

The method you need is cvMinAreaRect2().

查看更多
看我几分像从前
3楼-- · 2019-04-10 08:48

Follow the following algorithm

  1. Rotate the polygon onto the XY plane
  2. Pick 1 edge and align this edge with the X axis(use arctan). Use the min/max x,y to find the bounding rectangle. Compute Area and store in list
  3. Do the same for remaining edges in clipped polygon.
  4. Pick the rectangle with the minimum Area.
  5. Rotate Bounding Rectangle back for Coplanar reverse rotation of Step 1 and step 2

for more detail check link Minimum-Area-Rectangle

查看更多
在下西门庆
4楼-- · 2019-04-10 08:49

First do a grahm-scan and get the convex hull of the set of points. Then you can use something like minimum rectangle discussed here

查看更多
欢心
5楼-- · 2019-04-10 08:52

Obviously, you'll need the coordinates of the points to get the answer. If the rectangle is aligned to the X and Y aces, then the solution is trivial. If you want the smallest possible rectangle, at any angle, then you'll need to do some sort of optimization process.

查看更多
对你真心纯属浪费
6楼-- · 2019-04-10 08:55

Use the rotating calipers algorithm for a convex polygon, or the convex hull otherwise. You will of course need the coordinates of the points in the polygon, not just the number of points.

查看更多
登录 后发表回答