Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does one use cv::boxPoints(RotatedRect box, OutputArray points)

Tags:

c++

opencv

I tried the following:

cv::RotatedRect minRect = cv::minAreaRect(contour);
std::vector<cv::Point2f> boxPts;
cv::boxPoints(minRect, boxPts);

The boxPoints function does not seem to like the vector of Point2f. What kind of OutputArray does it want?

like image 857
Nick Wilkerson Avatar asked May 08 '26 20:05

Nick Wilkerson


2 Answers

One can also use RotatedRect.points which works with Point2f[] as follow:

RotatedRect minRect = minAreaRect(contour);
vector<Point2f> boxPts(4);
minRect.points(boxPts.data());
like image 91
YWsecond Avatar answered May 10 '26 17:05

YWsecond


Give a Mat as OutputArray.

RotatedRect minRect = minAreaRect(contour);
Mat boxPts;
boxPoints(minRect, boxPts);
cout << boxPts.size() << endl;
cout << "boxPts " << endl << " " << boxPts << endl;

The order of the box points: bottom left, top left, top right, bottom right

like image 30
Sam Avatar answered May 10 '26 18:05

Sam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!