direcs  2012-09-30
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
QKinect Class Reference

this class wraps the libfreenect library as a QObject this allows us to use singals and slots to communicate with the class from other Qt GUI elements. This class uses the Singleton pattern so must be accessed via the instance method More...

#include <QKinect.h>

Collaboration diagram for QKinect:

List of all members.

Public Slots

freenect_context * getContext ()
 return a pointer to the active device context
bool getDepth (std::vector< uint8_t > &o_buffer)
 getDepth buffer and convert it to an RGB colour representation this code is based on the sample implementation glview.c / cppview.cpp
bool getDepth16Bit (std::vector< uint16_t > &o_buffer)
 getDepth buffer as the raw 16 Bit values this is useful for generating point cloud renders as we have the full depth range
bool getDepthRaw (std::vector< uint8_t > &o_buffer)
 getDepth buffer as the raw values converted to uint8_t not sure if this will be much use but have used it in some tracking examples
bool getRGB (std::vector< uint8_t > &o_buffer)
 get the RGB buffer
void resetAngle ()
 reset the tilt angle
void setAngle (double _angle)
 slot to change the angle of the Kinect
void setGreenLed ()
 slot to enable the green LED
void setGreenLedFlash ()
 slot to flash the green led
void setLedOff ()
 slot to turn off the led
void setRedLed ()
 slot to enable the red LED
void setRedLedFlash ()
 slot to flash the red led
void setVideoMode (int _mode)
 slot to set the video mode
void setYellowLed ()
 slot to enable the yellow LED
void setYellowLedFlash ()
 slot to flash the yellow led
void startDepth ()
 start the Depth buffer grabbing subsystem
void startVideo ()
 start the Video buffer grabbing subsystem
void stopDepth ()
 stop the Depth buffer grabbing subsystem
void stopVideo ()
 stop the Depth buffer grabbing subsystem
void toggleDepthState (bool _mode)
 convenience method to toggle the depth mode with a bool to indicate mode, useful for connecting to buttons
void toggleVideoState (bool _mode)
 convenience method to toggle the video mode with a bool to indicate mode, useful for connecting to buttons

Signals

void message (QString text)

Public Member Functions

void setUserDeviceNumber (int _m)
 we can set the user device number here by default it will be 1
void shutDownKinect ()
 method to shutdown our device and close

Static Public Member Functions

static QKinectinstance ()
 get the instance of the QKinect object this will call the init method of the class if the instance doesn't exist. This is because this class will construct some threads so we need to create an instance first then pass that to the other classes in the thread

Public Attributes

bool kinectDetected
 true if camera detected

Private Member Functions

void depthFunc (freenect_device *_dev, void *o_depth, uint32_t _timestamp)
 function for depth callback this hooks into the libfreenect callback system
void grabDepth (void *_depth, uint32_t timestamp)
 method to grab the depth passed to the depthCallback function as we are hooking into a C lib we need to do it this way as the callback functions must be static (see below)
void grabVideo (void *_video, uint32_t timestamp)
 method to grab the Video passed to the depthCallback function as we are hooking into a C lib we need to do it this way as the callback functions must be static (see below)
void init ()
 private copy ctor as we are a singleton class
 QKinect ()
 private ctor as we are a singleton class
void rgbFunc (freenect_device *_dev, void *o_rgb, uint32_t _timestamp)
 function for Video callback this hooks into the libfreenect callback system
 ~QKinect ()
 private dtor as we are a singleton class

Static Private Member Functions

static void depthCallback (freenect_device *_dev, void *_depth, uint32_t _timestamp=0)
 this hooks into the feenet callback system an is the main way of getting the data from the kinect this is not called directly
static void videoCallback (freenect_device *_dev, void *_video, uint32_t _timestamp=0)
 this hooks into the feenet callback system an is the main way of getting the data from the kinect this is not called directly

Private Attributes

std::vector< uint8_t > m_bufferDepth
 our depth buffer for the current depth frames will be filled from the depth callback, this data is converted into an RGB representation with Red being closest and blue far away, this is done via a gamma table and converting the depth from 16 bit to 8 bit RGB useful for OpenCV like motion tracking
std::vector< uint8_t > m_bufferDepthRaw
 our depth buffer for the current depth frames will be filled from the depth callback this is the unaltered data converted to 8 bit not really useful so may get rid of at a later date just legacy from testing the other examples
std::vector< uint16_t > m_bufferDepthRaw16
 the 16Bit raw depth values, this is good for voxel rendering of the data
std::vector< uint8_t > m_bufferVideo
 our video buffer for the current rgb video frames will be filled from the rgb callback
freenect_context * m_ctx
 the contex for the device
freenect_device * m_dev
 our device pointer
bool m_deviceActive
 flag to indicate if the device is active
std::vector< uint16_t > m_gamma
 our gamma table this is filled in the ctor and used in the depth callbacks, this is taken from the sample code glview.c cppview.cpp
QMutex m_mutex
 our mutex used for the threaded processes, for ease we use a QMutexLocker to automagically control our mutex state
bool m_newDepthFrame
 flag to indicate if there is a new depth frame
bool m_newRgbFrame
 flag to indicate if there is a new rgb frame
QKinectProcessEventsm_process
 pointer to our thread process used to process the events
bool m_stopDevice
 flag to indicate if we need to stop the device
int m_userDeviceNumber
 user device number

Static Private Attributes

static QKinects_instance = 0
 our instance of the Kinect device

Detailed Description

this class wraps the libfreenect library as a QObject this allows us to use singals and slots to communicate with the class from other Qt GUI elements. This class uses the Singleton pattern so must be accessed via the instance method

@author Jonathan Macey
Version:
1.0
Date:
20/12/10 Inital commit

Definition at line 105 of file QKinect.h.


Constructor & Destructor Documentation

QKinect::QKinect ( )
private

private ctor as we are a singleton class

Definition at line 84 of file QKinect.cpp.

Here is the caller graph for this function:

QKinect::~QKinect ( )
private

private dtor as we are a singleton class

Definition at line 56 of file QKinect.cpp.


Member Function Documentation

static void QKinect::depthCallback ( freenect_device *  _dev,
void *  _depth,
uint32_t  _timestamp = 0 
)
inlinestaticprivate

this hooks into the feenet callback system an is the main way of getting the data from the kinect this is not called directly

Parameters:
[in]_devthis is not used as we use the class m_dev
[out]_videothe depth data
[in]_timestampthe timestamp of the operation (not used)

get an instance of our device

then call the grab method to fill the depth buffer and return it

Definition at line 416 of file QKinect.h.

Here is the call graph for this function:

Here is the caller graph for this function:

void QKinect::depthFunc ( freenect_device *  _dev,
void *  o_depth,
uint32_t  _timestamp 
)
private

function for depth callback this hooks into the libfreenect callback system

Parameters:
[in]_devthe device we are querying
[out]theactual depth data returned from the device
_timestampthe time stamp for the grab (not used at present)
freenect_context* QKinect::getContext ( )
inlineslot

return a pointer to the active device context

Returns:
the current active contects

Definition at line 255 of file QKinect.h.

bool QKinect::getDepth ( std::vector< uint8_t > &  o_buffer)
slot

getDepth buffer and convert it to an RGB colour representation this code is based on the sample implementation glview.c / cppview.cpp

Parameters:
[out]o_bufferthe buffer to fill

Definition at line 303 of file QKinect.cpp.

Here is the caller graph for this function:

bool QKinect::getDepth16Bit ( std::vector< uint16_t > &  o_buffer)
slot

getDepth buffer as the raw 16 Bit values this is useful for generating point cloud renders as we have the full depth range

Parameters:
[out]o_bufferthe buffer to fill

fill the 16 Bit data value first lock mutex

Definition at line 322 of file QKinect.cpp.

bool QKinect::getDepthRaw ( std::vector< uint8_t > &  o_buffer)
slot

getDepth buffer as the raw values converted to uint8_t not sure if this will be much use but have used it in some tracking examples

Parameters:
[out]o_bufferthe buffer to fill

Definition at line 341 of file QKinect.cpp.

bool QKinect::getRGB ( std::vector< uint8_t > &  o_buffer)
slot

get the RGB buffer

Parameters:
[out]o_bufferthe rgb values

this grabs the rgb data we first need to lock our mutex this will be unlocked on destruction of the locker

Definition at line 282 of file QKinect.cpp.

Here is the caller graph for this function:

void QKinect::grabDepth ( void *  _depth,
uint32_t  timestamp 
)
private

method to grab the depth passed to the depthCallback function as we are hooking into a C lib we need to do it this way as the callback functions must be static (see below)

Parameters:
[out]_depththe depth data
[in]_timestampthe timestamp of the operation (not used)

lock our mutex

Definition at line 359 of file QKinect.cpp.

Here is the caller graph for this function:

void QKinect::grabVideo ( void *  _video,
uint32_t  timestamp 
)
private

method to grab the Video passed to the depthCallback function as we are hooking into a C lib we need to do it this way as the callback functions must be static (see below)

Parameters:
[out]_videothe depth data
[in]_timestampthe timestamp of the operation (not used)

Definition at line 432 of file QKinect.cpp.

Here is the caller graph for this function:

void QKinect::init ( )
private

private copy ctor as we are a singleton class

private init method, this makes the instance method thread safe as all the initialisations will be done here

Returns:
EXIT_SUCCESS on success, EXIT_FAILURE om error

set loggin level make this programmable at some stage

see how many devices we have

now allocate the buffers so we can fill them

open the device at present hard coded to device 0 as I only have 1 kinect

Todo:
make this support multiple devices at some stage

build the gamma table used for the depth to rgb conversion taken from the demo programs

init our flags

Todo:
make this more flexible at some stage

hook in the callbacks

Definition at line 94 of file QKinect.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

QKinect * QKinect::instance ( )
static

get the instance of the QKinect object this will call the init method of the class if the instance doesn't exist. This is because this class will construct some threads so we need to create an instance first then pass that to the other classes in the thread

Returns:
an instance of the QKinect object
Note:
this could be made nicer to make it fully thread safe

Definition at line 66 of file QKinect.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void QKinect::message ( QString  text)
signal

Emits a info or error message to a slot. This slot can be used to display a text on a splash screen, log file, to print it to a console...

Here is the caller graph for this function:

void QKinect::resetAngle ( )
slot

reset the tilt angle

Definition at line 260 of file QKinect.cpp.

void QKinect::rgbFunc ( freenect_device *  _dev,
void *  o_rgb,
uint32_t  _timestamp 
)
private

function for Video callback this hooks into the libfreenect callback system

Parameters:
[in]_devthe device we are querying
[out]o_rgbthe actual video data returned from the device
_timestampthe time stamp for the grab (not used at present)
void QKinect::setAngle ( double  _angle)
slot

slot to change the angle of the Kinect

Parameters:
[in]_anglethe angle to set will be constrained to -/+ 30.0

Definition at line 266 of file QKinect.cpp.

void QKinect::setGreenLed ( )
slot

slot to enable the green LED

Definition at line 197 of file QKinect.cpp.

Here is the caller graph for this function:

void QKinect::setGreenLedFlash ( )
slot

slot to flash the green led

Definition at line 215 of file QKinect.cpp.

void QKinect::setLedOff ( )
slot

slot to turn off the led

Definition at line 185 of file QKinect.cpp.

void QKinect::setRedLed ( )
slot

slot to enable the red LED

Definition at line 191 of file QKinect.cpp.

void QKinect::setRedLedFlash ( )
slot

slot to flash the red led

Definition at line 209 of file QKinect.cpp.

void QKinect::setUserDeviceNumber ( int  _m)
inline

we can set the user device number here by default it will be 1

Parameters:
[in]_mthe number we wish to set

Definition at line 123 of file QKinect.h.

void QKinect::setVideoMode ( int  _mode)
slot

slot to set the video mode

param _mode the video mode as an int index FREENECT_VIDEO_RGB = 0, FREENECT_VIDEO_YUV_RGB = 1, FREENECT_VIDEO_IR_8BIT = 2,

stop the video and set to new mode

Definition at line 227 of file QKinect.cpp.

Here is the call graph for this function:

void QKinect::setYellowLed ( )
slot

slot to enable the yellow LED

Definition at line 203 of file QKinect.cpp.

void QKinect::setYellowLedFlash ( )
slot

slot to flash the yellow led

Definition at line 221 of file QKinect.cpp.

void QKinect::shutDownKinect ( )

method to shutdown our device and close

stop the processing thread

stop the video and depth callbacks

Definition at line 171 of file QKinect.cpp.

Here is the call graph for this function:

void QKinect::startDepth ( )
slot

start the Depth buffer grabbing subsystem

Definition at line 463 of file QKinect.cpp.

Here is the caller graph for this function:

void QKinect::startVideo ( )
slot

start the Video buffer grabbing subsystem

Definition at line 445 of file QKinect.cpp.

Here is the caller graph for this function:

void QKinect::stopDepth ( )
slot

stop the Depth buffer grabbing subsystem

Definition at line 472 of file QKinect.cpp.

Here is the caller graph for this function:

void QKinect::stopVideo ( )
slot

stop the Depth buffer grabbing subsystem

Definition at line 454 of file QKinect.cpp.

Here is the caller graph for this function:

void QKinect::toggleDepthState ( bool  _mode)
slot

convenience method to toggle the depth mode with a bool to indicate mode, useful for connecting to buttons

Definition at line 494 of file QKinect.cpp.

Here is the call graph for this function:

void QKinect::toggleVideoState ( bool  _mode)
slot

convenience method to toggle the video mode with a bool to indicate mode, useful for connecting to buttons

Definition at line 481 of file QKinect.cpp.

Here is the call graph for this function:

static void QKinect::videoCallback ( freenect_device *  _dev,
void *  _video,
uint32_t  _timestamp = 0 
)
inlinestaticprivate

this hooks into the feenet callback system an is the main way of getting the data from the kinect this is not called directly

Parameters:
[in]_devthis is not used as we use the class m_dev
[out]_videothe depth data
[in]_timestampthe timestamp of the operation (not used)

get an instance of our device

then fill the video buffer

Definition at line 434 of file QKinect.h.

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

bool QKinect::kinectDetected

true if camera detected

Definition at line 133 of file QKinect.h.

std::vector<uint8_t> QKinect::m_bufferDepth
private

our depth buffer for the current depth frames will be filled from the depth callback, this data is converted into an RGB representation with Red being closest and blue far away, this is done via a gamma table and converting the depth from 16 bit to 8 bit RGB useful for OpenCV like motion tracking

Definition at line 332 of file QKinect.h.

std::vector<uint8_t> QKinect::m_bufferDepthRaw
private

our depth buffer for the current depth frames will be filled from the depth callback this is the unaltered data converted to 8 bit not really useful so may get rid of at a later date just legacy from testing the other examples

Definition at line 346 of file QKinect.h.

std::vector<uint16_t> QKinect::m_bufferDepthRaw16
private

the 16Bit raw depth values, this is good for voxel rendering of the data

Definition at line 352 of file QKinect.h.

std::vector<uint8_t> QKinect::m_bufferVideo
private

our video buffer for the current rgb video frames will be filled from the rgb callback

Definition at line 338 of file QKinect.h.

freenect_context* QKinect::m_ctx
private

the contex for the device

Definition at line 297 of file QKinect.h.

freenect_device* QKinect::m_dev
private

our device pointer

Definition at line 302 of file QKinect.h.

bool QKinect::m_deviceActive
private

flag to indicate if the device is active

Definition at line 378 of file QKinect.h.

std::vector<uint16_t> QKinect::m_gamma
private

our gamma table this is filled in the ctor and used in the depth callbacks, this is taken from the sample code glview.c cppview.cpp

Definition at line 358 of file QKinect.h.

QMutex QKinect::m_mutex
private

our mutex used for the threaded processes, for ease we use a QMutexLocker to automagically control our mutex state

Definition at line 389 of file QKinect.h.

bool QKinect::m_newDepthFrame
private

flag to indicate if there is a new depth frame

Definition at line 368 of file QKinect.h.

bool QKinect::m_newRgbFrame
private

flag to indicate if there is a new rgb frame

Definition at line 363 of file QKinect.h.

QKinectProcessEvents* QKinect::m_process
private

pointer to our thread process used to process the events

Definition at line 383 of file QKinect.h.

bool QKinect::m_stopDevice
private

flag to indicate if we need to stop the device

Definition at line 373 of file QKinect.h.

int QKinect::m_userDeviceNumber
private

user device number

Definition at line 307 of file QKinect.h.

QKinect * QKinect::s_instance = 0
staticprivate

our instance of the Kinect device

Definition at line 292 of file QKinect.h.


The documentation for this class was generated from the following files: