我想画一个旋转的矩形我有左上角点和右下角点,盒子的宽度和高度。还有角度。但我似乎无法弄清楚如何在 Python 中使用 OpenCV 绘制旋转的矩形。请注意,我不想旋转图像。
谢谢
最佳答案
在 OpenCV 中绘制矩形的方法有很多种。
来自 OpenCV 文档:Drawing Functions
rectangle
Draws a simple, thick, or filled up-right rectangle.
所以这个函数没有帮助,因为你想绘制它旋转。
矩形不过是一种特殊的 4 边多边形。因此,只需使用绘制多边形的函数即可。
polylines
Draws several polygonal curves.
Python:
cv2.polylines(img, pts, isClosed, color[, thickness[, lineType[, shift]]]) → img
并插入旋转矩形的 4 个顶点
或使用分别绘制 4 个边
line
Draws a line segment connecting two points.
或
drawContours
Draws contours outlines or filled contours.
这些点可以通过简单的数学运算获得,例如使用 OpenCV 的 RotatedRect https://docs.opencv.org/2.4/modules/core/doc/basic_structures.html#rotatedrect
关于python - 在python中的openCV中绘制一个旋转框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49287227/