Question

I'm using Visual C++ 2010 Express with OpenCV, and I'm trying to track two hands. So far I already have the convexHull and convexityDefects, but I'm having trouble getting the points of the convexHull. I'd like to use them to draw a line from the center of each hand (a point I already can draw lines with) to each convexHull point, and then I can add filters on that so it only picks the ones for fingers. That's no problem, I just need to get the hull points into a working format for drawing functions. My code currently looks like this:

findContours(temp,Lcontours,hierarchy,CV_RETR_CCOMP,CV_CHAIN_APPROX_SIMPLE );
vector<vector<int> >hullI( Lcontours.size() );
vector<vector<Point> >hullP( Lcontours.size() );
vector<vector<Vec4i>> defects( Lcontours.size() );
std::sort(Lcontours.begin(), Lcontours.end(),compare_contour_areas);

for( int f = 0; f < Lcontours.size(); f++ ){
    convexHull( Mat(Lcontours[f]), hullI[f], true );
    convexHull( Mat(Lcontours[f]), hullP[f], true );
    convexityDefects(Lcontours[f],hullI[f],defects[f]);
    drawContours(cameraFeed(lefT), Lcontours, 0, Scalar(0,200,200), 1.5, 8, vector<Vec4i>(), 0, Point() );
    drawContours(cameraFeed(lefT), hullP, 0, Scalar(200,200,0), 1.5, 8, vector<Vec4i>(), 0, Point() );

How do I convert the hull vector (it doesn't matter which one, hullI for int or hullP for point formats) into something I can say "print the x and y of hull[f]" about. So far it seems to be like hull[?][?][?][?] because it's vector within vector or something? Does this have to do with the end of the convexHull functions, where the last parameter is either true or false?

Was it helpful?

Solution

for( int f = 0; f < Lcontours.size(); f++ ){
    convexHull( Mat(Lcontours[f]), hullI[f], true );
    convexHull( Mat(Lcontours[f]), hullP[f], true );

    vector <Point> thisHull(hullP[f].size());
    thisHull=hullP[f]; //which hull you want to look at
    int pointYouWant; //point you want to interrogate

    cout<<"for hull #"<< f << ", point #" << pointYouWant << " , x= " << thisHull[pointYouWant].x << " , y= " << thisHull[pointYouWant].y << endl;
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top