基于OpenCV的手势识别

zs542507066 2014-11-23 01:37:38
我刚接触手势识别这一块,下了一些源代码看。还是没看懂在识别过程中,是怎么跟模板进行匹配的。
1、匹配之中的数据是通过什么形式存放的?
2、下面的模板他定义的明明的图片bmp格式的数组,那是通过什么方法让摄像头读入的手型数据跟图片去匹配进行识别呢?



下面附点代码:

IplImage* tmp_img = 0;
CvMemStorage* storage_tmp = 0;

CvSeq* handT = 0;
CvSeq* handT1 = 0;
CvSeq* handT2 = 0;


int handTNum = 10; //10个模板

char *tmp_names[] = {"1.bmp","2.bmp","3.bmp","4.bmp","5.bmp","6.bmp","7.bmp","8.bmp","9.bmp","10.bmp"};
char *num_c[] = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"};



/////////////////////////////////////////////////////

//载入模板的轮廓
void init_hand_template()
{

storage_tmp = cvCreateMemStorage(0);

int i = 0;
for(i=0; i<handTNum; i++){

tmp_img = cvLoadImage(tmp_names[i], CV_LOAD_IMAGE_GRAYSCALE);
if(!tmp_img){
printf("未找到文件: %s\n", tmp_names[i]);
continue;
}
//cvShowImage("载入模板", tmp_img);
handT1 = handT2;
cvFindContours( tmp_img, storage_tmp, &handT2, sizeof(CvContour), CV_RETR_EXTERNAL);

if(handT2){
printf("载入模板: %s 成功!\n",tmp_names[i]);
if(handT1 == NULL){
printf("载入第一个模板!\n");
handT = handT2;
}else{
handT2->h_prev = handT1;
handT1->h_next = handT2;
}

}

}


}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////

bool if_match_num = false;
int match_num = -1;

//模板匹配手
void hand_template_match(CvSeq* handT, CvSeq* hand){
int i=0;
int kind = -1;
double hu = 1;

double hutmp;
CvSeq* handp = handT;
int method = CV_CONTOURS_MATCH_I1;

match_num = 0;

if(handT==NULL){return;printf("handT==NULL!\n");}
if(hand==NULL){return;printf("hand==NULL!\n");}

for(i=0; i<handTNum; i++){
hutmp = cvMatchShapes(handp, hand, method, 0);
handp = handp->h_next;

//找到hu矩最小的模板
if(hu > hutmp){
hu = hutmp;
kind = i+1;
}

//printf("%f ", hu);
}

//显示匹配结果
if(hu<((double)Hmatch_value)/100){
printf("匹配模板: %d (%f)", kind, hu);
match_num = kind;
if_match_num = true;
}else{
if_match_num = false;
}
}
...全文
614 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

5,530

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 模式及实现
社区管理员
  • 模式及实现社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧