1、opencv手势识别#ifdef _CH_#define WIN32#error The file needs cvaux, which is not wrapped yet. Sorry#endif#ifndef _EiC#include cv.h#include cxcore.h#include cvaux.h#include highgui.h#include #include #include #include #include #include #include #include #include #endifstatic CvMemStorage* storage;/static
2、double color;static CvSize imgSize;static CvSize tmplSize;static CvSeq* contour;static CvSeq* biggest;static CvCapture* capture = 0;static int isHandOpen = 1;/static double color;static CvScalar color;static IplImage *img;static IplImage *tmpImg;static IplImage *conv;static IplImage *H;static IplIma
3、ge *S;static IplImage *V;static IplImage *tmpH1;static IplImage *tmpS1;static IplImage *tmpH2;static IplImage *tmpS2;static IplImage *tmpH3;static IplImage *tmpS3;static IplImage *openHandTmpl, *closedHandTmpl;static IplImage *openGrayHandTmpl, *closedGrayHandTmpl;static IplImage *openscaledTmpl, *c
4、losedscaledTmpl;static IplImage *openMatchResult, *closedMatchResult;FILE *output;void handDetect( IplImage *img);static int numImg = 10;char *names = ./images/test01.jpg, ./images/test02.jpg, ./images/test03.jpg, ./images/test04.jpg, ./images/test05.jpg, ./images/test06.jpg, ./images/test07.jpg, ./
5、images/test08.jpg, ./images/test09.jpg, ./images/test10.jpg;char *resultsiamge = result01.jpg,result02.jpg,result03.jpg,result04.jpg,result05.jpg,result06.jpg,result07.jpg,result08.jpg,result09.jpg,result10.jpg;int main( int argc, char* argv ) int i = 0; char filename80; storage = cvCreateMemStorage
6、(0); #ifdef DEBUG cvNamedWindow( Template1, 1 ); cvNamedWindow( Template2, 1 ); cvNamedWindow( Comp Results1, 1 ); cvNamedWindow( Comp Results2, 1 ); cvNamedWindow( Skin Detection, 1 );#endif openHandTmpl = cvLoadImage(openHandTmpl.jpg,1); closedHandTmpl = cvLoadImage(closedHandTmpl.jpg,1); / Conver
7、t form RGB to GRAY tmplSize.width = openHandTmpl-width; tmplSize.height = openHandTmpl-height; openGrayHandTmpl = cvCreateImage( tmplSize, IPL_DEPTH_8U, 1); cvCvtColor( openHandTmpl, openGrayHandTmpl, CV_BGR2GRAY ); tmplSize.width = closedHandTmpl-width; tmplSize.height = closedHandTmpl-height; clos
8、edGrayHandTmpl = cvCreateImage( tmplSize, IPL_DEPTH_8U, 1); cvCvtColor( closedHandTmpl, closedGrayHandTmpl, CV_BGR2GRAY ); cvNamedWindow(source,1); cvMoveWindow(source,0,0); cvNamedWindow( Results, 1 ); cvMoveWindow(Results,400,300); cvAddSearchPath(images); / Open the Output File output = fopen( re
9、sults.log, w ); / Color for contour drawing color = CV_RGB( 255,255,255 ); if( argc = 1 | (argc = 2 & strlen(argv1) = 1 & isdigit(argv10) capture = cvCaptureFromCAM( argc = 2 ? argv10 - 0 : 0 ); else if( argc = 2 ) capture = cvCaptureFromAVI( argv1 ); if(capture != 0) for(;) IplImage *frame;/, *fram
10、e_copy; if( !cvGrabFrame( capture ) break; frame = cvRetrieveFrame( capture ); if( !frame ) break; imgSize.width = frame-width; imgSize.height = frame-height;/ frame_copy = cvCloneImage( frame ); handDetect( frame ); if( cvWaitKey( 10 ) = 0 ) break; cvReleaseCapture( &capture ); else for ( i = 0; i
11、width; imgSize.height = img-height; handDetect( img );/ strcat(filename, names); cvSaveImage(resultsiamge, img); cvReleaseImage(&img); cvWaitKey(0); / for ( i = 0; i width;/ tmplSize.height = openHandTmpl-height;/ / openGrayHandTmpl = cvCreateImage( tmplSize, IPL_DEPTH_8U, 1);/ cvCvtColor( openHandT
12、mpl, openGrayHandTmpl, CV_BGR2GRAY );/ / tmplSize.width = closedHandTmpl-width;/ tmplSize.height = closedHandTmpl-height;/ / closedGrayHandTmpl = cvCreateImage( tmplSize, IPL_DEPTH_8U, 1);/ cvCvtColor( closedHandTmpl, closedGrayHandTmpl, CV_BGR2GRAY );/ Generate processing images tmpImg = cvCloneIma
13、ge(img); conv = cvCreateImage( imgSize, IPL_DEPTH_8U, 3); tmpH1 = cvCreateImage( imgSize, IPL_DEPTH_8U, 1); tmpS1 = cvCreateImage( imgSize, IPL_DEPTH_8U, 1); tmpH2 = cvCreateImage( imgSize, IPL_DEPTH_8U, 1); tmpS2 = cvCreateImage( imgSize, IPL_DEPTH_8U, 1); tmpH3 = cvCreateImage( imgSize, IPL_DEPTH_
14、8U, 1); tmpS3 = cvCreateImage( imgSize, IPL_DEPTH_8U, 1); H = cvCreateImage( imgSize, IPL_DEPTH_8U, 1); S = cvCreateImage( imgSize, IPL_DEPTH_8U, 1); V = cvCreateImage( imgSize, IPL_DEPTH_8U, 1); / Flip the image if in capture mode if ( capture ) cvFlip(conv, conv, 0); / Image Smoothing /cvSmooth(im
15、g,tmpImg,CV_BLUR,3,3); cvSmooth(img,img,CV_GAUSSIAN,3,3); / Convert to HSV cvCvtColor( tmpImg, conv, CV_BGR2HSV ); / Split to HSV planes cvCvtPixToPlane(conv,H,S,V,0); / Average Illumination averageValue = cvAvg( V , 0); fprintf(output, Illumination Level = %fn, averageValue.val0); / Detect skin ton
16、e Hues and Saturations / NOTE: Hue values need to be doubled for actual / Red to Orange Hue with High Saturation / Hue 0 to 28 degree and Sat 190 to 200 cvInRangeS(H,cvScalar(0.0,0.0,0,0),cvScalar(14.0,0.0,0,0),tmpH1); cvInRangeS(S,cvScalar(75.0,0.0,0,0),cvScalar(200.,0.0,0,0),tmpS1); cvAnd(tmpH1,tm
17、pS1,tmpH1,0); / Red Hue with Low Saturation / Hue 0 to 26 degree and Sat 20 to 90 cvInRangeS(H,cvScalar(0.0,0.0,0,0),cvScalar(13.0,0.0,0,0),tmpH2); cvInRangeS(S,cvScalar(20.0,0.0,0,0),cvScalar(90.0,0.0,0,0),tmpS2); cvAnd(tmpH2,tmpS2,tmpH2,0); / Red Hue to Pink with Low Saturation / Hue 340 to 360 de
18、gree and Sat 15 to 90 cvInRangeS(H,cvScalar(170.0,0.0,0,0),cvScalar(180.0,0.0,0,0),tmpH3); cvInRangeS(S,cvScalar(15.0,0.0,0,0),cvScalar(90.,0.0,0,0),tmpS3); cvAnd(tmpH3,tmpS3,tmpH3,0); / Combine the Hue and Sat detections cvOr(tmpH3,tmpH2,tmpH2,0); cvOr(tmpH1,tmpH2,tmpH1,0); / Dilation and Erosion /
19、 Structuring Element Generation dilationElement = cvCreateStructuringElementEx( 5,5,3,3, CV_SHAPE_RECT , 0 ); erosionElement = cvCreateStructuringElementEx( 5,5,3,3, CV_SHAPE_RECT , 0 ); / Dilation adds a layer on, and returns things to the correct size. cvDilate(tmpH1,tmpH2,dilationElement,1); / Erosion peels a layer of pixels off, and makes small regions disappear cvErode(tmpH1,tmpH3,erosionElement,1); / Find the contours of all
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1