Ask Your Question
0

Create contour from corner points

asked 2018-07-04 10:21:59 -0600

Mary-Ann gravatar image

Hi,

I would like to check, if a given point is inside or outside of a given shape. I have already found the pointPolygonTest() function for this purpose. But my problem is, that I only have the corners of the shape, and I know that the edges are straight. Is there a way to create contours[] straight form the corner points? The only solution I found is to render (write into Mat) the edges and detect the shape to get the contours. But I actually dont need the rendered shape, I only want to perform this test. So I would like to skip this step if possible...

Thank you for any answers! Mary-Ann

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-07-04 10:26:54 -0600

LBerger gravatar image

updated 2018-07-06 04:25:52 -0600

try :

Point p1(10,10),p4(10,100), p3(100,100), p2(100,10) ;
    vector<Point> ctr;

ctr.push_back(p1);
ctr.push_back(p4);
ctr.push_back(p3);
ctr.push_back(p2);
double inside;
inside = pointPolygonTest(ctr, Point2f(254, 30.1), false);
if (inside < 0)
    cout << "Outside\n";
else if (inside > 0)
    cout << "inside\n";
else
    cout << "contour points\n";
inside= pointPolygonTest(ctr, Point2f(50, 50), false);
if (inside < 0)
    cout << "Outside\n";
else if (inside > 0)
    cout << "inside\n";
else
    cout << "contour points\n";
inside = pointPolygonTest(ctr, Point2f(10, 50), false);
if (inside < 0)
    cout << "Outside\n";
else if (inside > 0)
    cout << "inside\n";
else
    cout << "contour points\n";

Results :

Outside

inside

contour points

edit flag offensive delete link more

Comments

Hi! I thought that neighboring elements of the contour vector need to be connected pixels on the image (just like this answer says: http://answers.opencv.org/question/18...). But I will try if it works only using the corners! Thank you!

Mary-Ann gravatar imageMary-Ann ( 2018-07-04 10:37:16 -0600 )edit

Right, only the corners are enough for the algorithm. You dont need every single contour point. But if somebody needs it LineIterator does the job!

Mary-Ann gravatar imageMary-Ann ( 2018-07-06 04:06:29 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2018-07-04 10:21:59 -0600

Seen: 1,911 times

Last updated: Jul 06 '18