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