Ask Your Question

Revision history [back]

i think rotatedRectangleIntersection() is also useful

you can try the code below showing the idea ( sorry for lack of explanation):

cv::Mat img = cv::imread("test.png");

cv::RotatedRect rr1(cv::Point2f(0,0),cv::Size2f(660,800),61); //experimentally created

cv::Rect detection1(300,200, 64, 128); // just for test try to change x,y,width,height

cv::RotatedRect rrdetection1(cv::Point2f(detection1.x + (detection1.width / 2), detection1.y + (detection1.height / 2)),
                             cv::Size2f(detection1.width, detection1.height), 0);

//visualization 
cv::Point2f vtx1[4];
rr1.points(vtx1);
for (int i = 0; i < 4; i++)
    cv::line(img, vtx1[i], vtx1[(i + 1) % 4], cv::Scalar(0, 0, 255), 2);

std::vector<cv::Point2f> intersections;
cv::rotatedRectangleIntersection(rr1, rrdetection1, intersections);

std::cout << cv::Mat(intersections);
cv::imshow("Canvas", img);
cv::waitKey();