Quantcast
Viewing latest article 19
Browse Latest Browse All 22

Hand gesture detection and recognition using openCV 2

Image may be NSFW.
Clik here to view.
hand gesture detect using openCV - demo

Before the example – why haar classifiers for hand gesture detection

As mentioned in one of early articles such like hand gesture detection and recognition using openCV, there are two main ways to detect hand gestures, including skin colour segmentation and haar classifier training, although recently some feature-detecting algorithms are used to detect hand gestures such like swift. Skin colour segmentation is a dead end – hand colours can be white, or black, or any other colours – depends on the varieties of environmental light conditions. So using a skin colour model (as in The colour range for HSV skin extraction) with a specific colour range can do hand gesture recognition quite well in strict scenarios but this still faces tough challenges for other use.

The source codes

//============================================================================
// Name : opencv_handdetect.cpp
// Author : andol li, andol@andol.info
// Version : 0.1
// Copyright : 2012
// Description : using haartraining results to detect the hand gesture of FIST in video stream.
//
//============================================================================
#include <opencv/cv.h>
#include <opencv/cxcore.h>
#include <opencv/highgui.h>#include
#include

using namespace cv;
using namespace std;

const double scale = 1.1;

//1.0 api version
CvMemStorage* storage = 0;
CvHaarClassifierCascade* cascade = 0;
void detectAndDraw(IplImage *input_image);
const char* cascade_name = “fist.xml”;

//define the path to cascade file
string cascadeName = “fist.xml”; /*ROBUST-fist detection haartraining file*/

int main()
{
//1.0 api version
CvCapture *capture =0;
IplImage *frame, *frame_copy = 0;
cascade = (CvHaarClassifierCascade*)cvLoad( cascade_name, 0, 0, 0 );
if( !cascade ){
fprintf( stderr, “ERROR: Could not load classifier cascade\n” );
return -1;
}
storage = cvCreateMemStorage(0);
capture = cvCaptureFromCAM(0);
cvNamedWindow(“result”, 1);
if(capture){
for(;;){
if(!cvGrabFrame(capture)) break;
frame = cvRetrieveFrame( capture);
if(!frame) break;
if(!frame_copy) frame_copy = cvCreateImage(cvSize(frame->width, frame->height), IPL_DEPTH_8U, frame->nChannels);
if(frame->origin == IPL_ORIGIN_TL)
cvCopy(frame, frame_copy, 0);
else
cvFlip(frame, frame_copy, 0);
detectAndDraw(frame_copy);
if(cvWaitKey(10) >= 0) break;
}
cvReleaseImage( &frame_copy );
cvReleaseCapture( &capture );
}

return 0;
}

void detectAndDraw(IplImage *img)
{
double scale = 1.1;
IplImage* temp = cvCreateImage( cvSize(img->width/scale,img->height/scale), 8, 3 );
CvPoint pt1, pt2;
int i;

cvClearMemStorage( storage );
if(cascade){
CvSeq* faces = cvHaarDetectObjects(
img,
cascade,
storage,
scale, 2, CV_HAAR_DO_CANNY_PRUNING,
cvSize(24, 24) );
for( i = 0; i < (faces ? faces->total : 0); i++ )
{
CvRect* r = (CvRect*)cvGetSeqElem( faces, i );
pt1.x = r->x*scale;
pt2.x = (r->x+r->width)*scale;
pt1.y = r->y*scale;
pt2.y = (r->y+r->height)*scale;
cvRectangle( img, pt1, pt2, CV_RGB(200, 0, 0), 1, 8, 0 );
}
}
cvShowImage(“result”, img);
cvReleaseImage( &temp );
}

it can be downloaded from here SOURCE CODES OF HAND GESTURE DETECTION AND RECOGNITION USING OPENCV, relevant files/codes are for requests.


Viewing latest article 19
Browse Latest Browse All 22

Trending Articles