OpenCV Python: Draw minAreaRect ( RotatedRect not implemented)

opencv, python

Solution

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

should do the trick.

sources:

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

Python OpenCV Box2D

Problem

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?

Original source