![](/img/trans.png)
[英]Is there any function in OpenCV to find the intersection, union and complements of two cv::Rect
[英]Is there any simple way to multiply cv::Rect size and coordinates?
假设我有2个矩形。 我希望第二个矩形比第一个矩形大两倍,并且x,y的位置也要大一倍。
cv::Rect r1=Rect(10,20,40,60);
cv::Rect r2 = r1 * 2; //this won't work
将矩形2参数1设置为1将起作用
r2.height = r1.height * 2;
r2.width = r1.height * 2;
r2.x = r1.x * 2;
r2.y = r2.y * 2;
它可以工作,但是有没有更简单的方法(例如单行代码)呢?
如果要这样做,这可能是最短的方法:
cv::Rect r1=Rect(10,20,40,60);
cv::Rect r2(r1.tl() * 2, r1.br() * 2);
我们可以重载*
运算符:
cv::Rect operator*(cv::Rect r, double scale) {
r.height *= scale;
r.width *= scale;
r.x *= scale;
r.y *= scale;
return r;
}
然后,您可以直接乘以矩形:
Rect r2 = Rect(10, 20, 40, 60) * 2;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.