Opencv – how to draw a rectangle by specifying its 4 corners

image processingobject-detectionopencvopencv4android

I am using OpenCV4Android version 2.4.11. I am reading frames from the camera and I detect any rectangular shapes in the frame. Then I try to draw a semi-transparent rectangle around a detected object.

what i want to do is, to draw a semi-transparent rectangale given the four corners of the detected object. But, in openCV you can draw a rectangle by spcifying only two points of it "the topLeft and BottomRight".

please let me know how to draw a rectangle by spcifying the the four corners of it NOT ONLY by spcifying the topLeft and BottomRight corners.

the below posted image is to show you my attempts and to show you that what i want is to draw a rectangle around the four detected corners "red, green, blue, white"

image:

enter image description here

Best Answer

Same idea as @Saransh, but compiles for me:

auto x1 = std::min(tlx, std::min(trx, std::min(brx, blx))); // top-left pt. is the leftmost of the 4 points
auto x2 = std::max(tlx, std::max(trx, std::max(brx, blx))); // bottom-right pt. is the rightmost of the 4 points
auto y1 = std::min(tly, std::min(try, std::min(bry, bly))); //top-left pt. is the uppermost of the 4 points
auto y2 = std::max(tly, std::max(try, std::max(bry, bly))); //bottom-right pt. is the lowermost of the 4 points
Related Topic