More work on obtaining Kinect data.

This commit is contained in:
Andrzej Kapolka 2013-06-26 12:19:10 -07:00
parent 3d214c2655
commit 5e989b6ee5
2 changed files with 21 additions and 2 deletions

View file

@ -252,21 +252,38 @@ void FrameGrabber::grabFrame() {
Q_ARG(cv::Mat, frame), Q_ARG(cv::RotatedRect, faceRect));
}
const char* FREENECT_LOG_LEVEL_NAMES[] = { "fatal", "error", "warning", "notice", "info", "debug", "spew", "flood" };
static void logCallback(freenect_context* freenectDevice, freenect_loglevel level, const char *msg) {
printLog("Freenect %s: %s\n", FREENECT_LOG_LEVEL_NAMES[level], msg);
}
static void depthCallback(freenect_device* freenectDevice, void* depth, uint32_t timestamp) {
qDebug() << "Got depth " << depth << timestamp;
}
static void videoCallback(freenect_device* freenectDevice, void* video, uint32_t timestamp) {
qDebug() << "Got video " << video << timestamp;
}
bool FrameGrabber::init() {
// first try for a Kinect
if (freenect_init(&_freenectContext, 0) >= 0) {
freenect_set_log_level(_freenectContext, FREENECT_LOG_DEBUG);
freenect_set_log_callback(_freenectContext, logCallback);
freenect_select_subdevices(_freenectContext, FREENECT_DEVICE_CAMERA);
if (freenect_num_devices(_freenectContext) > 0) {
if (freenect_open_device(_freenectContext, &_freenectDevice, 0) >= 0) {
freenect_set_depth_callback(_freenectDevice, depthCallback);
freenect_set_video_callback(_freenectDevice, videoCallback);
freenect_set_video_callback(_freenectDevice, videoCallback);
_freenectVideoMode = freenect_find_video_mode(FREENECT_RESOLUTION_MEDIUM, FREENECT_VIDEO_RGB);
freenect_set_video_mode(_freenectDevice, _freenectVideoMode);
_freenectDepthMode = freenect_find_depth_mode(FREENECT_RESOLUTION_MEDIUM, FREENECT_DEPTH_11BIT);
freenect_set_depth_mode(_freenectDevice, _freenectDepthMode);
freenect_start_depth(_freenectDevice);
freenect_start_video(_freenectDevice);
freenect_start_video(_freenectDevice);
return true;
}
}

View file

@ -97,6 +97,8 @@ private:
freenect_context* _freenectContext;
freenect_device* _freenectDevice;
freenect_frame_mode _freenectVideoMode;
freenect_frame_mode _freenectDepthMode;
};
Q_DECLARE_METATYPE(cv::Mat)