Finger count and convexity defects providing wrong value

asked 2016-02-15 10:35:20 -0600

Vivek_Elango gravatar image

I have retrieved convexity defects and after referring to some questions asked here, I figured out that Convexity defect contains data in 4s, i.e., [startIndex, endIndex, farthestPoint, depth].

So I retrieved the all these values and drew circles at the points (except depth). Following is the code which I used to do that.

    for (int j = 0; j < convexDefect.toList().size(); j = j+4) {

        if(farPoint.y < a){

            MODELConvexityDefects convexityDefects = new MODELConvexityDefects();

             convexityDefects.setStartIndex(contours.get(boundPos).toList()
             .get(convexDefect.toList().get(j)));

            convexityDefects.setEndIndex(contours.get(boundPos).toList()
            .get(convexDefect.toList().get(j+1)));

            convexityDefects.setFarthestPoint(contours.get(boundPos).toList()
            .get(convexDefect.toList().get(j+2)));

            convexityData.add(convexityDefects);
            }
    }

    // Draws all the points from defect data
    MODELConvexityDefects convexityDefects;

    for (int i = 0; i < convexityData.size(); i++) {

        convexityDefects = new MODELConvexityDefects();
        convexityDefects = convexityData.get(i);

                    // Green 
        Core.circle(modifiedFrame, convexityDefects.getStartIndex(), 6, new Scalar(0,154,0));
                    // Orange 
        Core.circle(modifiedFrame, convexityDefects.getEndIndex(), 6, new Scalar(0,154,246)); 
                    // Red
        Core.circle(modifiedFrame, convexityDefects.getFarthestPoint(), 6, new Scalar(0,0,255));
    }

The output I got is not really desirable one. Please tell me what am I doing wrong here.

Output:

If you notice I'm not able to get the farthest point correctly and the thumb is completely neglected.

edit retag flag offensive close merge delete

Comments

What is MODELConvexityDefects?

FooBar gravatar imageFooBar ( 2016-02-15 11:01:37 -0600 )edit

Something similar here. have you got last opencv version?

LBerger gravatar imageLBerger ( 2016-02-15 11:03:08 -0600 )edit

Oh no I'm using 2.4.11 @LBerger

Vivek_Elango gravatar imageVivek_Elango ( 2016-02-15 11:05:41 -0600 )edit

@FooBar, MODELConvexityDefects is a custom getter and setter class.

Vivek_Elango gravatar imageVivek_Elango ( 2016-02-15 11:06:24 -0600 )edit