48 if (freenect_process_events(
m_ctx) < 0)
50 throw std::runtime_error(
"Cannot process freenect events");
97 if (freenect_init(&
m_ctx, NULL) < 0)
99 emit
message(
"freenect_init() failed");
107 freenect_set_log_level(
m_ctx, FREENECT_LOG_DEBUG);
110 int nr_devices = freenect_num_devices (
m_ctx);
112 emit
message(QString(
"%1 Kinects found.").arg(nr_devices));
127 emit
message(
"ERROR opening Kinect device.");
136 for (
int i=0; i<2048; ++i)
139 v = std::pow(v, 3)* 6;
150 freenect_set_video_format(
m_dev, FREENECT_VIDEO_RGB);
151 freenect_set_depth_format(
m_dev, FREENECT_DEPTH_11BIT);
176 freenect_stop_depth(
m_dev);
177 freenect_stop_video(
m_dev);
179 freenect_close_device(
m_dev);
180 freenect_shutdown(
m_ctx);
187 freenect_set_led(
m_dev,LED_OFF);
193 freenect_set_led(
m_dev,LED_RED);
199 freenect_set_led(
m_dev,LED_GREEN);
205 freenect_set_led(
m_dev,LED_YELLOW);
211 freenect_set_led(
m_dev,LED_BLINK_RED_YELLOW);
217 freenect_set_led(
m_dev,LED_BLINK_GREEN);
223 freenect_set_led(
m_dev,LED_BLINK_RED_YELLOW);
229 freenect_video_format vm=FREENECT_VIDEO_RGB;
233 case 0 : { vm=FREENECT_VIDEO_RGB;
break;}
234 case 1 : { vm=FREENECT_VIDEO_YUV_RGB;
break;}
235 case 2 : { vm=FREENECT_VIDEO_IR_8BIT;
break;}
247 emit
message(
"Kinect: index out of bounds for video mode");
248 vm = FREENECT_VIDEO_RGB;
254 freenect_stop_video(
m_dev);
255 freenect_set_video_format(
m_dev, vm);
256 freenect_start_video(
m_dev);
262 freenect_set_tilt_degs(
m_dev,0);
278 freenect_set_tilt_degs(
m_dev,_angle);
286 QMutexLocker locker( &
m_mutex );
306 QMutexLocker locker( &
m_mutex );
325 QMutexLocker locker( &
m_mutex );
344 QMutexLocker locker( &
m_mutex );
364 QMutexLocker locker( &
m_mutex );
367 uint16_t* depth =
static_cast<uint16_t*
>(_depth);
370 for (
unsigned int i = 0; i < FREENECT_FRAME_PIX; ++i)
381 int lb = pval & 0xff;
428 Q_UNUSED(_timestamp);
435 QMutexLocker locker( &
m_mutex );
437 uint8_t* rgb =
static_cast<uint8_t*
>(_video);
438 std::copy(rgb, rgb+FREENECT_VIDEO_RGB_SIZE,
m_bufferVideo.begin());
441 Q_UNUSED(_timestamp);
447 if(freenect_start_video(
m_dev) < 0)
449 throw std::runtime_error(
"Cannot start RGB callback");
456 if(freenect_stop_video(
m_dev) < 0)
458 throw std::runtime_error(
"Cannot stop RGB callback");
465 if(freenect_start_depth(
m_dev) < 0)
467 throw std::runtime_error(
"Cannot start depth callback");
474 if(freenect_stop_depth(
m_dev) < 0)
476 throw std::runtime_error(
"Cannot stop depth callback");