[英]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.