Ask Your Question
2

How to combine multiple cv::RotatedRect objects?

asked Mar 12 '17

I have several rotated rects obtained from cv::minAreaRect(contour). Now I want to combine some of them to create a single rotated rect that encompasses the ones that interest me.

Looking at the class reference for rotated rects, it contains not much, making me think I'm looking at the wrong docs.

Low karma wont let me post links, but these are the docs I was looking at: - http :// docs.opencv.org/trunk/db/dd6/classcv_1_1RotatedRect.html

How would I go about combining them?

Preview: (hide)

1 answer

Sort by » oldest newest most voted
4

answered Mar 12 '17

berak gravatar image

to combine them, push all their points into a vector, then get a new minAreaRect from that:

RotatedRect rr1, rr2; // your rects.

vector<Point2f> allpts;

Point2f p1[4];
rr1.points(p1);
allpts.push_back(p1[0]);
allpts.push_back(p1[1]);
allpts.push_back(p1[2]);
allpts.push_back(p1[3]);

Point2f p2[4];
rr2.points(p2);
allpts.push_back(p2[0]);
allpts.push_back(p2[1]);
allpts.push_back(p2[2]);
allpts.push_back(p2[3]);

RotatedRect final = minAreaRect(allpts);
Preview: (hide)

Question Tools

1 follower

Stats

Asked: Mar 12 '17

Seen: 2,228 times

Last updated: Mar 12 '17