资源简介
本源码实现了基于摄像头检测手掌和拳头的功能。
1. 源码项目是基于VC2010,需要自行配置好OpenCV2.0以上版本环境。
2. 本源码使用了两个训练文件 palm2.xml和fist2.xml, 运行前应将此两个文件复制到D盘根目录。
代码片段和文件信息
//============================================================================
// 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 “opencv2/core/core.hpp“
#include “opencv2/contrib/contrib.hpp“
#include “opencv2/highgui/highgui.hpp“
#include
#include
#include
using namespace cv;
using namespace std;
const double scale = 1.1;
CvMemStorage* storage = 0;
CvHaarClassifierCascade* cascadeFist = 0;
CvHaarClassifierCascade* cascadePalm = 0;
void Detect_Fist_Palm(IplImage *input_image);
void Detect_Fist(IplImage *input_image);
void fingerTip(IplImage *img);
const char* cascade_nameFist = “d:/fist2.xml“;
const char* cascade_namePalm = “d:/palm2.xml“;
CvRect prevRect;
vector queueRectDetected;
int main()
{
//1.0 api version
CvCapture *capture =0;
IplImage *frame *frame_copy=0 *frame_copy2= 0;
cascadeFist = (CvHaarClassifierCascade*)cvLoad( cascade_nameFist 0 0 0 );
cascadePalm = (CvHaarClassifierCascade*)cvLoad( cascade_namePalm 0 0 0 );
if( !cascadeFist || !cascade_namePalm ){
fprintf( stderr “ERROR: Could not load classifier cascade\n“ );
return -1;
}
storage = cvCreateMemStorage(0);
capture = cvCaptureFromCAM(0);
cvNamedWindow(“result“ 1);
prevRect.width =0;prevRect.height = 0;
prevRect.x =0;prevRect.y = 0;
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);
cvFlip(frame frame_copy 1);
}else{
cvFlip(frame frame_copy 0);
}
//开始检测拳头和手掌
Detect_Fist_Palm(frame_copy);
//检测指尖
//fingerTip(frame_copy);
if(cvWaitKey(10) >= 0)
break;
}
cvReleaseImage( &frame_copy );
cvReleaseCapture( &capture );
}
return 0;
}
void Detect_Fist_Palm(IplImage *img)
{
double scale = 1.1;
CvPoint pt1 pt2;
CvRect maxRectPalm;
maxRectPalm.x = 0;
maxRectPalm.y = 0;
maxRectPalm.width = 0;
maxRectPalm.height = 0;
cvClearMemStorage( storage );
CvSeq* palms = cvHaarDetectobjects(
img
cascadePalm
storage
scale 3 CV_HAAR_DO_CANNY_PRUNING
cvSize(40 40) );
maxRectPalm.height = 0;
maxRectPalm.width = 0;
for( int i = 0; i < (palms ? palms->total : 0); i++ )
{
CvRect* rpalm = (CvRect*)cvGetSeqElem( palms i );
if (rpalm->height > maxRectPalm.height ) maxRectPalm = *rpalm;
}
if ( maxRectPalm.width==0 ){
Detect_Fist(img);
}else{
/*pt1.x = maxRectPa
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2013-06-30 20:22 OpenCV - HandGesture\
文件 69355 2012-08-20 21:10 OpenCV - HandGesture\fist2.xm
文件 15872 2013-06-30 20:15 OpenCV - HandGesture\HelloOpenCV.suo
文件 7184 2013-06-26 12:12 OpenCV - HandGesture\main.cpp
文件 52186 2012-08-20 21:10 OpenCV - HandGesture\palm2.xm
文件 199 2013-06-30 20:20 OpenCV - HandGesture\使用说明.txt
- 上一篇:电路(系统)的线性指标详解
- 下一篇:ov9655设置代码
相关资源
- OpenCV 3d结构光扫描
- opencv_haartraining.exe 和opencv_createsample
- Opencv+Tensorflow入门人工智能处理无密完
- 行人检测Opencv实现
- 基于精确背景补偿的动态目标检测算
- opencv视频资料教程,51cto贾志刚录制的
-
opencv 训练 xm
l文件 haar - opencvforunity最新版
- ubuntu opencv qt 三位一体的摄像头源码
- opencv-2.4.8-part1
- OpenCV百度云链接.txt
- opencv图像处理视频
- 多边形的扫描转换
- 数字图像处理-3.7混合空间增强法-骨骼
- opencv训练分类器总结与疑问
- Patch_Sparsity代码opencv
- opencv 视频运动物体检测
- 8点算法计算基础矩阵计算机视觉Ope
- 使用Linux的V4L2读取摄像头数据+Opencv图
- opencv_createsamples.exe
- GrabCut-opencv源码注释
- 工程训练物料搬运小车OpenCV程序.rar
- 手势识别传感器paj7620 arduino板使用代
- opencv处理图像88分块DCT变换和量化
- opencv实现背景分离
- opencv 车牌 字符识别
- Windows下基于Opencv+Qt的视频聊天客户端
- OpenCV 飞行游戏手势控制源码
- Qt界面多线程opencv调用摄像头
- 基于django的人脸检测Web平台搭建基于
评论
共有 条评论