# Create contour from corner points

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 close merge delete

Sort by ยป oldest newest most voted

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

more

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!

( 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!

( 2018-07-06 04:06:29 -0600 )edit

Official site

GitHub

Wiki

Documentation