Ask Your Question
2

How can I divide an image into two specific polygons?

asked 2018-12-14 04:59:17 -0600

elnura gravatar image

updated 2020-11-28 06:14:14 -0600

Hi , I am not sure that the question has been asked or not. I have an image shown in first picture. And i detect humans in the picture. But i want to find where the detected humans located. I create two or more polygons in an image shown the second picture and need to find regions of detected humans. For example, suppose i have 5 detected humans in the image and then i need to find how many of them is in region 1 and how many of them is in region 2. I have coordinates of detected humans, and i developed an algorithm in it i compare coordinates of the regions and detected humans' coordinates. But i wonder i can use a different approach in such scenario. I would be appreciated if any help .

image description image description

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
1

answered 2018-12-14 05:16:48 -0600

berak gravatar image

updated 2018-12-14 05:17:35 -0600

if you manage to describe your polygons as a list of points, you can apply pointPolygonTest()

(you don't need to segment the image for this)

edit flag offensive delete link more
1

answered 2018-12-14 05:30:07 -0600

updated 2018-12-14 06:23:33 -0600

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();
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-12-14 04:59:17 -0600

Seen: 611 times

Last updated: Dec 14 '18