资源简介
OPENCV手势动作识别-石头剪刀布,OpenCV3.0版本,VS2012完美运行。
代码片段和文件信息
#include “opencv2/opencv.hpp“
#include
#include
using namespace std;
using namespace cv;
int num=0;
Mat MoveDetect(Mat background Mat img)
{ //对三个模板进行处理
Mat cloth= imread(“cloth.bmp“);
cvtColor(cloth cloth CV_BGR2GRAY);
threshold(cloth cloth 40 255 CV_THRESH_BINARY);
vector> contours1;
vector hierarcy1;
findContours(cloth contours1 hierarcy1 CV_RETR_EXTERNAL CV_CHAIN_APPROX_NONE);
Mat scissors= imread(“scissors.bmp“);
cvtColor(scissors scissors CV_BGR2GRAY);
threshold(scissors scissors 40 255 CV_THRESH_BINARY);
vector> contours2;
vector hierarcy2;
findContours(scissors contours2 hierarcy2 CV_RETR_EXTERNAL CV_CHAIN_APPROX_NONE);
Mat stone= imread(“stone.bmp“);
cvtColor(stone stone CV_BGR2GRAY);
threshold(stone stone 40 255 CV_THRESH_BINARY);
vector> contours3;
vector hierarcy3;
findContours(stone contours3 hierarcy3 CV_RETR_EXTERNAL CV_CHAIN_APPROX_NONE);
//得出减去背景后的图像
Mat dst = img.clone();
Mat gray1 gray2;
cvtColor(background gray1 CV_BGR2GRAY);
cvtColor(img gray2 CV_BGR2GRAY);
Mat diff;
absdiff(gray1 gray2 diff);
//imshow(“absdiss“ diff);
threshold(diff diff 70 255 CV_THRESH_BINARY);
//imshow(“threshold“ diff);
Mat element = getStructuringElement(MORPH_RECT Size(3 3));
Mat element2 = getStructuringElement(MORPH_RECT Size(1010));
medianBlur(diff diff 5);//滤波参数根据自己环境调整
//imshow(“medianBlur“ diff);
/*blur(diff diff Size(10 10));
imshow(“blur“ diff);*/
erode(diff diff element);
//imshow(“erode“ diff);
dilate(diff diff element2);//膨胀参数根据自己环境调整
imshow(“dilate“ diff);
vector> contours;
vector hierarcy;
findContours(diff contours hierarcy CV_RETR_EXTERNAL CHAIN_APPROX_NONE); //查找轮廓
//drawContours(result contours -1 Scalar(00255) 2 8); //绘制轮廓
for(int i=0;i {
double matchrate1=matchShapes(contours1[0]contours[i]CV_CONTOURS_MATCH_I1 0.0);
cout<<“index1=“< double matchrate2=matchShapes(contours2[0]contours[i]CV_CONTOURS_MATCH_I1 0.0);
cout<<“index2=“< double matchrate3=matchShapes(contours3[0]contours[i]CV_CONTOURS_MATCH_I1 0.0);
cout<<“index3=“< if(matchrate1 {
Mat result= imread(“cloth1.jpg“);
imshow(“jieguo“ result);
putText(dst “cloth“ Point(30 70) CV_FONT_HERSHEY_COMPLEX 2 Scalar(0 0 255) 2 8);
}
if(matchrate2 {
Mat result= imread(“scissors1.jpg“);
imshow(“jieguo“ result);
putText(dst “scissors“ Point(30 70) CV_FONT_HERSHEY_COMPLEX 2 Scalar(0 0 255) 2 8);
}
if(matchrate3
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-04-22 17:14 test2\
目录 0 2018-04-22 16:28 test2\Debug\
文件 95744 2018-04-22 17:07 test2\Debug\test2.exe
文件 579572 2018-04-22 17:07 test2\Debug\test2.ilk
文件 1534976 2018-04-22 17:07 test2\Debug\test2.pdb
目录 0 2018-04-22 10:35 test2\test2\
目录 0 2018-04-22 17:07 test2\test2\Debug\
文件 23300 2018-04-22 17:07 test2\test2\Debug\CL.read.1.tlog
文件 276 2018-04-22 17:07 test2\test2\Debug\CL.write.1.tlog
文件 592 2018-04-22 17:07 test2\test2\Debug\cl.command.1.tlog
文件 2 2018-04-22 17:07 test2\test2\Debug\li
文件 2 2018-04-22 17:07 test2\test2\Debug\li
文件 2 2018-04-22 17:07 test2\test2\Debug\li
文件 2 2018-04-22 17:07 test2\test2\Debug\li
文件 2 2018-04-22 17:07 test2\test2\Debug\li
文件 2 2018-04-22 17:07 test2\test2\Debug\li
文件 2 2018-04-22 17:07 test2\test2\Debug\li
文件 2 2018-04-22 17:07 test2\test2\Debug\li
文件 2 2018-04-22 17:07 test2\test2\Debug\li
文件 2 2018-04-22 17:07 test2\test2\Debug\li
文件 2 2018-04-22 17:07 test2\test2\Debug\li
文件 2 2018-04-22 17:07 test2\test2\Debug\li
文件 2 2018-04-22 17:07 test2\test2\Debug\li
文件 2 2018-04-22 17:07 test2\test2\Debug\li
文件 2656 2018-04-22 17:07 test2\test2\Debug\li
文件 8208 2018-04-22 17:07 test2\test2\Debug\li
文件 350 2018-04-22 17:07 test2\test2\Debug\li
文件 320616 2018-04-22 17:07 test2\test2\Debug\test.obj
文件 3731 2018-04-22 15:52 test2\test2\Debug\test2.Build.CppClean.log
文件 58 2018-04-22 17:07 test2\test2\Debug\test2.lastbuildstate
文件 3256 2018-04-22 17:07 test2\test2\Debug\test2.log
............此处省略14个文件信息
- 上一篇:HMPla
yer-2013.01.rar - 下一篇:高校教师工资绩效管理系统
评论
共有 条评论