cv::Rect的坑宽度或高度小了1

70 篇文章 9 订阅

见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).

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值