1. 程式人生 > >opencv minAreaRect獲取最小方框函式總結

opencv minAreaRect獲取最小方框函式總結

不得不說,opencv的函式還是很豐富的,最近專案需求發現opencv還有minAreaRect這個函式,這個函式的功能就是:
@param points Input vector of 2D points, stored in std::vector\<\> or Mat */ CV_EXPORTS_W
RotatedRect minAreaRect( InputArray points );
可以看到輸入的是點群,輸出的是一個旋轉方框,這個方框的特性就是以最小的面積包含了所有的點群。

這裡用用到了RotatedRect這個型別,這個型別有一個方法:

 
 /** returns 4 vertices of the rectangle
@param pts The points array for storing rectangle vertices. The order is bottomLeft, topLeft, topRight, bottomRight.
*/

void points(Point2f pts[]) const;

這個方法的作用是將RotatedRect的四個頂點放到一個四個點的指標,比如

//定義一個儲存以上四個點的座標的變數
Point2f fourPoint2f[4];

然後這樣就可以輸出四個點,點的順序看註釋。