GECKO 1.0
Human-computer interface based on hand gesture recognition
|
00001 //------------------------------------------------------------------------------ 00002 //-- HandDetector 00003 //------------------------------------------------------------------------------ 00004 //-- 00005 //-- Extracts a binary image with the silouette of the candidates to be a hand 00006 //-- 00007 //------------------------------------------------------------------------------ 00008 //-- 00009 //-- This file belongs to the "Gecko - Gesture Recognition" project 00010 //-- (https://github.com/David-Estevez/gecko) 00011 //-- 00012 //------------------------------------------------------------------------------ 00013 //-- Authors: David Estevez Fernandez 00014 //-- Irene Sanz Nieto 00015 //-- 00016 //-- Released under the GPL license (more info on LICENSE.txt file) 00017 //------------------------------------------------------------------------------ 00018 00028 #ifndef HAND_DETECTOR 00029 #define HAND_DETECTOR 00030 00031 #include <opencv2/opencv.hpp> 00032 #include "handUtils.h" 00033 00034 00045 class HandDetector 00046 { 00047 00048 public: 00049 00050 //-- Constructors 00051 //----------------------------------------------------------------------- 00053 HandDetector(); 00055 HandDetector( cv::Mat& ROI); 00056 00057 //-- Destructor 00058 //----------------------------------------------------------------------- 00059 ~HandDetector(); 00060 00061 00062 //-- Calibration loop 00064 void calibrationLoop(cv::VideoCapture); 00066 void defaultValues(cv::VideoCapture cap); 00072 void customValues(cv::VideoCapture cap); 00073 00074 00075 //-- Calibration functions 00076 //----------------------------------------------------------------------- 00077 00079 void calibrate( cv::Mat& ROI); 00080 00082 void calibrate( cv::Scalar lower_limit = cv::Scalar( 0, 58, 89), cv::Scalar upper_limit = cv::Scalar( 25, 173, 229) ); 00084 void getCalibration( cv::Scalar& lower_limit, cv::Scalar& upper_limit); 00085 00086 //-- Hand-detection 00087 //----------------------------------------------------------------------- 00095 void operator()(cv::Mat& src, cv::Mat& dst); 00096 00104 void filter_hand(cv::Mat& src, cv::Mat& dst); 00105 00106 //-- Face-tracking 00107 //----------------------------------------------------------------------- 00109 std::vector< cv::Rect >& getLastFacesPos(); 00110 00120 void drawFaceMarks( const cv::Mat& src, cv::Mat& dst , cv::Scalar color = cv::Scalar(0, 255, 0), int thickness = 1 ); 00121 00122 //-- Get lower and upper level (calibration) 00123 //----------------------------------------------------------------------- 00125 cv::Scalar getLower(); 00127 cv::Scalar getUpper(); 00128 00129 00130 private: 00131 //-- Statistical functions: 00134 int average( cv::Mat& ROI); 00136 int median( cv::Mat& ROI); 00138 int stdDeviation( cv::Mat& ROI); 00139 00140 //-- Hand filtering functions: 00141 //----------------------------------------------------------------------- 00147 void threshold( const cv::Mat& src, cv::Mat& dst); 00153 void filterBlobs( const cv::Mat& src, cv::Mat& dst); 00154 00155 //-- Filter contours: 00156 void filterContours( std::vector< std::vector < cv::Point > >& contours , std::vector< std::vector < cv::Point > >& filteredContours); 00157 00158 //-- Background substractor: 00159 //--------------------------------------------------------------------------------- 00161 backgroundSubstractor bg ; 00163 void initBackgroundSubstractor(); 00169 void backgroundSubstraction(cv::Mat& src, cv::Mat& dst); 00170 00171 00172 //-- Filter face: 00173 //---------------------------------------------------------------------------------- 00175 cv::CascadeClassifier faceDetector; 00176 00178 std::vector< cv::Rect > lastFacesPos; 00179 00181 double factorX, factorY; 00182 00184 void initCascadeClassifier(); 00185 00187 void filterFace(const cv::Mat& src, cv::Mat& dstMask ); 00188 00189 00190 00191 //-- Skin hue calibration 00192 //----------------------------------------------------------------------------------- 00193 //-- HSV limits 00195 cv::Scalar lower_limit; 00197 cv::Scalar upper_limit; 00199 bool hue_invert; 00200 00201 //-- HSV sigma multiplier 00203 int hue_sigma_mult; 00205 int sat_sigma_mult; 00207 int val_sigma_mult; 00208 00210 static const int halfSide=40; 00211 00213 cv::Scalar lower; 00215 cv::Scalar upper; 00216 }; 00217 00218 #endif // HAND_DETECTOR