Is it a bug of opencv RotatedRect?

asked 2016-03-08 09:14:50 -0600

Gauss gravatar image

updated 2016-03-08 09:16:32 -0600

#include<iostream>
#include<opencv2/core/core.hpp>
using namespace std;
using namespace cv;

int main()
{
    Point2f p[4];
    RotatedRect rr(Point2f(),Size2f(1,1.8),1);
    rr.points(p);
    for(int i = 0;i < 4;i++) cout<<p[i]<<endl;
    Rect r = rr.boundingRect();
    cout<< r.x << " " << r.y << " " << r.br().x << " " << r.br().y <<endl;
    return 0;
}

The top-left corner of RotatedRect rr is (-0.484217,-0.908589),and the bottom-right corner of RotatedRect rr is (0.484217,0.908589).So the minminimal up-right rectangle containing the rotated rectangle is [(-1,-1),(1,1)],(-1,-1) is the top-left corner,(1,1) is the bottom-right corner.But the result rect's bottom-right corner is (2,2).

And I read the source:

Rect RotatedRect::boundingRect() const
{
    Point2f pt[4];
    points(pt);
    Rect r(cvFloor(std::min(std::min(std::min(pt[0].x, pt[1].x), pt[2].x), pt[3].x)),
           cvFloor(std::min(std::min(std::min(pt[0].y, pt[1].y), pt[2].y), pt[3].y)),
           cvCeil(std::max(std::max(std::max(pt[0].x, pt[1].x), pt[2].x), pt[3].x)),
           cvCeil(std::max(std::max(std::max(pt[0].y, pt[1].y), pt[2].y), pt[3].y)));
    r.width -= r.x - 1;
    r.height -= r.y - 1;
    return r;
}

I wonder the code r.width -= r.x - 1; and r.height -= r.y - 1; And I think it should be r.width -= r.x; and r.height -= r.y; Who can tell me is it the source wrong?

And I have other questions? Does RotatedRect have bottom boundary and right boundary ? And if the corners of RotatedRect lies on the minminimal up-right rectangle ,may be we use increase bottom boundary and right boundary by one,because the right boundary and bottom boundary don't belong to rectange,so we also should use the code r.width -= r.x - 1; and r.height -= r.y - 1;

So maybe we should change code according to the situation.

edit retag flag offensive close merge delete

Comments

there's already an issue about it.

berak gravatar imageberak ( 2016-03-08 09:17:21 -0600 )edit