Answer a question

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?

Answers

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

Logo

学AI,认准AI Studio!GPU算力,限时免费领,邀请好友解锁更多惊喜福利 >>>

更多推荐