文档下载 文档下载导航
设为首页 | 加入收藏
搜索 请输入内容:  
 导航当前位置: 文档下载 > 所有分类 > IT/计算机 > 互联网 > Hand_Gesture_Detection
侵权投诉

Hand_Gesture_Detection

手势检测源码

/* ---------------------------------------------------------------------------------------------------------------------------- Hand Gesture Detection Done By Mohafiz Raz.M.A Febin Jose C.Sanjay Arvind ---------------------------------------------------------------------------------------------------------------------------- */ #include <opencv/cv.h> #include <opencv/highgui.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <assert.h> #include <math.h> #include <float.h> #include <limits.h> #include <time.h> #include <ctype.h> // Create a string that contains the exact cascade name // Contains the trained classifer for detecting hand const char *cascade_name="hand.xml"; //The function detects the hand from input frame and draws a rectangle around the detected portion of the frame void detect_and_draw( IplImage* img ) { // Create memory for calculations static CvMemStorage* storage = 0; // Create a new Haar classifier static CvHaarClassifierCascade* cascade = 0; // Sets the scale with which the rectangle is drawn with int scale = 1; // Create two points to represent the hand locations CvPoint pt1, pt2; // Looping variable int i; // Load the HaarClassifierCascade cascade = (CvHaarClassifierCascade*)cvLoad( cascade_name, 0, 0, 0 ); // Check whether the cascade has loaded successfully. Else report and error and quit if( !cascade ) { fprintf( stderr, "ERROR: Could not load classifier cascade\n" ); return; } // Allocate the memory storage storage = cvCreateMemStorage(0); // Create a new named window with title: result cvNamedWindow( "result", 1 ); // Clear the memory storage which was used before cvClearMemStorage( storage ); // Find whether the cascade is loaded, to find the hands. If yes, then: if( cascade ) { // There can be more than one hand in an image. So create a growable sequence of hands. // Detect the objects and store them in the sequence CvSeq* hands = cvHaarDetectObjects( img, cascade, storage, 1.1, 2, CV_HAAR_DO_CANNY_PRUNING, cvSize(40, 40) ); // Loop the number of hands found. for( i = 0; i < (hands ? hands->total : 0); i++ ) { // Create a new rectangle for drawing the hand CvRect* r = (CvRect*)cvGetSeqElem( hands, i ); // Find the dimensions of the hand,and scale it if necessary pt1.x = r->x*scale; pt2.x = (r->x+r->width)*scale; pt1.y = r->y*scale; pt2.y = (r->y+r->height)*scale; // Draw the rectangle in the input image cvRectangle( img, pt1, pt2, CV_RGB(230,20,232), 3, 8, 0 ); } } // Show the image in the window name

第1页

你可能喜欢

热门文档

相关文档

站点地图 | 文档上传 | 侵权投诉 | 手机版
本站所有资源均来自互联网,本站只负责收集和整理,均不承担任何法律责任,如有侵权等其它行为请联系我们.
文档下载 Copyright 2013 doc.guandang.net All Rights Reserved.  -  email