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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With