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

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

问题描述

是否有任何辅助方法来绘制由 cv2.minAreaRect()大概是((x1,y1),(x2,y2),angle)? cv2.rectangle()不支持角度. 并且由于返回的元组不是"RotatedRect"类的(因为它似乎未在Python绑定中实现),因此没有points()方法,如C ++教程解决方案

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

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)

should do the trick.

sources:

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

2) Python OpenCV Box2D

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

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