get convexhull points from array in openframeworks opencv

168 views Asked by At

I'm using openframeworks and opencv together and I'm trying to find the points of the convexhull. when i console log this method I get an array of all of the points but I need to be able to access specific points in the array.

When I console log the getConvexHull Method, I get the x and y points in the array:

 cout << "convexhull points" << contourFinder.getConvexHull(i) << endl;

And this is what the console gives me:

getconvexhull[243, 434;
  241, 443;
  243, 419]

How can I access the individuals points so I can reference them? I was thinking I need to do something like hull[0] but thats just returning [0, 0].

1

There are 1 answers

0
amoz On
for (auto contourIndex = 0; contourIndex < contourFinder.size(); ++contourIndex)
{

    const ofPolyline contour = contourFinder.getPolylines()[contourIndex];

    ConvexHull convexHull(contour, hullMinumumDefectDepth);

    for (auto point: convexHull.convexHull()){
        ofSetColor(0,0,255, 100);
        ofDrawRectangle(point.x, point.y, 100, 100);
    }
}

This is what I did to get each points of convexHull and draw a blue rectangle on each point. Hope it helps!