OpenCV模板匹配的方法识别手势

该博客介绍了使用OpenCV进行手势识别的过程,通过模板匹配方法检测手部是否为打开或关闭状态。首先,从RGB图像转换为灰度图像,然后加载开手和闭手模板。接着,通过比较模板与图像区域的相似度来确定手的状态。代码中包含了图像处理的多个步骤,如平滑、转换到HSV空间、肤色检测、膨胀和腐蚀等,以提高检测的准确性。
摘要由CSDN通过智能技术生成

#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 <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>
#endif


static CvMemStorage* storage;
//static 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 IplImage *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, *closedscaledTmpl;
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", "./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 filename[80];
     storage = cvCreateMemStorage(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);
    
     // Convert 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;
    
     closedGrayHandTmpl = 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("

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值