Ask Your Question
2

How to combine multiple cv::RotatedRect objects?

asked 2017-03-11 19:45:04 -0600

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?

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
4

answered 2017-03-12 04:07:24 -0600

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);
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-03-11 19:45:04 -0600

Seen: 2,103 times

Last updated: Mar 12 '17