见cv::Rect通过矩形的topleft、bottomright构造函数
template<typename _Tp> inline
Rect_<_Tp>::Rect_(const Point_<_Tp>& pt1, const Point_<_Tp>& pt2)
{
x = std::min(pt1.x, pt2.x);
y = std::min(pt1.y, pt2.y);
width = std::max(pt1.x, pt2.x) - x;
height = std::max(pt1.y, pt2.y) - y;
}
由于width和height的计算没加1,如果依据这组高宽分配Mat的大小是错误
如,topleft=(-50,-50), bottomright=(449,449),实际的矩形尺寸是 500 * 500,而cv::Rect返回的是499 * 499
这是因为opencv里的起止点范围其实是一个左闭右开的区间: [x0, x1)和[y0, y1)
相比之下,Qt的QRect则是按照闭区间:[x0,x1]和[y0,y1],所以QRect::bottomRight()就是右下角的坐标
QPoint QRect::bottomRight() const
Returns the position of the rectangle’s bottom-right corner.
Note that for historical reasons this function returns QPoint(left() + width() -1, top() + height() - 1).