I have two points (assumed to be from rectangle, which are its top-left corner & bottom-right corner).
我有两个点(假设来自矩形,它的左上角和右下角)。
Point pTopLeft;
Point pBottomRight;
I want to formulate a cv::Rect using these points. So, I tried
我想用这些点写出一份简历。所以,我试着
cv::Rect rRect;
rRect.tl() = pTopLeft;
rRect.br() = pBottomRight;
There is no error. But the Rect seems to be containing nothing. i.e., both the points are indicating zero. So, How do I formulate a new Rect object with arbitrary two points ?
没有错误。但Rect似乎什么也没有。即。,两个点都表示0。那么,如何用任意两点表示一个新的Rect对象呢?
3 个解决方案
#1
10
since Rect::tl() and Rect::br() just return copies, not references, try a constructor:
Rect::tl()和Rect::br()只是返回副本,而不是引用,尝试构造函数:
cv::Rect rRect(pTopLeft, pBottomRight);
#2
5
You have to calcul basic informations from your two points. Width and height, and then create new object using the following constructor :
你必须从你的两点中找出基本的信息。宽度和高度,然后使用以下构造函数创建新对象:
(Object) rect(x, y, width, height)
pTopLeft.x = x
pTopLeft.y = y
pBottomRight.x - pTopLeft.x = width
pTopLeft.y - pBottomRight.y = height
#3
3
You can make it this way also,
你也可以这样做,
Point pTopLeft;
Point pBottomRight;
cv::Rect rRect(pTopLeft.x,pTopLeft.y,pBottomRight.x-pTopLeft.x,pBottomRight.y-pTopLeft.y);
#1
10
since Rect::tl() and Rect::br() just return copies, not references, try a constructor:
Rect::tl()和Rect::br()只是返回副本,而不是引用,尝试构造函数:
cv::Rect rRect(pTopLeft, pBottomRight);
#2
5
You have to calcul basic informations from your two points. Width and height, and then create new object using the following constructor :
你必须从你的两点中找出基本的信息。宽度和高度,然后使用以下构造函数创建新对象:
(Object) rect(x, y, width, height)
pTopLeft.x = x
pTopLeft.y = y
pBottomRight.x - pTopLeft.x = width
pTopLeft.y - pBottomRight.y = height
#3
3
You can make it this way also,
你也可以这样做,
Point pTopLeft;
Point pBottomRight;
cv::Rect rRect(pTopLeft.x,pTopLeft.y,pBottomRight.x-pTopLeft.x,pBottomRight.y-pTopLeft.y);