# Revision history [back]

### Finger count and convexity defects providing wrong value

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)));

}
}

// 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.

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