Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Is it a bug of opencv RotatedRect?

#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.

Is it a bug of opencv RotatedRect?

#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? wrong?

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

So maybe we should change code according to the situation.