OpenCV Python:绘制 minAreaRect(未实现 RotatedRect) [英] OpenCV Python: Draw minAreaRect ( RotatedRect not implemented)

查看:21
本文介绍了OpenCV Python:绘制 minAreaRect(未实现 RotatedRect)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何辅助方法可以绘制由 cv2.minAreaRect() 大概是 ((x1,y1),(x2,y2),angle)?cv2.rectangle() 不支持角度.由于返回的元组不属于RotatedRect"类(因为它似乎没有在 Python 绑定中实现),因此没有 points() 方法,如 C++ 教程 "为轮廓创建边界旋转框和椭圆¶".

Are there any helper methods to draw a rotated rectangle that is returned by cv2.minAreaRect() presumably as ((x1,y1),(x2,y2),angle)? cv2.rectangle() does not support an angle. And since the tuple returned is not of the "RotatedRect" class (because it seems to not be implemented in the Python bindings) there is no points() method, as shown in the C++ tutorial "Creating Bounding rotated boxes and ellipses for contours¶".

如何从直线绘制旋转的矩形 - 围绕中心点或给定的第一个点旋转?

How could a rotated rectangle be drawn from lines - rotate about the center point or the first point given?

推荐答案

rect = cv2.minAreaRect(cnt)
box = cv2.cv.BoxPoints(rect) # cv2.boxPoints(rect) for OpenCV 3.x
box = np.int0(box)
cv2.drawContours(im,[box],0,(0,0,255),2)

应该可以解决问题.

来源:

1) http://opencvpython.blogspot.in/2012/06/contours-2-brotherhood.html

2) Python OpenCV Box2D

这篇关于OpenCV Python:绘制 minAreaRect(未实现 RotatedRect)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆