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);
}
} }
thanks
i don't think, that you can avoid, that it detects the wrist joint
maybe the whole approach (counting convexity defects) is far too brittle ? (e.g. for an upraised thumb, there might be no point 2, and for an uprised little finger no point 1
also see https://github.com/zmdsjtu/Hand_gesture