opencv实现的手势识别,石头剪刀布的实现,亲测可运行


一个实现石头剪刀布的小程序,基于opencv,在vs2010和opencv2.4.4下可以完美运行。
资源截图
代码片段和文件信息
// @Author:onezeros@yahoo.cn
// @Date:10/8/2010

//abstract features:width/height white pixels ratio
#include 
#include 
#include 

#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;

void featrue(IplImage* imgfloat& widHeiRatiofloat& whitePixelRatio)
{
assert(img->nChannels==1);
unsigned long whitePixelNum=0;

int top=img->height;
int bottom=-1;
int right=0;
for (int w=0;wwidth;w++){
bool isBlack=true;
int b=-1;
int t=-1;
unsigned char* pline=(unsigned char*)(img->imageData);
for (int h=0;hheight;h++pline+=img->widthStep){
if (*(pline+w)>100){
isBlack=false;
whitePixelNum++;
if (t<0){
t=h;
b=h;
}else{
b=h;
}
}
}
if (isBlack){
break;
}
if (top>t){
top=t;
}
if (bottom bottom=b;
}

right=w;
}
widHeiRatio=(float)right/(bottom-top);
whitePixelRatio=(float)whitePixelNum/right/(bottom-top);

}
int main( int argc char** argv )
{
IplImage* pImg;
char strBuff[3][100];
fstream filefeature1(“feature-widthHeight.txt“ios::out);
fstream filefeature2(“feature-whiteRatio.txt“ios::out);
float widHeiRatio=0;
float whiteRatio=0;
for(int counter=0;counter<100;counter++){
sprintf(strBuff[0]“images-train/stone-%03d.bmp“counter);
sprintf(strBuff[1]“images-train/scissors-%03d.bmp“counter);
sprintf(strBuff[2]“images-train/cloth-%03d.bmp“counter);
for (int i=0;i<3;i++){
pImg=cvLoadImage(strBuff[i]CV_LOAD_IMAGE_GRAYSCALE);
if (pImg==NULL){
cout<<“error happened while loading image:“< cvWaitKey(0);
}
featrue(pImgwidHeiRatiowhiteRatio);
cvReleaseImage(&pImg);
filefeature1< filefeature2< cout< }
filefeature1< filefeature2<
}
filefeature1.close();
filefeature2.close();

return 0;
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2013-11-12 21:56  opencv实现的手势识别,石头剪刀布的实现
     目录           0  2013-11-21 23:00  opencv实现的手势识别,石头剪刀布的实现StoneScissorsCloth
     目录           0  2013-11-21 22:48  opencv实现的手势识别,石头剪刀布的实现StoneScissorsClothRelease
     文件       41068  2013-11-19 21:44  opencv实现的手势识别,石头剪刀布的实现StoneScissorsClothReleaseCL.read.1.tlog
     文件        1448  2013-11-19 21:44  opencv实现的手势识别,石头剪刀布的实现StoneScissorsClothReleaseCL.write.1.tlog
     文件       26624  2013-11-21 22:38  opencv实现的手势识别,石头剪刀布的实现StoneScissorsClothReleaseStoneScissorsCloth.exe
     文件         381  2013-11-21 22:38  opencv实现的手势识别,石头剪刀布的实现StoneScissorsClothReleaseStoneScissorsCloth.exe.intermediate.manifest
     文件         150  2013-11-21 22:48  opencv实现的手势识别,石头剪刀布的实现StoneScissorsClothReleaseStoneScissorsCloth.lastbuildstate
     文件        1218  2013-11-21 22:48  opencv实现的手势识别,石头剪刀布的实现StoneScissorsClothReleaseStoneScissorsCloth.log
     文件     1027072  2013-11-21 22:38  opencv实现的手势识别,石头剪刀布的实现StoneScissorsClothReleaseStoneScissorsCloth.pdb
     文件        1320  2013-11-19 15:36  opencv实现的手势识别,石头剪刀布的实现StoneScissorsClothReleaseStoneScissorsCloth.res
     文件     1745641  2013-11-19 21:44  opencv实现的手势识别,石头剪刀布的实现StoneScissorsClothReleaseStoneScissorsCloth_recognize.obj
     文件        1910  2013-11-19 21:44  opencv实现的手势识别,石头剪刀布的实现StoneScissorsClothReleasecl.command.1.tlog
     文件           2  2013-11-21 22:38  opencv实现的手势识别,石头剪刀布的实现StoneScissorsClothReleaselink-cvtres.read.1.tlog
     文件           2  2013-11-21 22:38  opencv实现的手势识别,石头剪刀布的实现StoneScissorsClothReleaselink-cvtres.write.1.tlog
     文件        5674  2013-11-21 22:38  opencv实现的手势识别,石头剪刀布的实现StoneScissorsClothReleaselink.command.1.tlog
     文件        8166  2013-11-21 22:38  opencv实现的手势识别,石头剪刀布的实现StoneScissorsClothReleaselink.read.1.tlog
     文件        1236  2013-11-21 22:38  opencv实现的手势识别,石头剪刀布的实现StoneScissorsClothReleaselink.write.1.tlog
     文件         718  2013-11-21 22:38  opencv实现的手势识别,石头剪刀布的实现StoneScissorsClothReleasemt.command.1.tlog
     文件        1632  2013-11-21 22:38  opencv实现的手势识别,石头剪刀布的实现StoneScissorsClothReleasemt.read.1.tlog
     文件         516  2013-11-21 22:38  opencv实现的手势识别,石头剪刀布的实现StoneScissorsClothReleasemt.write.1.tlog
     文件        1610  2013-11-19 15:36  opencv实现的手势识别,石头剪刀布的实现StoneScissorsClothRelease
c.command.1.tlog
     文件        5576  2013-11-19 15:36  opencv实现的手势识别,石头剪刀布的实现StoneScissorsClothRelease
c.read.1.tlog
     文件         934  2013-11-19 15:36  opencv实现的手势识别,石头剪刀布的实现StoneScissorsClothRelease
c.write.1.tlog
     文件      765952  2013-11-19 21:44  opencv实现的手势识别,石头剪刀布的实现StoneScissorsClothReleasevc100.pdb
     文件      823548  2010-10-10 08:22  opencv实现的手势识别,石头剪刀布的实现StoneScissorsClothStoneScissorsCloth-images.zip
     文件       19532  2013-11-20 09:57  opencv实现的手势识别,石头剪刀布的实现StoneScissorsClothStoneScissorsCloth.aps
     文件        1964  2010-10-08 21:19  opencv实现的手势识别,石头剪刀布的实现StoneScissorsClothStoneScissorsCloth.rc
     文件    13979648  2013-11-21 23:01  opencv实现的手势识别,石头剪刀布的实现StoneScissorsClothStoneScissorsCloth.sdf
     文件         902  2013-11-19 11:05  opencv实现的手势识别,石头剪刀布的实现StoneScissorsClothStoneScissorsCloth.sln
     文件       30208  2013-11-21 23:00  opencv实现的手势识别,石头剪刀布的实现StoneScissorsClothStoneScissorsCloth.suo
............此处省略30个文件信息

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)