cv::RotatedRect::boundingRect() with different behavior between versions (Bug #1406)
Description
cv::RotatedRect::boundingRect() is returning different results in different OpenCV versions.
code is this:
...
cv::RotatedRect my_rotated_rect(cv::Point2f(1000, 1000), cv::Size2f(200, 100), 3);
cv::Rect br = my_rotated_rect.boundingRect();
std::cout<<"x = "<<br.x<<" y = "<<br.y<<" width = "<<br.width<<" height = "<<br.height<<std::endl;
...
In version 2.3.1 32 bits windows it returns:
x = 897 y = 944 width = 207 height = 113
In version compiled from svn trunk from March 27, 2010 (64 bits Windows)
x = 944 y = 897 width = 113 height = 207
So, x and y axes are inverted between versions.
Best regards,
Andres Hurtis
www.visiondepatentes.com.ar
Associated revisions
Merge pull request #1406 from SpecLad:gpu-resize-warn
History
Updated by Alexander Shishkov over 13 years ago
Good day!
Yes, results of this function are different for various versions of OpenCV. But I think that results of 2.3.1.32 version are correct and results of other version are So we should not fix behavior of the function in the latest version.
Best regards,
Alexander Shishkov.
- Status changed from Open to Done
- (deleted custom field) set to invalid
Updated by Andres Hurtis over 13 years ago
Hello Alexander,
Ok.
In order to have backward compatibility I wrote some code, I'm pasting it here to share. With this the results are not exactly the same but they are equivalent.
Note: axes are not inverted. The main difference is that the angle is referred to y in old version and to x in new version.
cv::Rect boundingRect(cv::RotatedRect &rotated_rect)
{
static int opencv_bounding_rect_version = -1;
if(opencv_bounding_rect_version -1)
{
if(cv::RotatedRect(cv::Point2f(10, 5), cv::Size2f(20, 10), 0).boundingRect().x 5)
opencv_bounding_rect_version = 0;
else
opencv_bounding_rect_version = 1;
}
cv::Rect ret;
if(opencv_bounding_rect_version)
ret = cv::RotatedRect(rotated_rect.center, rotated_rect.size, rotated_rect.angle + 90).boundingRect();
else
ret = rotated_rect.boundingRect();
return ret;
}