RotatedRect类opencv 标签: opencv图像处理 转自:http://blog.csdn.net/u012507022/article/details/51684776 有三个属性: 矩形中心点(质心)边长(长和宽)旋转角度 [cpp] view plain copy class CV_EXPORTS RotatedRect { public: //构造函数 RotatedRect(); RotatedRect(const Point2f& center, const Size2f& size, float angle); RotatedRect(const CvBox2D& box); //!返回矩形的4个顶点 void points(Point2f pts[]) const; //返回包含旋转矩形的最小矩形 Rect boundingRect() const; //!转换到旧式的cvbox2d结构 operator CvBox2D() const; Point2f center; //矩形的质心 Size2f size; //矩形的边长 float angle; //旋转角度,当角度为0、90、180、270等时,矩形就成了一个直立的矩形 }; 示例程序: [cpp] view plain copy #include"iostream" #include"opencv2/opencv.hpp" using namespace std; using namespace cv; int main() { Mat image(200, 200, CV_8UC3, Scalar(0)); RotatedRect rRect(Point2f(100, 100), Size2f(100, 50), 30); Point2f vertices[4]; //定义矩形的4个顶点 rRect.points(vertices); //计算矩形的4个顶点 for (int i = 0; i < 4; i++) line(image, vertices[i], vertices[(i + 1) % 4], Scalar(0, 255, 0)); Rect brect = rRect.boundingRect(); //返回包含旋转矩形的最小矩形 rectangle(image, brect, Scalar(255, 0, 0)); imshow("rectangles", image); waitKey(0); } 运行结果: