Convert two points to a rectangle (cv::Rect)

Since Rect::tl() and Rect::br() just return copies, not references, try a constructor:

cv::Rect rRect(pTopLeft, pBottomRight);

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

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);