# How can I find defect points? I want to find hand and palm. I used below algorithm :

1- Get a frame from webcam 2- Convert to grayscale, apply blur and threshold method. 3- Use canny method and findContours 4- Find the contour which has max area, draw it 5- Find and draw convex hull 6- Apply convexityDefects

My result is below : I wanted to find palm center. For this, I used below code after defects was found.

It calculates average of defects point's coordinate. But the result is not good bacause the defect points aren't found regularly. How can I get better result?

int x = 0,y = 0;
for(int i = 0; i < defects.size(); i++) {

Point p1 = contours[maxAreaIndex].at(defects[i].val);
x += p1.x;
y += p1.y;
}

// draw a circle for palm center
circle(drawing, Point(x/defects.size(), y/defects.size()), 3, Scalar( 0, 255, 0 ), 3);

edit retag close merge delete

What are the blue points? You have only seven points in you convex hull, but there are 11(?) blue points. Why do you use the convexity defects to find the center of the hand? These points are rather unstable (imagine the case when two fingers touch: the defect point between the will move very fast so that your palm position will be unstable).

Blue points are defects. I tried to find two points on wrist and four points between fingers. I calculated these 6 points's center.And it would be center of palm.

I used convexityDefects() function in opencv. The function gives 4 integer numbers. I used third number. int x = 0,y = 0; for(int i = 0; i < defects.size(); i++) {

    Point p1 = contours[maxAreaIndex].at(defects[i].val);
x += p1.x;
y += p1.y;
}

// draw a circle for palm center
circle(drawing, Point(x/defects.size(), y/defects.size()), 3, Scalar( 0, 255, 0 ), 3);


You posted this code already... And it does not show how you compute(!) the points, but only how you draw them. And the blue points don't look like defect points. E.g. why is there no point between middle and ring finger? But a point on the tip of the index finger? How do you draw the seven segments of the convex hull?

I used this function convexityDefects(polyContour, hullInt, defects);

For convex hull, convexHull(contours[maxAreaIndex], hullInt, false);

It's really hard to help if you provide the code one line at a time. In the first code segment, you read the points from a variable called contours[maxAreaIndex] but computes the defects for a contour called polyContour. How does this fit together?

Sort by » oldest newest most voted

@FooBar thanks your help. I use different algorithm for center of palm.

more

Official site

GitHub

Wiki

Documentation