OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Sun, 26 Oct 2014 09:10:37 -0500How can I find defect points?http://answers.opencv.org/question/45530/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 :
![image description](/upfiles/14142716271606411.png)
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);
Sat, 25 Oct 2014 16:15:20 -0500http://answers.opencv.org/question/45530/how-can-i-find-defect-points/Comment by jossyy for <p>I want to find hand and palm. I used below algorithm :</p>
<p>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</p>
<p>My result is below :</p>
<p><img alt="image description" src="/upfiles/14142716271606411.png"></p>
<p>I wanted to find palm center. For this, I used below code after defects was found.</p>
<p>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?</p>
<pre><code>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);
</code></pre>
http://answers.opencv.org/question/45530/how-can-i-find-defect-points/?comment=45542#post-id-45542I 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#convexitydefectsSun, 26 Oct 2014 04:21:57 -0500http://answers.opencv.org/question/45530/how-can-i-find-defect-points/?comment=45542#post-id-45542Comment by FooBar for <p>I want to find hand and palm. I used below algorithm :</p>
<p>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</p>
<p>My result is below :</p>
<p><img alt="image description" src="/upfiles/14142716271606411.png"></p>
<p>I wanted to find palm center. For this, I used below code after defects was found.</p>
<p>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?</p>
<pre><code>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);
</code></pre>
http://answers.opencv.org/question/45530/how-can-i-find-defect-points/?comment=45539#post-id-45539What 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). Sun, 26 Oct 2014 03:27:53 -0500http://answers.opencv.org/question/45530/how-can-i-find-defect-points/?comment=45539#post-id-45539Comment by FooBar for <p>I want to find hand and palm. I used below algorithm :</p>
<p>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</p>
<p>My result is below :</p>
<p><img alt="image description" src="/upfiles/14142716271606411.png"></p>
<p>I wanted to find palm center. For this, I used below code after defects was found.</p>
<p>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?</p>
<pre><code>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);
</code></pre>
http://answers.opencv.org/question/45530/how-can-i-find-defect-points/?comment=45541#post-id-45541How did you compute these points?Sun, 26 Oct 2014 04:15:26 -0500http://answers.opencv.org/question/45530/how-can-i-find-defect-points/?comment=45541#post-id-45541Comment by jossyy for <p>I want to find hand and palm. I used below algorithm :</p>
<p>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</p>
<p>My result is below :</p>
<p><img alt="image description" src="/upfiles/14142716271606411.png"></p>
<p>I wanted to find palm center. For this, I used below code after defects was found.</p>
<p>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?</p>
<pre><code>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);
</code></pre>
http://answers.opencv.org/question/45530/how-can-i-find-defect-points/?comment=45540#post-id-45540Blue 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.Sun, 26 Oct 2014 03:38:31 -0500http://answers.opencv.org/question/45530/how-can-i-find-defect-points/?comment=45540#post-id-45540Comment by FooBar for <p>I want to find hand and palm. I used below algorithm :</p>
<p>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</p>
<p>My result is below :</p>
<p><img alt="image description" src="/upfiles/14142716271606411.png"></p>
<p>I wanted to find palm center. For this, I used below code after defects was found.</p>
<p>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?</p>
<pre><code>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);
</code></pre>
http://answers.opencv.org/question/45530/how-can-i-find-defect-points/?comment=45547#post-id-45547It'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? Sun, 26 Oct 2014 05:20:20 -0500http://answers.opencv.org/question/45530/how-can-i-find-defect-points/?comment=45547#post-id-45547Comment by FooBar for <p>I want to find hand and palm. I used below algorithm :</p>
<p>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</p>
<p>My result is below :</p>
<p><img alt="image description" src="/upfiles/14142716271606411.png"></p>
<p>I wanted to find palm center. For this, I used below code after defects was found.</p>
<p>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?</p>
<pre><code>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);
</code></pre>
http://answers.opencv.org/question/45530/how-can-i-find-defect-points/?comment=45543#post-id-45543You 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? Sun, 26 Oct 2014 04:47:04 -0500http://answers.opencv.org/question/45530/how-can-i-find-defect-points/?comment=45543#post-id-45543Comment by jossyy for <p>I want to find hand and palm. I used below algorithm :</p>
<p>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</p>
<p>My result is below :</p>
<p><img alt="image description" src="/upfiles/14142716271606411.png"></p>
<p>I wanted to find palm center. For this, I used below code after defects was found.</p>
<p>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?</p>
<pre><code>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);
</code></pre>
http://answers.opencv.org/question/45530/how-can-i-find-defect-points/?comment=45544#post-id-45544I used this function convexityDefects(polyContour, hullInt, defects);
For convex hull, convexHull(contours[maxAreaIndex], hullInt, false);Sun, 26 Oct 2014 04:52:06 -0500http://answers.opencv.org/question/45530/how-can-i-find-defect-points/?comment=45544#post-id-45544Answer by jossyy for <p>I want to find hand and palm. I used below algorithm :</p>
<p>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</p>
<p>My result is below :</p>
<p><img alt="image description" src="/upfiles/14142716271606411.png"></p>
<p>I wanted to find palm center. For this, I used below code after defects was found.</p>
<p>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?</p>
<pre><code>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);
</code></pre>
http://answers.opencv.org/question/45530/how-can-i-find-defect-points/?answer=45559#post-id-45559@FooBar thanks your help. I use different algorithm for center of palm. Sun, 26 Oct 2014 09:10:37 -0500http://answers.opencv.org/question/45530/how-can-i-find-defect-points/?answer=45559#post-id-45559