Ask Your Question
1

How can I find defect points?

asked 2014-10-25 16:15:20 -0600

jossyy gravatar image

updated 2020-04-08 06:31:52 -0600

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 :

image description

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[2]);
        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 flag offensive close merge delete

Comments

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

FooBar gravatar imageFooBar ( 2014-10-26 03:27:53 -0600 )edit

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.

jossyy gravatar imagejossyy ( 2014-10-26 03:38:31 -0600 )edit

How did you compute these points?

FooBar gravatar imageFooBar ( 2014-10-26 04:15:26 -0600 )edit

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[2]);
    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);

http://docs.opencv.org/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html#convexitydefects

jossyy gravatar imagejossyy ( 2014-10-26 04:21:57 -0600 )edit

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?

FooBar gravatar imageFooBar ( 2014-10-26 04:47:04 -0600 )edit

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

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

jossyy gravatar imagejossyy ( 2014-10-26 04:52:06 -0600 )edit

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?

FooBar gravatar imageFooBar ( 2014-10-26 05:20:20 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2014-10-26 09:10:37 -0600

jossyy gravatar image

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

edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-10-25 16:15:20 -0600

Seen: 2,738 times

Last updated: Oct 25 '14