First time here? Check out the FAQ!

Ask Your Question
1

How can I find defect points?

asked Oct 25 '14

jossyy gravatar image

updated Apr 8 '0

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);
Preview: (hide)

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 (Oct 26 '14)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 (Oct 26 '14)edit

How did you compute these points?

FooBar gravatar imageFooBar (Oct 26 '14)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 (Oct 26 '14)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 (Oct 26 '14)edit

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

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

jossyy gravatar imagejossyy (Oct 26 '14)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 (Oct 26 '14)edit

1 answer

Sort by » oldest newest most voted
0

answered Oct 26 '14

jossyy gravatar image

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

Preview: (hide)

Question Tools

Stats

Asked: Oct 25 '14

Seen: 3,026 times

Last updated: Oct 25 '14