Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
575 views
in Technique[技术] by (71.8m points)

OpenCV Python: Draw minAreaRect ( RotatedRect not implemented)

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...