minAreaRect(contours) 的输出是什么

RC0*_*993 2 python opencv contour

我最近开始使用 openCV 和 python。我有一个项目,我使用findContours. 我得到大约 6-8 个轮廓,我在上面循环以获得适合轮廓的边界框。

为此,我使用了minAreaRect(contours)它给我应该适合轮廓的旋转矩形。现在这个命令的输出是一个元组列表。

每个元组看起来像这样((81.0, 288.0), (22.0, 10.0), -0.0)我无法得到关于每个数字的含义的任何描述?

我认为它可能是((x-coordinate, y-coordinate),(width, height), rotation)

Han*_*rse 6

你是对的。查看 OpenCV 上的 (C++) 文档cv::minAreaRect,我们看到cv::RotatedRect返回了 a 。该全construcorcv::RotatedRect方法是:

cv::RotatedRect::RotatedRect(const cv::Point2f& center, const cv::Size2f& size, float angle)    
Run Code Online (Sandbox Code Playgroud)

对应参数的说明为:

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.
Run Code Online (Sandbox Code Playgroud)

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

希望有帮助!