Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to delete additional circles in OpenCV's Finger Detection?

i'm developing an app to recognize hand gestures... My program detect 3 useless points.. how can I make sure they are not detected?

i am using opencv 4.0.1 and microsoft visual studio 2017.

this is the code:

//FIND CONVEX HULLS int largestcontour = 0; int maxarea = 0; for (int i = 0; i < contours.size(); i++) { double a = contourArea(contours[i]); if (a > maxarea) { maxarea = a; largestcontour = i; } }

vector<vector<point>

hull(contours.size()); vector<vector<int> > hullsI(contours.size()); vector<vector<vec4i>> defects(contours.size());

for (int i = 0; i < contours.size(); i++) { convexHull(contours[i], hull[i], false); convexHull(contours[i], hullsI[i], false); if (hullsI[i].size() > 3) { convexityDefects(contours[i], hullsI[i], defects[i]); } }

if (maxarea > 100) { drawContours(drawing, hull, largestcontour, Scalar(255, 0, 255), 3, 8, vector<vec4i>(), 0, Point());

for (int j = 0; j < defects[largestcontour].size(); ++j)
{
    const Vec4i& v = defects[largestcontour][j];
    float depth = v[3] / 256;
    if (depth > 5) //  filter defects by depth
    {
        int startidx = v[0]; Point ptStart(contours[largestcontour][startidx]);
        int endidx = v[1]; Point ptEnd(contours[largestcontour][endidx]);
        int faridx = v[2]; Point ptFar(contours[largestcontour][faridx]);

        line(drawing, ptStart, ptEnd, Scalar(0, 255, 0), 1);
        line(drawing, ptStart, ptFar, Scalar(0, 255, 0), 1);
        line(drawing, ptEnd, ptFar, Scalar(0, 255, 0), 1);

        //DRAW POINTS
        circle(drawing, ptFar, 9, Scalar(0, 255, 0), 2);
        circle(drawing, ptEnd, 9, Scalar(0, 0, 255), 2);

    }
} }

and this is the result: https://imgur.com/a/Ip5mXIh

thanks

click to hide/show revision 2
None

updated 2019-01-17 05:53:18 -0600

berak gravatar image

How to delete additional circles in OpenCV's Finger Detection?

i'm developing an app to recognize hand gestures... My program detect 3 useless points.. how can I make sure they are not detected?

i am using opencv 4.0.1 and microsoft visual studio 2017.

this is the code:

//FIND CONVEX HULLS HULLS
int largestcontour
  largestcontour = 0; int maxarea = 0;  for (int i = 0; i < contours.size(); i++) {
      double a = contourArea(contours[i]);
      if (a > maxarea)
      {
 {
         maxarea = a;
          largestcontour = i;
      } }

vector<vector<point>

hull(contours.size()); } vector<vector<Point> hull(contours.size()); vector<vector<int> > > hullsI(contours.size()); vector<vector<vec4i>> defects(contours.size());

vector<vector<Vec4i>> defects(contours.size()); for (int i = 0; i < contours.size(); contours.size(); i++) { convexHull(contours[i], hull[i], false); convexHull(contours[i], hullsI[i], false); if (hullsI[i].size() > 3) { { convexityDefects(contours[i], hullsI[i], defects[i]); } }

} if (maxarea > 100) { drawContours(drawing, hull, largestcontour, Scalar(255, 0, 255), 3, 8, vector<vec4i>(), vector<Vec4i>(), 0, Point());

Point());

     for (int j = 0; j < defects[largestcontour].size(); ++j)
{
     {
         const Vec4i& v = defects[largestcontour][j];
     float depth = v[3] / 256;
     if (depth > 5) //  filter defects by depth
    {
     {
             int startidx = v[0]; Point ptStart(contours[largestcontour][startidx]);
         int endidx = v[1]; Point ptEnd(contours[largestcontour][endidx]);
         int faridx = v[2]; Point ptFar(contours[largestcontour][faridx]);

         line(drawing, ptStart, ptEnd, Scalar(0, 255, 0), 1);
         line(drawing, ptStart, ptFar, Scalar(0, 255, 0), 1);
         line(drawing, ptEnd, ptFar, Scalar(0, 255, 0), 1);

         //DRAW POINTS
         circle(drawing, ptFar, 9, Scalar(0, 255, 0), 2);
         circle(drawing, ptEnd, 9, Scalar(0, 0, 255), 2);

     }
 } }

and this is the result: https://imgur.com/a/Ip5mXIh

thanks

How to delete additional circles in OpenCV's Finger Detection?

i'm developing an app to recognize hand gestures... My program detect 3 useless points.. how can I make sure they are not detected?

i am using opencv 4.0.1 and microsoft visual studio 2017.

this is the code:

//FIND CONVEX HULLS
int largestcontour = 0; int maxarea = 0; 
for (int i = 0; i < contours.size(); i++) {
     double a = contourArea(contours[i]);
     if (a > maxarea)
     {
         maxarea = a;
         largestcontour = i;
     } }

 vector<vector<Point> hull(contours.size());
vector<vector<int> >  hullsI(contours.size());
 vector<vector<Vec4i>>  defects(contours.size());

 for (int i = 0; i < contours.size(); i++) {
     convexHull(contours[i], hull[i], false);
     convexHull(contours[i], hullsI[i], false);
     if (hullsI[i].size() > 3)
     {
         convexityDefects(contours[i], hullsI[i], defects[i]);
     } }

 if (maxarea > 100) {
     drawContours(drawing, hull, largestcontour, Scalar(255, 0, 255),
 3, 8, vector<Vec4i>(), 0, Point());

     for (int j = 0; j < defects[largestcontour].size(); ++j)
     {
         const Vec4i& v = defects[largestcontour][j];
         float depth = v[3] / 256;
         if (depth > 5) //  filter defects by depth
         {
             int startidx = v[0]; Point ptStart(contours[largestcontour][startidx]);
             int endidx = v[1]; Point ptEnd(contours[largestcontour][endidx]);
             int faridx = v[2]; Point ptFar(contours[largestcontour][faridx]);

             line(drawing, ptStart, ptEnd, Scalar(0, 255, 0), 1);
             line(drawing, ptStart, ptFar, Scalar(0, 255, 0), 1);
             line(drawing, ptEnd, ptFar, Scalar(0, 255, 0), 1);

             //DRAW POINTS
             circle(drawing, ptFar, 9, Scalar(0, 255, 0), 2);
             circle(drawing, ptEnd, 9, Scalar(0, 0, 255), 2);

         }
     } }

and this is the result: https://imgur.com/a/Ip5mXIhC:\fakepath\Immagine.png

thanks

click to hide/show revision 4
None

updated 2019-01-17 05:59:52 -0600

berak gravatar image

How to delete additional circles in OpenCV's Finger Detection?

i'm developing an app to recognize hand gestures... My program detect 3 useless points.. how can I make sure they are not detected?

i am using opencv 4.0.1 and microsoft visual studio 2017.

this is the code:

//FIND CONVEX HULLS
int largestcontour = 0; int maxarea = 0; 
for (int i = 0; i < contours.size(); i++) {
     double a = contourArea(contours[i]);
     if (a > maxarea)
     {
         maxarea = a;
         largestcontour = i;
     } }

 vector<vector<Point> hull(contours.size());
vector<vector<int> >  hullsI(contours.size());
 vector<vector<Vec4i>>  defects(contours.size());

 for (int i = 0; i < contours.size(); i++) {
     convexHull(contours[i], hull[i], false);
     convexHull(contours[i], hullsI[i], false);
     if (hullsI[i].size() > 3)
     {
         convexityDefects(contours[i], hullsI[i], defects[i]);
     } }

 if (maxarea > 100) {
     drawContours(drawing, hull, largestcontour, Scalar(255, 0, 255),
 3, 8, vector<Vec4i>(), 0, Point());

     for (int j = 0; j < defects[largestcontour].size(); ++j)
     {
         const Vec4i& v = defects[largestcontour][j];
         float depth = v[3] / 256;
         if (depth > 5) //  filter defects by depth
         {
             int startidx = v[0]; Point ptStart(contours[largestcontour][startidx]);
             int endidx = v[1]; Point ptEnd(contours[largestcontour][endidx]);
             int faridx = v[2]; Point ptFar(contours[largestcontour][faridx]);

             line(drawing, ptStart, ptEnd, Scalar(0, 255, 0), 1);
             line(drawing, ptStart, ptFar, Scalar(0, 255, 0), 1);
             line(drawing, ptEnd, ptFar, Scalar(0, 255, 0), 1);

             //DRAW POINTS
             circle(drawing, ptFar, 9, Scalar(0, 255, 0), 2);
             circle(drawing, ptEnd, 9, Scalar(0, 0, 255), 2);

         }
     } }

C:\fakepath\Immagine.pngC:\fakepath\Immagine.png

thanks