首页 > 解决方案 > What is the output of minAreaRect(contours)

问题描述

I have recently started working with openCV and and python. I have a project where I am finding contours using findContours. I get roughly around 6-8 contours on which I am looping to get the bounding box that fits the contour.

For that I have used minAreaRect(contours) which gives me rotated rectangle that should fit the contour. Now the output of this command is a list of tuples.

Each tuple looks like this ((81.0, 288.0), (22.0, 10.0), -0.0) I couldnt get any description on what each of that number mean?

I think it might be ((x-coordinate, y-coordinate),(width, height), rotation).

标签: pythonopencvcontour

解决方案


你是对的。查看 OpenCV 的 (C++) 文档cv::minAreaRect,我们看到cv::RotatedRect返回了 a 。的完整构造cv::RotatedRect

cv::RotatedRect::RotatedRect(const cv::Point2f& center, const cv::Size2f& size, float angle)    

对应参数的说明为:

center    The rectangle mass center.
size      Width and height of the rectangle.
angle     The rotation angle in a clockwise direction. When the angle is 0, 90, 180, 270 etc., the rectangle becomes an up-right rectangle.

显然,centersize在 Python API 中被视为元组,并且所有三个参数也作为元组返回。所以,总而言之,这很符合你的假设。

希望有帮助!


推荐阅读