opencv 获取手势的轮廓

本文介绍了一种使用OpenCV进行手势识别的方法,通过肤色范围的二值化和平滑处理,找到感兴趣区域,进而提取出手势轮廓。程序涉及到色彩空间转换、边缘检测、轮廓查找等步骤,并通过计算轮廓面积来判断手势类型,如闭合的手掌、张开的手掌或拳头。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

程序是以前在网站上搜到了,使用的opencv的版本为0.9.7.如果用opencv1.0的版本来编译的话有两个需要注意的地方

smooth()函数由于版本的问题参数个数不同,需进行调整,还有一个不能写时拷贝的问题,这个问题产生的原因是opencv的一个函数(具体哪个函数我忘了,编译或运行的时候会有提示)有几个参数,由于输入参数和修改后的参数是同一个造成的,解决方法是自己重新定义一个这种类型的变量,为其分配内存空间,作为该函数的输出参数就可以了。

获得手势识别的方法是根据肤色来进行的,内定了一个肤色的范围,通过肤色的二值化后再平滑处理,边缘接触,计算ROI区域,得到感兴趣区,最后将轮廓找出来。

//VERSION: HAND DETECTION 1.0
//AUTHOR: ANDOL LI@CW3/18, Live:lab
//PROJECT: HAND DETECTION PROTOTYPE
//LAST UPDATED: 03/2009

#include "cv.h"
#include "cxcore.h"
#include "highgui.h"
#include "math.h"
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <sstream>
#include <time.h>
using namespace std;
/*
--------------------------------------------*/
int main()
{
 int c = 0;
 CvSeq* a = 0;
    CvCapture* capture = cvCaptureFromCAM(0);//从对摄像头的初始化捕获
  if(!cvQueryFrame(capture)){ cout<<"Video capture failed, please check the camera."<<endl;}else{cout<<"Video camera capture status: OK"<<endl;};
    CvSize sz = cvGetSize(cvQueryFrame( capture));//得到摄像头图像大小
 IplImage* src = cvCreateImage( sz, 8, 3 );//4通道,每个通道8位
 IplImage* hsv_image = cvCreateImage( sz, 8, 3);//
 IplImage* hsv_mask = cvCreateImage( sz, 8, 1);
 IplImage* hsv_edge = cvCreateImage( sz, 8, 1);
 
 CvScalar  hsv_min = cvScalar(0, 30, 80, 0);//得到BGR,&,每个通道的和
 CvScalar  hsv_max = cvScalar(20, 150, 255, 0);
 //
 CvMemStorage* storage = cvCreateMemStorage(0);//分配大小为0的内存空间
 CvMemStorage* areastorage = cvCreateMemStorage(0);
 CvMemStorage* minStorage = cvCreateMemStorage(0);
 CvMemStorage* dftStorage = cvCreateMemStorage(0);
 CvSeq* contours = NULL;
 //
 cvNamedWindow( "src",1);
 //在屏幕上创建一个窗口,第一个参数为窗口标题,第二个参数为窗口属性,
 //设置为0(默认值),或者CV_WINDOW_AUTOSIZE,设置为0,则窗口不会因图像的大小而改变
 //图像只能在窗口中根据窗口的大小进行拉伸或缩放;设置为CV_WINDOW_AUTOSIZE时,窗口会根据图像
 //的实际大小进行自动拉伸或缩放。
 //cvNamedWindow( "hsv-msk",1);
 //cvNamedWindow( "contour",1);
 //////
 while( c != 27)//27为ASCII键值(ESC),
 {
  IplIma

根据摄像头拍摄的人体动作来演奏音乐 ======================================================================== CONSOLE APPLICATION : MusicPlay ======================================================================== AppWizard has created this MusicPlay application for you. This file contains a summary of what you will find in each of the files that make up your MusicPlay application. MusicPlay.dsp This file (the project file) contains information at the project level and is used to build a single project or subproject. Other users can share the project (.dsp) file, but they should export the makefiles locally. MusicPlay.cpp This is the main application source file. MusicPlay.rc This is a listing of all of the Microsoft Windows resources that the program uses. It includes the icons, bitmaps, and cursors that are stored in the RES subdirectory. This file can be directly edited in Microsoft Visual C++. ///////////////////////////////////////////////////////////////////////////// Other standard files: StdAfx.h, StdAfx.cpp These files are used to build a precompiled header (PCH) file named MusicPlay.pch and a precompiled types file named StdAfx.obj. Resource.h This is the standard header file, which defines new resource IDs. Microsoft Visual C++ reads and updates this file. ///////////////////////////////////////////////////////////////////////////// Other notes: AppWizard uses "TODO:" to indicate parts of the source code you should add to or customize. /////////////////////////////////////////////////////////////////////////////
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值