Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pessimistic cv::RotatedRect::boundingRect() #18417

Closed
chacha21 opened this issue Sep 25, 2020 · 2 comments
Closed

pessimistic cv::RotatedRect::boundingRect() #18417

chacha21 opened this issue Sep 25, 2020 · 2 comments
Labels
question (invalid tracker) ask questions and other "no action" items here: https://forum.opencv.org

Comments

@chacha21
Copy link
Contributor

chacha21 commented Sep 25, 2020

OpenCV 4.4.0

Even with integer center/even size, the boundingRect() estimation of a cv::RotatedRect() with a 0 angle may be one-pixel wider than expected.
This is not wrong per se (this is still a bounding rect), but it is a little pessimistic :

cv::Rect r(0, 0, 1280, 1024);
cv::RotatedRect rr(cv::Point2f(r.width/2.f, r.height/2.f),
                   cv::Size2f(1.f*r.width, 1.f*r.height),
                   0);
cv::Rect br = rr.boundingRect();
std::cout << "r:" << r << std::endl; //1280x1024
std::cout << "br:" << br << std::endl; //1281x1025

This may be normal since a RotatedRect is center-wise, so the size may have to be odd to match integer-pixel boundaries.
However, this is still pessimistic :

cv::Rect r(0, 0, 1281, 1025);
cv::RotatedRect rr(cv::Point2f(640, 512), cv::Size2f(1.f*r.width, 1.f*r.height), 0);
cv::Rect br = rr.boundingRect();
std::cout << "r:" << r << std::endl;//1281 x 1025
std::cout << "br:" << br << std::endl;//1283 x 1027
@alalek
Copy link
Member

alalek commented Sep 27, 2020

Pixels on the right/bottom border of Rect are excluded.
RotatedRect has different semantics.


Usage questions should go to Users OpenCV Q/A forum: http://answers.opencv.org

@4sfaloth
Copy link

I also think the center of the box should be given by x0 + (width - 1) / 2, y0 + (height - 1) / 2

Imagine the box has a width of 5 and starts at 0, so pixels are 0, 1, 2, 3, 4. Center 2 is obviously '2', which is obtained by the formula above. If you don't subtract 1 from the width before dividing by two you get 2.5 which is wrong

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question (invalid tracker) ask questions and other "no action" items here: https://forum.opencv.org
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants