-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gesture_recognition.cpp
136 lines (114 loc) · 2.8 KB
/
Gesture_recognition.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include"Gesture_recognition.h"
void saveTemplate(vector<vector<Point> >t)//此函数用于对获取的手势模板进行保存保存在template1.txt和template2.txt中
{
ofstream template_file1("template3.txt",ios::out);
if(!template_file1)
{
cerr<<"File could be opened "<<endl;
exit(1);
}
for(int i = 0;i<t[0].size();i++)
{
template_file1<<(int)t[0][i].x<<" " ;
template_file1<<(int)t[0][i].y <<" ";
}
template_file1.close();
/* ofstream template_file2("template2.txt",ios::out);
if(!template_file2)
{
cerr<<"File could be opened "<<endl;
exit(1);
}
for(int i = 0;i<t[1].size();i++)
{
template_file2<<(int)t[1][i].x<<" " ;
template_file2<<(int)t[1][i].y <<" ";
}
template_file2.close();*/
}
/**********************************************************************/
void readTemplate1(vector<Point>& a)//从template1.txt中读取模板1
{
ifstream template_file_in1;
template_file_in1.open("template1.txt",ios::in);
if(!template_file_in1)
{
cerr<<"File can not be read"<<endl;
exit(1);
}
int temp1;
int temp2;
while(template_file_in1>>temp1>>temp2)
{
a.push_back(Point(temp1,temp2));
}
template_file_in1.close();
cout<<a.size()<<endl;
}
/*******************************************************************/
void readTemplate2(vector<Point>& b)//从template2.txt中读取模板2
{
ifstream template_file_in2;
template_file_in2.open("template2.txt",ios::in);
if(!template_file_in2)
{
cerr<<"File can not be read"<<endl;
exit(1);
}
int temp1;
int temp2;
while(template_file_in2>>temp1>>temp2)
{
b.push_back(Point(temp1,temp2));
}
template_file_in2.close();
cout<<b.size()<<endl;
}
/************************************************************/
void readTemplate3(vector<Point>& c)//从template2.txt中读取模板2
{
ifstream template_file_in3;
template_file_in3.open("template3.txt",ios::in);
if(!template_file_in3)
{
cerr<<"File can not be read"<<endl;
exit(1);
}
int temp1;
int temp2;
while(template_file_in3>>temp1>>temp2)
{
c.push_back(Point(temp1,temp2));
}
template_file_in3.close();
cout<<c.size()<<endl;
}
/******************************************************************************/
void getTemplates()//需要进一步丰富操作
{
Target target1;
vector<vector<Point> >T;
VideoCapture templa;
Mat frame;
templa>>frame;
for(;;)
{
target1.setRawFame(frame);
target1.showRawFrame();
target1.getHSVmask();
target1.getContours();
target1.showContours();
int c = waitKey(0);
if(c =='y')
{
T.push_back(target1.contours[0]);
cout<<"get template "<<T.size()<<endl;
}
if(c =='q')
break;
target1.contours.clear();
}
saveTemplate(T);
cout<<"templates have been saved"<<T[0]<<endl<<T[1]<<endl;
target1.contours.clear();
}