资源简介
VC++和openCV实现用手势来控制鼠标的移动,左键单击,左键双击,右键单击的功能,我用的是vs2010和openCV2.3,如要在其他版本使用需要自己配置一下,代码可运行。
代码片段和文件信息
/*
* @ Author: onezeros@yahoo.cn
* @ blog : blog.csdn.net/onezeros
* @ Date : 12/12/2010
* @ Note : You can use this program for any purpose if you keep this note.
* I‘ll appreciate if you can email bugs to me.
* Have A Nice Day!
*/
#include “stdafx.h“
#include “CVobject.h“
#include
#include
#include
#include
using namespace std;
void cvThresholdBidirection(IplImage* imgint lowerint upper)
{
assert(img->nChannels==1);
for (int h=0;hheight;h++){
for (int w=0;wwidth;w++){
unsigned char* p =(unsigned char*)(img->imageData+h*img->widthStep+w);
if (*p<=upper&&*p>=lower){
*p=255;
}else{
*p=0;
}
}
}
}
void cvCvtWhite2RGB(IplImage*srcIplImage* dst)
{
assert(src->nChannels==1);
assert(dst->nChannels==3);
assert(dst->width==src->width);
assert(dst->height==src->height);
for (int h=0;hheight;h++){
for (int w=0;wwidth;w++){
unsigned char* p=(unsigned char*)(dst->imageData+h*dst->widthStep+w*3);
if (*(unsigned char*)(src->imageData+h*src->widthStep+w)==255){//white
*p=255;
*(p+1)=255;
*(p+2)=255;
}
}
}
}
static bool _rankTargets(CvTarget t1CvTarget t2)
{
return t1.erea>t2.erea;
}
void cvFindTargets(const IplImage* img_const int erea_thresholdvector&targets)//here!
{
assert(img_->nChannels==1);
targets.clear();
IplImage* img=cvCreateImage(cvSize(img_->widthimg_->height)IPL_DEPTH_8U1);
cvCopy(img_img);
for (int h=0;hheight;h++){
for (int w=0;wwidth;w++){
if (*(unsigned char*)(img->imageData+h*img->widthStep+w)==255){
CvTarget target;
target.top=h;
target.bottom=h;
target.left=w;
target.right=w;
queue points;
points.push(cvPoint(wh));
*(img->imageData+h*img->widthStep+w)=0;
//find target with breadth iteration
while(!points.empty()){
target.erea++;
CvPoint p=points.front();
points.pop();
if (p.x>0&&*(unsigned char*)(img->imageData+p.y*img->widthStep+p.x-1)==255){//left
*(img->imageData+p.y*img->widthStep+p.x-1)=0;
points.push(cvPoint(p.x-1p.y));
if (target.left>p.x-1){
target.left=p.x-1;
}
}
if (p.y+1height&&*(unsigned char*)(img->imageData+(p.y+1)*img->widthStep+p.x)==255){//bottom
*(img->imageData+(p.y+1)*img->widthStep+p.x)=0;
points.push(cvPoint(p.xp.y+1));
if (target.bottom target.bottom=p.y+1;
}
}
if (p.x+1width&&*(unsigned char*)(img->imageData+p.y*img->widthStep+p.x+1)==255){//right
*(img->imageData+p.y*img->widthStep+p.x+1)=0;
points.push(cvPoint(p.x+1p.y));
if (target.right target.right=p.x+1;
}
}
if (p.y>0&&*(unsigned char*)(img->imageData+(p.y-1)*img->widthStep+p.x)==255){//top
*(img->imageData+(p.y-1)*img->widthStep
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 35016704 2013-06-05 21:33 MouseController\AnotherMouseController.sdf
文件 910 2013-06-04 11:01 MouseController\AnotherMouseController.sln
..A..H. 20992 2013-06-05 21:33 MouseController\AnotherMouseController.suo
..A..H. 13312 2011-01-02 18:55 MouseController\AnotherMouseController.suo.old
文件 4398 2011-01-02 10:16 MouseController\AnotherMouseController.vcproj
文件 6904 2013-04-29 09:38 MouseController\AnotherMouseController.vcxproj
文件 1534 2013-04-29 09:36 MouseController\AnotherMouseController.vcxproj.filters
文件 5485 2013-06-04 18:36 MouseController\CVob
文件 1197 2013-06-04 17:51 MouseController\CVob
文件 6716 2011-01-02 18:54 MouseController\mouseController.cpp
文件 1213 2010-12-15 08:52 MouseController\ReadMe.txt
文件 21232 2011-01-02 09:50 MouseController\simulateTheKeyWitchCanControlMouseInLaptop.JPG
文件 217 2010-12-15 08:52 MouseController\stdafx.cpp
文件 412 2013-06-04 11:18 MouseController\stdafx.h
文件 498 2013-06-04 18:13 MouseController\targetver.h
文件 2090 2013-04-29 09:36 MouseController\UpgradeLog.xm
文件 1449 2013-06-04 11:01 MouseController\UpgradeLog2.xm
文件 3348 2013-06-04 11:01 MouseController\_UpgradeReport_Files\UpgradeReport.css
文件 12505 2010-05-04 01:19 MouseController\_UpgradeReport_Files\UpgradeReport.xslt
文件 69 2013-06-04 11:01 MouseController\_UpgradeReport_Files\UpgradeReport_Minus.gif
文件 71 2013-06-04 11:01 MouseController\_UpgradeReport_Files\UpgradeReport_Plus.gif
目录 0 2013-06-05 21:31 MouseController\ipch\anothermousecontroller-ccc9ca7
目录 0 2013-06-05 21:34 MouseController\Debug
目录 0 2013-06-05 21:29 MouseController\ipch
目录 0 2013-06-05 21:29 MouseController\_UpgradeReport_Files
目录 0 2013-06-05 21:33 MouseController
----------- --------- ---------- ----- ----
35121256 26
评论
共有 条评论