Last active
December 18, 2015 13:18
-
-
Save jayrambhia/5788734 to your computer and use it in GitHub Desktop.
Fingertips detection using Kinect
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Canny(img_thresh, img_canny, 60, 110); | |
| vector< vector<Point> > contours; | |
| vector< vector<Point> >hull; | |
| vector< vector<int> >hullI; | |
| findContours(img_canny, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE); | |
| for(i = 0; i < contours.size(); i++) | |
| { | |
| convexHull(contours[i], hull[i], false); | |
| convexHull(contours[i], hullI[i], false); | |
| } | |
| # draw Contours | |
| Mat drawing = Mat::zeros(img_thresh.size(), CV_8UC3); | |
| for(i = 0; i < contours.size(); i++) | |
| { | |
| Scalar color = Scalar(255, 255, 255); | |
| drawContours(drawing, contours, i, color, 1, 8, vector<Vec4i>(), 0, Point()); | |
| drawContours(drawing, hull, i, color, 1, 8, vector<Vec4i>(), 0, Point()); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| vector< vector<Point> >nfhull; | |
| int chullx, chully, add_flag=1, nhullindex=-1; | |
| for (i=0; i<finhull.size(); i++) | |
| { | |
| nfhull.push_back(vector<Point>()); | |
| for(j=0; j<finhull[i].size(); j++) | |
| { | |
| chullx = finhull[i][j].x; | |
| chully = finhull[i][j].y; | |
| add_flag = 1; | |
| for (k=0; k<nfhull[i].size(); k++) | |
| { | |
| if (nfhull[i][k].x > chullx - 15 && nfhull[i][k].x < chullx + 15 | |
| && nfhull[i][k].y > chully - 15 && nfhull[i][k].y < chully + 15) | |
| { | |
| add_flag = 0; | |
| break; | |
| } | |
| } | |
| if (add_flag) | |
| { | |
| nfhull[i].push_back(Point(chullx, chully)); | |
| } | |
| } | |
| } | |
| # draw hull Points | |
| for (i=0; i<nfhull.size(); i++) | |
| { | |
| for(j=0; j<nfhull[i].size(); j++) | |
| { | |
| circle(drawing, nfhull[i][j], 15, (255, 0, 255), 1, 8); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Vector< vector<Point> > fhull, finhull; | |
| int fhullIndex=-1; | |
| Point p1, p2, hullP; | |
| double th1, th2, th; | |
| int i, j, k; | |
| for(i=0; i < contours.size(); i++) | |
| { | |
| if (contours[i].size() < 50) | |
| { | |
| continue; | |
| } | |
| fhull.push_back(vector<Point>()); | |
| finhull.push_back(vector<Point>()); | |
| fhullIndex++; | |
| for(j=0; j< hullI[i].size(); j++) | |
| { | |
| hullP = contours[i][hullI[i][j]]; | |
| p1 = contours[i][hullI[i][j] - 16]; | |
| p2 = contours[i][hullI[i][j] + 16]; | |
| th1 = abs(atan2(hullP.y - p1.y, hullP.x - p1.x)*180/CV_PI); | |
| th2 = abs(atan2(hullP.y - p2.y, hullP.x - p2.x)*180/CV_PI); | |
| th = abs(th1 - th2); | |
| if (th < 40) | |
| { | |
| finhull[fhullIndex].push_back(hullP); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # get Maximum and Minimum depth | |
| double min_intensity, max_intensity; | |
| minMaxLoc(img_depth, &min_intensity, &max_intensity); | |
| int i, j, k, sum = 0, count = 0; | |
| for(i = 0; i < 480; i++) | |
| { | |
| for(j = 0 ; j < 640; j++) | |
| { | |
| if(img_depth.at<uchar>(i, j) < 180) | |
| { | |
| sum += img_depth.at<uchar>(i, j); | |
| count++; | |
| } | |
| } | |
| } | |
| int range = 15; | |
| if(count) | |
| { | |
| range = 190 - sum/count; | |
| } | |
| Mat img_thresh; | |
| threshold(img_depth, img_thresh, min_intensity + range, 255, THRESH_BINARY_INV); | |
| medianBlur(img_thresh, img_thresh, 5); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment