我写了以下代码:
我想知道代码
#include<iostream>
#include<opencv2/core/core.hpp>
using namespace std;
using namespace cv;
int main()
{
Point2f p[4];
RotatedRect rr(Point2f(),Size2f(1,2),0);
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;
}
旋转矩形rr的左上角为(-0.5,-1),右下角为(0.5,1)。因此包含旋转矩形的最小正矩形为[(-1,-1),(1,1)],(-1,-1)为左上角,(1,1)为右下角。但是结果矩形的右下角为(2,2)。
我查看了源代码:
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;
}
我想知道代码
r.width -= r.x - 1;
和 r.height -= r.y - 1;
的意思。
我认为应该是 r.width -= r.x;
和 r.height -= r.y;
谁能告诉我这个源代码是否有误?
cv :: boundingRect
,结果会怎样呢? - Micka