-
Notifications
You must be signed in to change notification settings - Fork 3
/
goop.c
608 lines (522 loc) · 17.4 KB
/
goop.c
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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
/*
* This file is part of the OpenKinect Project. http://www.openkinect.org
*
* Copyright (c) 2010 individual OpenKinect contributors. See the CONTRIB file
* for details.
*
* This code is licensed to you under the terms of the Apache License, version
* 2.0, or, at your option, the terms of the GNU General Public License,
* version 2.0. See the APACHE20 and GPL2 files for the text of the licenses,
* or the following URLs:
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.gnu.org/licenses/gpl-2.0.txt
*
* If you redistribute this file in source form, modified or unmodified, you
* may:
* 1) Leave this header intact and distribute it under the same terms,
* accompanying it with the APACHE20 and GPL20 files, or
* 2) Delete the Apache 2.0 clause and accompany it with the GPL2 file, or
* 3) Delete the GPL v2 clause and accompany it with the APACHE20 file
* In all cases you must keep the copyright notice intact and include a copy
* of the CONTRIB file.
*
* Binary distributions must follow the binary distribution requirements of
* either License.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "libfreenect.h"
#include "old.h"
#include <pthread.h>
#if defined(__APPLE__)
#include <GLUT/glut.h>
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#else
#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>
#endif
#include <math.h>
pthread_t freenect_thread;
volatile int die = 0;
int g_argc;
char **g_argv;
int window;
pthread_mutex_t gl_backbuf_mutex = PTHREAD_MUTEX_INITIALIZER;
// back: owned by libfreenect (implicit for depth)
// mid: owned by callbacks, "latest frame ready"
// front: owned by GL, "currently being drawn"
uint8_t *depth_mid, *depth_front, *color_diff_depth_map;
uint8_t *rgb_back, *rgb_mid, *rgb_front;
GLuint gl_depth_tex;
GLuint gl_rgb_tex;
freenect_context *f_ctx;
freenect_device *f_dev;
int freenect_angle = 0;
int freenect_led;
freenect_video_format requested_format = FREENECT_VIDEO_RGB;
freenect_video_format current_format = FREENECT_VIDEO_RGB;
pthread_cond_t gl_frame_cond = PTHREAD_COND_INITIALIZER;
int got_rgb = 0;
int got_depth = 0;
int * depth_map;/*[ FREENECT_FRAME_PIX ]; */
int * old_depth_map;/*[ FREENECT_FRAME_PIX ];*/
int * diff_depth_map;/*[ FREENECT_FRAME_PIX ];*/
int * tmp_diff_depth_map;/*[ FREENECT_FRAME_PIX ];*/
int depth_frame = 0;
#define SHADOW 2047
#define WIDTH 640
#define HEIGHT 480
void clearBorders( int * map ) {
for (int y = 0 ; y < HEIGHT; y++) {
map[WIDTH * y + 0] = 0;
map[WIDTH * y + WIDTH - 1] = 0;
}
for (int x = 0 ; x < WIDTH; x++) {
map[x] = 0;
map[FREENECT_FRAME_PIX - WIDTH + x] = 0;
}
}
void despeckleInPlace( int * map ) {
clearBorders( tmp_diff_depth_map );
for (int y = 1 ; y < HEIGHT-1; y++) {
for (int x = 1 ; x < WIDTH-1; x++) {
int cnt = (map[WIDTH*(y+1) + x] > 0)
+ (map[WIDTH*(y-1) + x] > 0)
+ (map[WIDTH*(y) + x + 1] > 0)
+ (map[WIDTH*(y) + x - 1] > 0);
tmp_diff_depth_map[ WIDTH * y + x ] = (cnt > 2)?map[ WIDTH * y + x]:0;
}
}
memcpy( map, tmp_diff_depth_map, sizeof(int) * FREENECT_FRAME_PIX );
}
void smoothInPlace( int * map ) {
clearBorders( map );
for (int y = 1 ; y < HEIGHT-1; y++) {
for (int x = 1 ; x < WIDTH-1; x++) {
int V = WIDTH * y + x;
int cnt = map[V - WIDTH - 1] + map[V - WIDTH] + map[V - WIDTH + 1] +
map[V] + map[V] + map[V + 1] +
map[V + WIDTH - 1] + map[V + WIDTH] + map[V + WIDTH + 1];
tmp_diff_depth_map[ V ] = cnt / 9;
}
}
memcpy( map, tmp_diff_depth_map, sizeof(int) * FREENECT_FRAME_PIX );
}
void calcStats( int * map, double * avg, int * sum ) {
int summation = 0;
for(int i = 0 ; i < FREENECT_FRAME_PIX; i++) {
summation += map[ i ];
}
*avg = (double)summation / (double)FREENECT_FRAME_PIX;
*sum = summation;
}
void calcStatsForRegion( int * map, double * avg, int * sum, int startx, int starty, int width, int height ) {
int summation = 0;
for(int y = 0; y < height; y++) {
for(int x = 0; x < width; x++) {
summation += map[ WIDTH * (starty+y) + (startx+x) ];
}
}
*avg = (double)summation / (double)(width * height);
*sum = summation;
}
void DrawGLScene()
{
pthread_mutex_lock(&gl_backbuf_mutex);
// When using YUV_RGB mode, RGB frames only arrive at 15Hz, so we shouldn't force them to draw in lock-step.
// However, this is CPU/GPU intensive when we are receiving frames in lockstep.
if (current_format == FREENECT_VIDEO_YUV_RGB) {
while (!got_depth && !got_rgb) {
pthread_cond_wait(&gl_frame_cond, &gl_backbuf_mutex);
}
} else {
while ((!got_depth || !got_rgb) && requested_format != current_format) {
pthread_cond_wait(&gl_frame_cond, &gl_backbuf_mutex);
}
}
if (requested_format != current_format) {
pthread_mutex_unlock(&gl_backbuf_mutex);
return;
}
uint8_t *tmp;
if (got_depth) {
int i = 0;
int j = 0;
int jmin = 0;
int mprn = 200;
int d = 0;
int dv = 0;
tmp = depth_front;
depth_front = depth_mid;
depth_mid = tmp;
got_depth = 0;
jmin = depth_map[ 0 ];
int dmax = 0;
for ( i = 1 ; i < FREENECT_FRAME_PIX ; i++ ) {
if (depth_map[ i ] == SHADOW) {
//diff_depth_map[ i ] = 0;
//diff_depth_map[ i ] *= 9;
//diff_depth_map[ i ] /= 10;
} else if (old_depth_map[ i ] == SHADOW) {
//diff_depth_map[ i ] = 0;
//diff_depth_map[ i ] *= 9;
//diff_depth_map[ i ] /= 10;
} else {
d = abs(depth_map[ i ] - old_depth_map[ i ]);
if (d > 1) {
diff_depth_map[ i ] += 1;// (10*diff_depth_map[i] + 9*(d > 1 && d < 30)?d:0)/8;
//diff_depth_map[ i ] += d;
}
//diff_depth_map[ i ] = (6*diff_depth_map[i] + 4*(d > 1 && d < 30)?d:0)/10;
//diff_depth_map[ i ] += (d > 1 && d < 30)?d:0;//(d > 0)?d:0;
}
/* if (depth_frame != 0 && diff_depth_map[ i ] != SHADOW && diff_depth_map[ i ] != 0) {
fprintf( stdout, "diff: %d %d %d %d %d\n", depth_frame, i, diff_depth_map[i], depth_map[i], old_depth_map[i] );
} */
dv = 0;
if (depth_map[ i ] != SHADOW) {
old_depth_map[ i ] = depth_map[ i ];
//dv = 255*abs(diff_depth_map[i])/255;
dv = diff_depth_map[i];
if (dv > dmax) {
dmax = dv;
}
} else {
dv = 0;
}
}
// smooth depth_map
//despeckleInPlace( diff_depth_map );
smoothInPlace( diff_depth_map );
for (i = 0; i < FREENECT_FRAME_PIX; i++) {
dv = diff_depth_map[i];//255*diff_depth_map[i]/30;
color_diff_depth_map[ 3 * i ] = 255*dv/(1+dmax);//255-(dv & 0xFF);// + rgb_front[3*i]>>2;
color_diff_depth_map[ 3 * i + 1] = rgb_front[3*i+1];
color_diff_depth_map[ 3 * i + 2] = rgb_front[3*i+1];rgb_front[3*i+2];
}
//if (depth_frame % 2==0) {
// for (i = 0; i < FREENECT_FRAME_PIX; i++)
// diff_depth_map[i] >>= 1;//255*diff_depth_map[i]/30;
//}
int sum,sumleft,sumright,sumcenter;
double avg,avgleft,avgright,avgcenter;
calcStats( diff_depth_map, &avg, &sum);
calcStatsForRegion( diff_depth_map, &avgcenter, &sumcenter, WIDTH/4, HEIGHT/4, WIDTH/2, HEIGHT/2);
calcStatsForRegion( diff_depth_map, &avgleft, &sumleft, 0, 0, WIDTH/3, HEIGHT);
calcStatsForRegion( diff_depth_map, &avgright, &sumright, 2*WIDTH/3, 0, WIDTH/3, HEIGHT);
fprintf(stderr, "i1 0 0 %d %f %d %f %d %f %d %f\n", sum, avg, sumcenter, avgcenter, sumleft, avgleft, sumright, avgright);
fprintf(stdout, "i1 0 0 %d %f %d %f %d %f %d %f\n", sum, avg, sumcenter, avgcenter, sumleft, avgleft, sumright, avgright);
depth_frame++;
fflush( stdout );
}
if (got_rgb) {
tmp = rgb_front;
rgb_front = rgb_mid;
rgb_mid = tmp;
got_rgb = 0;
}
pthread_mutex_unlock(&gl_backbuf_mutex);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, gl_depth_tex);
/* glTexImage2D(GL_TEXTURE_2D, 0, 3, 640, 480, 0, GL_RGB, GL_UNSIGNED_BYTE, depth_front); */
glTexImage2D(GL_TEXTURE_2D, 0, 3, 640, 480, 0, GL_RGB, GL_UNSIGNED_BYTE, color_diff_depth_map );
glBegin(GL_TRIANGLE_FAN);
glColor4f(255.0f, 255.0f, 255.0f, 255.0f);
glTexCoord2f(0, 0); glVertex3f(0,0,0);
glTexCoord2f(1, 0); glVertex3f(640,0,0);
glTexCoord2f(1, 1); glVertex3f(640,480,0);
glTexCoord2f(0, 1); glVertex3f(0,480,0);
glEnd();
// glBindTexture(GL_TEXTURE_2D, gl_rgb_tex);
// if (current_format == FREENECT_VIDEO_RGB || current_format == FREENECT_VIDEO_YUV_RGB)
// glTexImage2D(GL_TEXTURE_2D, 0, 3, 640, 480, 0, GL_RGB, GL_UNSIGNED_BYTE, rgb_front);
// else
// glTexImage2D(GL_TEXTURE_2D, 0, 1, 640, 480, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, rgb_front+640*4);
//
// glBegin(GL_TRIANGLE_FAN);
// glColor4f(255.0f, 255.0f, 255.0f, 255.0f);
// glTexCoord2f(0, 0); glVertex3f(640,0,0);
// glTexCoord2f(1, 0); glVertex3f(1280,0,0);
// glTexCoord2f(1, 1); glVertex3f(1280,480,0);
// glTexCoord2f(0, 1); glVertex3f(640,480,0);
// glEnd();
glutSwapBuffers();
}
void keyPressed(unsigned char key, int x, int y)
{
if (key == 27) {
die = 1;
pthread_join(freenect_thread, NULL);
glutDestroyWindow(window);
free(color_diff_depth_map);
free(depth_map);
free(old_depth_map);
free(diff_depth_map);
free(depth_mid);
free(depth_front);
free(rgb_back);
free(rgb_mid);
free(rgb_front);
pthread_exit(NULL);
}
if (key == 'w') {
freenect_angle++;
if (freenect_angle > 30) {
freenect_angle = 30;
}
}
if (key == 's') {
freenect_angle = 0;
}
if (key == 'f') {
if (requested_format == FREENECT_VIDEO_IR_8BIT)
requested_format = FREENECT_VIDEO_RGB;
else if (requested_format == FREENECT_VIDEO_RGB)
requested_format = FREENECT_VIDEO_YUV_RGB;
else
requested_format = FREENECT_VIDEO_IR_8BIT;
}
if (key == 'x') {
freenect_angle--;
if (freenect_angle < -30) {
freenect_angle = -30;
}
}
if (key == '1') {
freenect_set_led(f_dev,LED_GREEN);
}
if (key == '2') {
freenect_set_led(f_dev,LED_RED);
}
if (key == '3') {
freenect_set_led(f_dev,LED_YELLOW);
}
if (key == '4') {
freenect_set_led(f_dev,LED_BLINK_GREEN);
}
if (key == '5') {
// 5 is the same as 4
freenect_set_led(f_dev,LED_BLINK_GREEN);
}
if (key == '6') {
freenect_set_led(f_dev,LED_BLINK_RED_YELLOW);
}
if (key == '0') {
freenect_set_led(f_dev,LED_OFF);
}
freenect_set_tilt_degs(f_dev,freenect_angle);
}
void ReSizeGLScene(int Width, int Height)
{
glViewport(0,0,Width,Height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//glOrtho (0, 1280, 480, 0, -1.0f, 1.0f);
glOrtho (0, 640, 480, 0, -1.0f, 1.0f);
glMatrixMode(GL_MODELVIEW);
}
void InitGL(int Width, int Height)
{
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0);
glDepthFunc(GL_LESS);
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glShadeModel(GL_SMOOTH);
glGenTextures(1, &gl_depth_tex);
glBindTexture(GL_TEXTURE_2D, gl_depth_tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glGenTextures(1, &gl_rgb_tex);
glBindTexture(GL_TEXTURE_2D, gl_rgb_tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
ReSizeGLScene(Width, Height);
}
void *gl_threadfunc(void *arg)
{
fprintf(stderr,"GL thread\n");
glutInit(&g_argc, g_argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH);
//glutInitWindowSize(1280, 480);
glutInitWindowSize(640, 480);
glutInitWindowPosition(0, 0);
window = glutCreateWindow("LibFreenect");
glutDisplayFunc(&DrawGLScene);
glutIdleFunc(&DrawGLScene);
glutReshapeFunc(&ReSizeGLScene);
glutKeyboardFunc(&keyPressed);
//InitGL(1280, 480);
InitGL(640, 480);
glutMainLoop();
return NULL;
}
uint16_t t_gamma[2048];
void depth_cb(freenect_device *dev, void *v_depth, uint32_t timestamp)
{
int i;
uint16_t *depth = (uint16_t*)v_depth;
pthread_mutex_lock(&gl_backbuf_mutex);
for (i=0; i<FREENECT_FRAME_PIX; i++) {
int pval = t_gamma[depth[i]];
depth_map[ i ] = depth[ i ] ; /* pval; */
int lb = pval & 0xff;
switch (pval>>8) {
case 0:
depth_mid[3*i+0] = 255;
depth_mid[3*i+1] = 255-lb;
depth_mid[3*i+2] = 255-lb;
break;
case 1:
depth_mid[3*i+0] = 255;
depth_mid[3*i+1] = lb;
depth_mid[3*i+2] = 0;
break;
case 2:
depth_mid[3*i+0] = 255-lb;
depth_mid[3*i+1] = 255;
depth_mid[3*i+2] = 0;
break;
case 3:
depth_mid[3*i+0] = 0;
depth_mid[3*i+1] = 255;
depth_mid[3*i+2] = lb;
break;
case 4:
depth_mid[3*i+0] = 0;
depth_mid[3*i+1] = 255-lb;
depth_mid[3*i+2] = 255;
break;
case 5:
depth_mid[3*i+0] = 0;
depth_mid[3*i+1] = 0;
depth_mid[3*i+2] = 255-lb;
break;
default:
depth_mid[3*i+0] = 0;
depth_mid[3*i+1] = 0;
depth_mid[3*i+2] = 0;
break;
}
}
got_depth++;
pthread_cond_signal(&gl_frame_cond);
pthread_mutex_unlock(&gl_backbuf_mutex);
}
void rgb_cb(freenect_device *dev, void *rgb, uint32_t timestamp)
{
pthread_mutex_lock(&gl_backbuf_mutex);
// swap buffers
assert (rgb_back == rgb);
rgb_back = rgb_mid;
freenect_set_video_buffer(dev, rgb_back);
rgb_mid = (uint8_t*)rgb;
got_rgb++;
pthread_cond_signal(&gl_frame_cond);
pthread_mutex_unlock(&gl_backbuf_mutex);
}
void *freenect_threadfunc(void *arg)
{
int accelCount = 0;
freenect_set_tilt_degs(f_dev,freenect_angle);
freenect_set_led(f_dev,LED_RED);
freenect_set_depth_callback(f_dev, depth_cb);
freenect_set_video_callback(f_dev, rgb_cb);
//freenect_set_video_format(f_dev, current_format);
//freenect_set_depth_format(f_dev, FREENECT_DEPTH_11BIT);
//freenect_set_video_format(f_dev, current_format);
//reenect_set_depth_format(f_dev, FREENECT_DEPTH_11BIT);
freenect_set_video_mode(f_dev, freenect_find_video_mode(FREENECT_RESOLUTION_MEDIUM, current_format));
freenect_set_depth_mode(f_dev, freenect_find_depth_mode(FREENECT_RESOLUTION_MEDIUM, FREENECT_DEPTH_11BIT));
freenect_set_video_buffer(f_dev, rgb_back);
freenect_start_depth(f_dev);
freenect_start_video(f_dev);
fprintf(stderr,"'w'-tilt up, 's'-level, 'x'-tilt down, '0'-'6'-select LED mode, 'f'-video format\n");
while (!die && freenect_process_events(f_ctx) >= 0) {
//Throttle the text output
if (accelCount++ >= 2000)
{
accelCount = 0;
freenect_raw_tilt_state* state;
freenect_update_tilt_state(f_dev);
state = freenect_get_tilt_state(f_dev);
double dx,dy,dz;
freenect_get_mks_accel(state, &dx, &dy, &dz);
fprintf(stderr,"\r raw acceleration: %4d %4d %4d mks acceleration: %4f %4f %4f", state->accelerometer_x, state->accelerometer_y, state->accelerometer_z, dx, dy, dz);
fflush(stdout);
}
if (requested_format != current_format) {
freenect_stop_video(f_dev);
//freenect_set_video_format(f_dev, requested_format);
freenect_set_video_mode(f_dev, freenect_find_video_mode(FREENECT_RESOLUTION_MEDIUM, requested_format));
freenect_start_video(f_dev);
current_format = requested_format;
}
}
printf("\nshutting down streams...\n");
freenect_stop_depth(f_dev);
freenect_stop_video(f_dev);
freenect_close_device(f_dev);
freenect_shutdown(f_ctx);
printf("-- done!\n");
return NULL;
}
int main(int argc, char **argv)
{
int res;
int pixels = 640*480;
depth_mid = (uint8_t*)malloc(640*480*3);
color_diff_depth_map = (uint8_t*)malloc(640*480*3);
depth_map = (int *) malloc(sizeof(int)*pixels);
memset(depth_map, 0, sizeof(int)*pixels);
old_depth_map = (int *) malloc(sizeof(int)*pixels);
memset(old_depth_map, 0, sizeof(int)*pixels);
diff_depth_map = (int *) malloc(sizeof(int)*pixels);
memset(diff_depth_map, 0, sizeof(int)*pixels);
tmp_diff_depth_map = (int *) malloc(sizeof(int)*pixels);
memset(tmp_diff_depth_map, 0, sizeof(int)*pixels);
depth_front = (uint8_t*)malloc(640*480*3);
rgb_back = (uint8_t*)malloc(640*480*3);
rgb_mid = (uint8_t*)malloc(640*480*3);
rgb_front = (uint8_t*)malloc(640*480*3);
//printf("Kinect camera test\n");
int i;
for (i=0; i<2048; i++) {
float v = i/2048.0;
v = powf(v, 3)* 6;
t_gamma[i] = v*6*256;
}
g_argc = argc;
g_argv = argv;
if (freenect_init(&f_ctx, NULL) < 0) {
printf("freenect_init() failed\n");
return 1;
}
freenect_set_log_level(f_ctx, FREENECT_LOG_DEBUG);
int nr_devices = freenect_num_devices (f_ctx);
fprintf (stderr,"Number of devices found: %d\n", nr_devices);
int user_device_number = 0;
if (argc > 1)
user_device_number = atoi(argv[1]);
if (nr_devices < 1)
return 1;
if (freenect_open_device(f_ctx, &f_dev, user_device_number) < 0) {
printf("Could not open device\n");
return 1;
}
res = pthread_create(&freenect_thread, NULL, freenect_threadfunc, NULL);
if (res) {
printf("pthread_create failed\n");
return 1;
}
// OS X requires GLUT to run on the main thread
gl_threadfunc(NULL);
return 0;
}