-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
332 lines (222 loc) · 8.11 KB
/
main.cpp
File metadata and controls
332 lines (222 loc) · 8.11 KB
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
#include <iostream>
#include "kinecthandler.h"
#include "leaphandler.h"
#include "gesturemanager.h"
#include "doubleswipemanager.h"
#include "swipemanager.h"
#include "tappingmanager.h"
#include "monitorhandsmanager.h"
#include "ioeventmanager.h"
#include "scrollupdownmanager.h"
#include "singleclickholdeventmanager.h"
#include "storehandmask.h"
#include "alttabeventmanager.h"
#include "visionprocessor.h"
//#include "hand.h"
using namespace std;
Point2f sampleMouseGetPos(){
Display *dpy = NULL;
XEvent event;
dpy = XOpenDisplay (NULL);
/* Get the current pointer position */
XQueryPointer (dpy, RootWindow (dpy, 0), &event.xbutton.root,
&event.xbutton.window, &event.xbutton.x_root,
&event.xbutton.y_root, &event.xbutton.x, &event.xbutton.y,
&event.xbutton.state);
//cout<< event.xbutton.x_root<<", "<<event.xbutton.y_root<<endl;
XCloseDisplay (dpy);
return Point2f(event.xbutton.x_root,event.xbutton.y_root );
}
void testVisionProcessor(){
int NManagers=3;
GestureManager ** managers=new GestureManager*[NManagers];
managers[0]=new DoubleSwipeManager;
managers[1]=new SwipeManager;
managers[2]=new TappingManager;
//managers[3]=new MonitorHandsManager;
ScrollUpDownManager *scroll=new ScrollUpDownManager;
SingleClickHoldEventManager *drag=new SingleClickHoldEventManager;
SingleClickHoldEventManager *drag2=new SingleClickHoldEventManager;
StoreHandMask * store=new StoreHandMask;
AltTabEventManager *altTab=new AltTabEventManager;
string folderHand( "defaultOutput" );
store->setFolder(folderHand);
managers[0]->setIOManager( scroll );
managers[1]->setIOManager( drag );
//managers[1]->setIOManager( altTab );
managers[2]->setIOManager( drag2 );
//managers[3]->setIOManager( store );
drag->setButton( 1 );//setting Left button
scroll->initData();
drag->initData();
drag2->initData();
altTab->initData();
VisionProcessor visionProcessor;
//visionProcessor.setVerboseVideo(true);
//visionProcessor.init(1280,1024);
visionProcessor.init();
//getting data ready for creating the background for the inRange
visionProcessor.createMaxDepthWithHistogram();
visionProcessor.getScreenTransformation();
FrameData frameData;
vector<Hand> hands;
frameData.hands=&hands;
VideoWriter outputVideo;
bool verboseVideo;
verboseVideo=true;
if( verboseVideo ){
time_t rawtime;
struct tm * timeinfo;
char buffer [100];
time (&rawtime);
timeinfo = localtime (&rawtime);
strftime (buffer,80,"video_%Y%B%d_%Hh_%Mm_%Ss.avi",timeinfo);
string debugVideoName(buffer);
Size2i kinectRes=visionProcessor.getKinectResolution();
kinectRes.width*=2;
kinectRes.height*=2;
outputVideo.open( debugVideoName,CV_FOURCC('M', 'P', '4', '2') ,30,kinectRes ,true );
}
double acumSec=0;
long nframes=0;
int MaxFrames=1500;
while( true ) {
double duration=0;
hands.clear();
Mat depth;
visionProcessor.processFrame( frameData, duration );
for( int i=0; i<NManagers; i++ ){
managers[i]->updateStatus( frameData );
}
acumSec+=duration;
nframes++;
if( nframes == MaxFrames ){
cout<<"Avg processing frame rate: "<< ((float)MaxFrames)/acumSec<<endl;
nframes=0;
acumSec=0;
}
if( verboseVideo ){
Mat tmp;
Mat depthTmp;
Mat handTmp;
Mat fingersTmp;
Mat tmp2,tmpF;
//frameData.depthMap.convertTo( depthTmp, CV_8UC3);
cvtColor( frameData.depthMap, depthTmp, CV_GRAY2RGB );
cvtColor( frameData.handsMaskRaw, handTmp, CV_GRAY2RGB );
cvtColor( frameData.fingersMaskRaw, fingersTmp, CV_GRAY2RGB );
hconcat( frameData.rgbDebug, depthTmp, tmp );
hconcat( handTmp, fingersTmp, tmp2 );
vconcat( tmp,tmp2,tmpF );
outputVideo << tmpF;
imshow( "contours",tmpF );
}else{
imshow( "contours",frameData.rgbDebug );
}
char key =cvWaitKey(1);
if (key==27/*ESC*/) {
break;
}
}
}
void testTappingAccuracy(){
int screenResolutionW=1024;
int screenResolutionH=768;
int NManagers=1;
GestureManager ** managers=new GestureManager*[NManagers];
managers[0]=new TappingManager;
//managers[1]=new MonitorHandsManager;
//ScrollUpDownManager *scroll=new ScrollUpDownManager;
SingleClickHoldEventManager *drag=new SingleClickHoldEventManager;
//SingleClickHoldEventManager *drag2=new SingleClickHoldEventManager;
StoreHandMask * store=new StoreHandMask;
string folderHand( "output" );
store->setFolder(folderHand);
// managers[0]->setIOManager( scroll );
managers[0]->setIOManager( drag );
//managers[2]->setIOManager( drag2 );
//managers[3]->setIOManager( store );
drag->setButton( 1 );//setting Left button
drag->initData();
VisionProcessor visionProcessor;
visionProcessor.init();
//getting data ready for creating the background for the inRange
visionProcessor.createMaxDepthWithHistogram();
visionProcessor.getScreenTransformation();
FrameData frameData;
ProjectiveMapping kinect2creen=visionProcessor.getKinect2screen();
Mat drawingHand;
vector< Point2f > screenPoints;
int stepW=floor( screenResolutionW/8.0 );
int stepH=floor( (screenResolutionH-50)/6.0 );//substract window bars height
for( int i=stepW; i<(screenResolutionW-stepW); i+=stepW ){
for( int j=stepH; j<(screenResolutionH-50-stepH); j+=stepH ){
screenPoints.push_back( Point2f( i, j ) );
}
}
int attempsPerPoint=150;
vector<Point2f> capturedPoints;
int minDist=50;
namedWindow( "WindowName", CV_WINDOW_AUTOSIZE );
cv::moveWindow("WindowName", 0, 0);
vector<Hand> hands;
frameData.hands=&hands;
for( int i=0; i< screenPoints.size(); i++ ){
Mat testMat=Mat::zeros(screenResolutionH,screenResolutionW-50, CV_8UC3 )*1;
imshow( "WindowName",testMat );
char key =cvWaitKey(250);
//points shifted the window header width and height
circle( testMat, Point(screenPoints.at(i).x+1, screenPoints.at(i).y+50 ), 5, Scalar(0,255,0),2 );
circle( testMat, Point(screenPoints.at(i).x+1, screenPoints.at(i).y+50 ), 10, Scalar(0,255,0),2 );
imshow( "WindowName",testMat );
cout<<"Showing new point"<<endl;
key =cvWaitKey(250);
if (key==27) {
break;
}
Point2f acumMeasure;
acumMeasure.x=0;
acumMeasure.y=0;
int counterMeasured=0;
double duration;
for( int j=0;j<attempsPerPoint;j++ ){
hands.clear();
Mat depth;
//visionProcessor.processFrame( hands, drawingHand,depth );
visionProcessor.processFrame( frameData,duration );
//frameData.hands=&hands;
//frameData.depthMap=depth;
for( int id=0; id<NManagers; id++ ){
managers[id]->updateStatus( frameData );
}
//get mouse position and assign it to acumMeasure
Point2f mousePosition=sampleMouseGetPos();
float dist=norm( mousePosition - screenPoints.at(i) );
if( dist<minDist ){
//cout<<"Match found"<<endl;
acumMeasure.x +=mousePosition.x;
acumMeasure.y +=mousePosition.y;
counterMeasured++;
}
usleep( 10*1000 );
//sleep( 1 );
}
acumMeasure.x/=counterMeasured;
acumMeasure.y/=counterMeasured;
capturedPoints.push_back( acumMeasure );
key =cvWaitKey(15);
if (key==27) {
break;
}
}
cout<<"Screen points"<<endl;
cout<<screenPoints<<endl;
cout<<"Observed points"<<endl;
cout<<capturedPoints<<endl;
}
int main()
{
testVisionProcessor();
//testTappingAccuracy();
return 0;
}