aihot  2017-04-27 20:49:14  OpenCV |   查看评论   
  •         Mat show_img;  
  •         frame.copyTo(show_img, skinArea);  
  •   
  •         vector<vector<Point> > contours;  
  •         vector<Vec4i> hierarchy;  
  •   
  •         //寻找轮廓  
  •         findContours(skinArea, contours, hierarchy, CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE);  
  •   
  •         // 找到最大的轮廓  
  •         int index;  
  •         double area, maxArea(0);  
  •         for (int i=0; i < contours.size(); i++)  
  •         {  
  •             area = contourArea(Mat(contours[i]));  
  •             if (area > maxArea)  
  •             {  
  •                 maxArea = area;  
  •                 index = i;  
  •             }             
  •         }  
  •   
  •         //drawContours(frame, contours, index, Scalar(0, 0, 255), 2, 8, hierarchy );  
  •           
  •         Moments moment = moments(skinArea, true);  
  •         Point center(moment.m10/moment.m00, moment.m01/moment.m00);  
  •         circle(show_img, center, 8 ,Scalar(0, 0, 255), CV_FILLED);  
  •   
  •         // 寻找指尖  
  •         vector<Point> couPoint = contours[index];  
  •         vector<Point> fingerTips;  
  •         Point tmp;  
  •         int max(0), count(0), notice(0);  
  •         for (int i = 0; i < couPoint.size(); i++)  
  •         {  
  •             tmp = couPoint[i];  
  •             int dist = (tmp.x - center.x) * (tmp.x - center.x) + (tmp.y - center.y) * (tmp.y - center.y);  
  •             if (dist > max)  
  •             {  
  •                 max = dist;  
  •                 notice = i;  
  •             }  
  •   
  •             // 计算最大值保持的点数,如果大于40(这个值需要设置,本来想根据max值来设置,  
  •  

    除特别注明外,本站所有文章均为 赢咖4注册 原创,转载请注明出处来自简单粗糙的指尖检测方法(FingerTips Detection)

    留言与评论(共有 0 条评论)
       
    验证码:
    [lianlun]1[/lianlun]