Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get vertices of a rotated rectangle in OpenCV?

I used warpAffine in OpenCV to rotate a rectangle. Now I want to get the four vertices (the x and y locations of four points) of this rotated rectangle without rotating it back. After hours of search, I came up with no result. Could someone help me on this? Thank you.

like image 662
E_learner Avatar asked Jan 20 '14 15:01

E_learner


1 Answers

Like this:

cv::RotatedRect RotRect;
// Fill in RotRect somehow...

//Get four corners
cv::Point2f pts[4];
RotRect.points(pts);

The documentation also has an example.

like image 161
David Nilosek Avatar answered Sep 23 '22 10:09

David Nilosek