KINECT STATS GENERATOR FOR SPORTS VISUALISATION  1.0
KinectInterface 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 <KinectInterface.h>

+ Collaboration diagram for KinectInterface:

List of all members.

Public Slots

void setVideoMode (int _mode)
 slot to set the video mode
bool getDepth (cv::Mat &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 getDepthRaw (cv::Mat &o_buffer, float *o_depthinmBuffer)
 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 getDepth16Bit (cv::Mat &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 getDepthSliced (cv::Mat &o_buffer)
bool getRGB (cv::Mat &o_buffer)
 get the RGB buffer
void startDepth ()
 start the Depth buffer grabbing subsystem
void stopDepth ()
 stop the Depth buffer grabbing subsystem
void startVideo ()
 start the Video buffer grabbing subsystem
void stopVideo ()
 stop the Depth buffer grabbing subsystem
void toggleVideoState (bool _mode)
 convenience method to toggle the video mode with a bool to indicate mode, useful for connecting to buttons
void toggleDepthState (bool _mode)
 convenience method to toggle the depth mode with a bool to indicate mode, useful for connecting to buttons
freenect_context * getContext ()
 return a pointer to the active device context
void setDepthVolumeLower (double _inputLowerDepth)
void setDepthVolumeHigher (double _inputHigherDepth)

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
void setBoxObject (int _topX, int _topY, int _width, int _height)
 this sets the defined bounds into a cv rect
void setBoundsDefined (bool _isBoundsDefined)
 this sets the defined bounds into a cv rect
cv::Rect & getBoxObject ()
 this returns the defined bounds from the RGB window in a Rect format
void toggleTracking ()
 this toggles the tracking flag START/STOP
bool getTrackingFlag ()
 this tells if the user has pressed start tracking
bool getBounds ()
 this tells if the user is refinining bounds by right clicking again and again

Static Public Member Functions

static KinectInterfaceinstance ()
 get the instance of the KinectInterface 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

Private Member Functions

 KinectInterface ()
 private ctor as we are a singleton class
 ~KinectInterface ()
 private dtor as we are a singleton class
bool init ()
 private copy ctor as we are a singleton class
void depthFunc (freenect_device *_dev, void *o_depth, uint32_t _timestamp)
 function for depth callback this hooks into the libfreenect callback system
void rgbFunc (freenect_device *_dev, void *o_rgb, uint32_t _timestamp)
 function for Video 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)

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

freenect_context * m_ctx
 the contex for the device
freenect_device * m_dev
 our device pointer
int m_userDeviceNumber
 user device number
cv::Mat 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
cv::Mat m_bufferVideo
 our video buffer for the current rgb video frames will be filled from the rgb callback
cv::Mat m_nextBuffer
cv::Mat m_prevBuffer
cv::Mat m_diffBuffer
cv::Mat m_bufferVideoGray
cv::Mat 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
float m_bufferDepthinM [640 *480]
cv::Mat m_bufferDepthRaw16
 the 16Bit raw depth values, this is good for voxel rendering of the data
std::vector< float > 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
bool m_newRgbFrame
 flag to indicate if there is a new rgb frame
bool m_newDepthFrame
 flag to indicate if there is a new depth frame
bool m_stopDevice
 flag to indicate if we need to stop the device
bool m_deviceActive
 flag to indicate if the device is active
unsigned int m_resolutionRGBBytes
 size of the RGB buffer for the current mode
unsigned int m_resolutionDepthBytes
 size of the depth buffer for the current mode
QKinectProcessEventsm_process
 pointer to our thread process used to process the events
QMutex m_mutex
 our mutex used for the threaded processes, for ease we use a QMutexLocker to automagically control our mutex state
int m_threshValue
double m_depthLower
double m_depthHigher
cv::Rect m_selectedBoxCoords
bool m_toggleTracking
bool m_setBounds

Static Private Attributes

static KinectInterfaces_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 KinectInterface.h.


Constructor & Destructor Documentation

private ctor as we are a singleton class

Definition at line 96 of file KinectInterface.cpp.

References m_bufferDepthinM.

                                 : QObject(0)
{
    // nothing to see here we just need a valid object pointer the init
    // method does all the hard work
    qDebug()<<"ctor called \n";

    for( unsigned int i = 0 ; i < 640*480 ; ++i)
    {
        m_bufferDepthinM[i] = 0;
    }




}

+ Here is the caller graph for this function:

private dtor as we are a singleton class

Destructor ---------------------------------------------------------------------------------------------------------------.

Definition at line 64 of file KinectInterface.cpp.

References s_instance.

{
        // dtor is not called directly
        if (s_instance)
        {
                delete s_instance;
        }
}

Member Function Documentation

static void KinectInterface::depthCallback ( freenect_device *  _dev,
void *  _depth,
uint32_t  _timestamp = 0 
) [inline, static, private]

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 420 of file KinectInterface.h.

References grabDepth(), and instance().

    {
        Q_UNUSED(_dev);

        KinectInterface *kinect=KinectInterface::instance();
        kinect->grabDepth(_depth,_timestamp);
    }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KinectInterface::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)

this tells if the user is refinining bounds by right clicking again and again

Definition at line 566 of file KinectInterface.cpp.

References m_setBounds.

{
    return m_setBounds;
}

+ Here is the caller graph for this function:

this returns the defined bounds from the RGB window in a Rect format

Definition at line 551 of file KinectInterface.cpp.

References m_selectedBoxCoords.

{
    return m_selectedBoxCoords;
}

+ Here is the caller graph for this function:

freenect_context* KinectInterface::getContext ( ) [inline, slot]

return a pointer to the active device context

Returns:
the current active contects

Definition at line 240 of file KinectInterface.h.

References m_ctx.

{return m_ctx;}
bool KinectInterface::getDepth ( cv::Mat &  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 301 of file KinectInterface.cpp.

References m_bufferDepth, m_mutex, and m_newDepthFrame.

{
    // this fills the depth buffer, first lock our mutex
    QMutexLocker locker( &m_mutex );
    if(m_newDepthFrame)
    {
        // swap data
        m_bufferDepth.copyTo(o_buffer);

        m_newDepthFrame = false;
        return true;
    }
    else
    {
        return false;
    }
}
bool KinectInterface::getDepth16Bit ( cv::Mat &  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 321 of file KinectInterface.cpp.

References m_bufferDepthRaw16, m_mutex, and m_newDepthFrame.

{
    QMutexLocker locker( &m_mutex );
    if(m_newDepthFrame)
    {
        // fill our buffer if avaliable
        m_bufferDepthRaw16.copyTo(o_buffer);
        m_newDepthFrame = false;
        return true;
    }
    else
    {
        return false;
    }
}
bool KinectInterface::getDepthRaw ( cv::Mat &  o_buffer,
float *  o_depthinmBuffer 
) [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 362 of file KinectInterface.cpp.

References m_bufferDepthinM, m_bufferDepthRaw, m_mutex, and m_newDepthFrame.

{


    QMutexLocker locker( &m_mutex );
    if(m_newDepthFrame)
    {

        m_bufferDepthRaw.copyTo(o_buffer);
        for( unsigned int i = 0 ; i < 640*480 ; ++i)
        {
            o_depthinmBuffer[i] = m_bufferDepthinM[i];
        }
        m_newDepthFrame = false;
        return true;
    }
    else
    {
        return false;
    }
}

+ Here is the caller graph for this function:

bool KinectInterface::getDepthSliced ( cv::Mat &  o_buffer) [slot]

fill the 16 Bit data value first lock mutex

Definition at line 342 of file KinectInterface.cpp.

References m_bufferDepthRaw, m_mutex, and m_newDepthFrame.

{
    QMutexLocker locker( &m_mutex );
    if(m_newDepthFrame)
    {
        // fill our buffer if avaliable
        m_bufferDepthRaw.copyTo(o_buffer);
        m_newDepthFrame = false;
        return true;
    }
    else
    {
        return false;
    }
}

+ Here is the caller graph for this function:

bool KinectInterface::getRGB ( cv::Mat &  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 278 of file KinectInterface.cpp.

References m_bufferVideo, m_mutex, and m_newRgbFrame.

{

    //static int _frameCount = 1;
    QMutexLocker locker( &m_mutex );
    // do we have a new frame?
    if(m_newRgbFrame)
    {

        m_bufferVideo.copyTo(o_buffer);
        m_newRgbFrame = false;
        return true;
    }
    else
    {
    return false;
    }
}

+ Here is the caller graph for this function:

this tells if the user has pressed start tracking

Definition at line 561 of file KinectInterface.cpp.

References m_toggleTracking.

{
    return m_toggleTracking;
}

+ Here is the caller graph for this function:

void KinectInterface::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 384 of file KinectInterface.cpp.

References m_bufferDepth, m_bufferDepthinM, m_bufferDepthRaw, m_bufferDepthRaw16, m_depthHigher, m_depthLower, m_gamma, m_mutex, and m_newDepthFrame.

{
// this method fills all the different depth buffers at once
// modifed from the sample code glview and cppview.cpp
QMutexLocker locker( &m_mutex );
// cast the void pointer to the unint16_t the data is actually in
uint16_t* depth = static_cast<uint16_t*>(_depth);



// now loop and fill data buffers
for( unsigned int i = 0 ; i < 640*480 ; ++i)
{
    // first our two raw buffers the first will lose precision and may well
    // be removed in the next iterations

    // now get the index into the gamma table
    float pval = m_gamma[depth[i]]; // my notes: so pval is in metres now..using cam caliberation values, we have converted depth values to metres
                                    // using open kinect forum formulae this (i,j,z) value can be transformed to (x,y,z)





    //m_bufferDepthinM.data[i] = m_gamma[depth[i]];

    //m_originalFrameDepth1[_frameCountGrab] = m_gamma[depth[i]];


    //std::cout<<"pval is"<<pval<<"\n";

    // a bounded volume as explained in rally keeper project to detect contours
    if (pval >= m_depthLower && pval <= m_depthHigher)
    {
        m_bufferDepthRaw.data[i]=255;
        m_bufferDepthRaw16.data[i]=255;
        m_bufferDepthinM[i] = depth[i];
    }
    else
    {
        m_bufferDepthRaw.data[i]=0;
        m_bufferDepthRaw16.data[i]=0;
    }
    if (pval <= 0.9)
    {
        m_bufferDepth.data[3*i+0] = 255;
        m_bufferDepth.data[3*i+1] = 0;
        m_bufferDepth.data[3*i+2] = 0;

    }
    else if (pval > 0.9 && pval <= 2)
    {
        m_bufferDepth.data[3*i+0] = 0;
        m_bufferDepth.data[3*i+1] = 255;
        m_bufferDepth.data[3*i+2] = 0;

    }
    else if (pval > 2)
    {
        m_bufferDepth.data[3*i+0] = 0;
        m_bufferDepth.data[3*i+1] = 0;
        m_bufferDepth.data[3*i+2] = 255;

    }
}
// flag we have a new frame
m_newDepthFrame = true;
}

+ Here is the caller graph for this function:

void KinectInterface::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 457 of file KinectInterface.cpp.

References m_bufferVideo, m_mutex, m_newRgbFrame, and m_resolutionRGBBytes.

{
    // lock our mutex and copy the data from the video buffer
    QMutexLocker locker( &m_mutex );
    uint8_t* rgb = static_cast<uint8_t*>(_video);
    //std::copy(rgb, rgb+m_resolutionRGBBytes, m_bufferVideo.begin());
    memcpy(  m_bufferVideo.data , rgb, m_resolutionRGBBytes);

    m_newRgbFrame = true;
}

+ Here is the caller graph for this function:

bool KinectInterface::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

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 112 of file KinectInterface.cpp.

References depthCallback(), m_bufferDepth, m_bufferDepthRaw, m_bufferDepthRaw16, m_bufferVideo, m_ctx, m_depthHigher, m_depthLower, m_dev, m_deviceActive, m_gamma, m_newDepthFrame, m_newRgbFrame, m_process, m_resolutionDepthBytes, m_resolutionRGBBytes, m_selectedBoxCoords, m_setBounds, m_threshValue, m_toggleTracking, m_userDeviceNumber, QKinectProcessEvents::setActive(), startDepth(), startVideo(), and videoCallback().

{
    // first see if we can init the kinect
    if (freenect_init(&m_ctx, NULL) < 0)
    {
        qDebug()<<"freenect_init() failed\n";
        exit(EXIT_FAILURE);
    }
    freenect_set_log_level(m_ctx, FREENECT_LOG_DEBUG);
    int nr_devices = freenect_num_devices (m_ctx);
    qDebug()<<"Number of devices found: "<<nr_devices<<"\n";

    if(nr_devices < 1)
    {
        //delete s_instance;
        //s_instance = 0;
        return false;
    }
    m_userDeviceNumber = 0;
    // grab the buffer size and store for later use
    m_resolutionRGBBytes=freenect_find_video_mode(FREENECT_RESOLUTION_MEDIUM,FREENECT_VIDEO_RGB).bytes;
    m_bufferDepth=cvCreateMat(480,640,CV_8UC3);

    //m_bufferVideo.resize(m_resolutionRGBBytes);

    m_bufferVideo = cvCreateMat(480,640,CV_8UC3);

//    m_nextBuffer = cvCreateMat(480,640,CV_8UC1);
//    m_prevBuffer = cvCreateMat(480,640,CV_8UC1);
//    m_diffBuffer = cvCreateMat(480,640,CV_8UC1);

    m_resolutionDepthBytes=freenect_find_depth_mode(FREENECT_RESOLUTION_MEDIUM,FREENECT_DEPTH_11BIT).bytes;
    //m_bufferDepthRaw.resize(m_resolutionDepthBytes);
    m_bufferDepthRaw16=cvCreateMat(480,640,CV_8UC1);

    m_bufferDepthRaw=cvCreateMat(480,640,CV_8UC1);



   // m_originalFrameDepth=NULL;



    m_gamma.resize(2048);
    if (freenect_open_device(m_ctx, &m_dev, m_userDeviceNumber) < 0)
    {
        qDebug()<<"Could not open device\n";
        exit(EXIT_FAILURE);
    }


//    for (int i=0; i<2048; ++i)
//    {
//        float v = i/2048.0;
//        v = std::pow(v, 3)* 6;
//        m_gamma[i] = v*6*256;
//    }


    // from opencv imaging imformation wiki page http://openkinect.org/wiki/Imaging_Information
    const float k1 = 1.1863;
    const float k2 = 2842.5;
    const float k3 = 0.1236;
    const float offset = 0.037;
    float depth = 0;
    for (size_t i=0; i<2048; i++)
    {
        depth = k3 * tanf(i/k2 + k1) - offset;
        m_gamma[i] = depth;
    }


    m_newRgbFrame=false;
    m_newDepthFrame=false;
    m_deviceActive=true;

    m_threshValue = 100;


    // set our video formats to RGB by default
    freenect_set_video_mode(m_dev, freenect_find_video_mode(FREENECT_RESOLUTION_MEDIUM, FREENECT_VIDEO_RGB));
    freenect_set_depth_mode(m_dev, freenect_find_depth_mode(FREENECT_RESOLUTION_MEDIUM, FREENECT_DEPTH_11BIT));
    // deprecated
    //freenect_set_video_format(m_dev, FREENECT_VIDEO_RGB);
    //freenect_set_depth_format(m_dev, FREENECT_DEPTH_11BIT);
    freenect_set_depth_callback(m_dev, depthCallback);
    freenect_set_video_callback(m_dev, videoCallback);
    // start the video and depth sub systems
    startVideo();
    startDepth();
    // set the thread to be active and start
    m_process = new QKinectProcessEvents(m_ctx);
    m_process->setActive();
    m_process->start();

    m_depthLower = 0.02;
    m_depthHigher = 1.02; // has to be just above the table (in meteres)

    //m_selectedBoxCoords = NULL;

    m_selectedBoxCoords = cv::Rect(0,0,0,0);

    m_toggleTracking = false;
    m_setBounds = false;

    return true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

get the instance of the KinectInterface 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

Get instance --------------------------------------------------------------------------------------------------------------.

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

Definition at line 75 of file KinectInterface.cpp.

References init(), KinectInterface(), and s_instance.

{
    // this is the main singleton code first check to see if we exist
    if (s_instance==0 )
    {
        // we do so create an instance (this will validate the pointer so other
        // methods called in the init function will have a valid pointer to use)
        s_instance = new KinectInterface;
        // now setup the actual class (with a valid pointer)
        if(s_instance->init() ==  false)
        {
            s_instance = 0;
        }
    }
    // otherwise return the existing pointer
    return s_instance;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KinectInterface::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 KinectInterface::setBoundsDefined ( bool  _isBoundsDefined)

this sets the defined bounds into a cv rect

Definition at line 571 of file KinectInterface.cpp.

References m_setBounds.

{
    m_setBounds = _isBoundsDefined;
}

+ Here is the caller graph for this function:

void KinectInterface::setBoxObject ( int  _topX,
int  _topY,
int  _width,
int  _height 
)

this sets the defined bounds into a cv rect

Definition at line 541 of file KinectInterface.cpp.

References m_selectedBoxCoords, and m_setBounds.

{
    m_setBounds = true;
    m_selectedBoxCoords.x = _topX;
    m_selectedBoxCoords.y = _topY;
    m_selectedBoxCoords.width = _width;
    m_selectedBoxCoords.height = _height;

}

+ Here is the caller graph for this function:

void KinectInterface::setDepthVolumeHigher ( double  _inputHigherDepth) [slot]

Definition at line 536 of file KinectInterface.cpp.

References m_depthHigher.

{
    m_depthHigher = _inputHigherDepth;
}
void KinectInterface::setDepthVolumeLower ( double  _inputLowerDepth) [slot]

Definition at line 531 of file KinectInterface.cpp.

References m_depthLower.

{
    m_depthLower = _inputLowerDepth;
}
void KinectInterface::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 KinectInterface.h.

References m_userDeviceNumber.

void KinectInterface::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 246 of file KinectInterface.cpp.

References m_dev.

{
    freenect_video_format vm=FREENECT_VIDEO_RGB;
    switch(_mode)
    {
        case 0 : { vm=FREENECT_VIDEO_RGB; break;}
        case 1 : { vm=FREENECT_VIDEO_YUV_RGB; break;}
        case 2 : { vm=FREENECT_VIDEO_IR_8BIT; break;}
        /*
        case 1 : { vm=FREENECT_VIDEO_BAYER; break;}
        case 2 : { vm=FREENECT_VIDEO_IR_8BIT; break;}
        case 3 : { vm=FREENECT_VIDEO_IR_10BIT; break;}
        case 4 : { vm=FREENECT_VIDEO_IR_10BIT_PACKED; break;}
        case 5 : { vm=FREENECT_VIDEO_YUV_RGB; break;}
        case 6 : { vm=FREENECT_VIDEO_YUV_RAW; break;}
        */
        default : qDebug()<<"index out of bounds for video mode\n";
                            vm=FREENECT_VIDEO_RGB;
        break;
    }
    freenect_stop_video(m_dev);
    freenect_set_video_mode(m_dev, freenect_find_video_mode(FREENECT_RESOLUTION_MEDIUM, FREENECT_VIDEO_RGB));
    //deprecated
    //  freenect_set_video_format(m_dev, vm);
    freenect_start_video(m_dev);
}

method to shutdown our device and close

stop the processing thread

stop the video and depth callbacks

Definition at line 232 of file KinectInterface.cpp.

References m_ctx, m_dev, m_process, and QKinectProcessEvents::setInActive().

{
    m_process->setInActive();
    freenect_stop_depth(m_dev);
    freenect_stop_video(m_dev);
    // close down our devices
    freenect_close_device(m_dev);
    freenect_shutdown(m_ctx);

}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KinectInterface::startDepth ( ) [slot]

start the Depth buffer grabbing subsystem

Definition at line 488 of file KinectInterface.cpp.

References m_dev.

{
    if(freenect_start_depth(m_dev) < 0)
    {
        throw std::runtime_error("Cannot start depth callback");
    }
}

+ Here is the caller graph for this function:

void KinectInterface::startVideo ( ) [slot]

start the Video buffer grabbing subsystem

Definition at line 472 of file KinectInterface.cpp.

References m_dev.

{
    if(freenect_start_video(m_dev) < 0)
    {
        throw std::runtime_error("Cannot start RGB callback");
    }
}

+ Here is the caller graph for this function:

void KinectInterface::stopDepth ( ) [slot]

stop the Depth buffer grabbing subsystem

Definition at line 497 of file KinectInterface.cpp.

References m_dev.

{
    if(freenect_stop_depth(m_dev) < 0)
    {
        throw std::runtime_error("Cannot stop depth callback");
    }
}

+ Here is the caller graph for this function:

void KinectInterface::stopVideo ( ) [slot]

stop the Depth buffer grabbing subsystem

Definition at line 480 of file KinectInterface.cpp.

References m_dev.

{
    if(freenect_stop_video(m_dev) < 0)
    {
        throw std::runtime_error("Cannot stop RGB callback");
    }
}

+ Here is the caller graph for this function:

void KinectInterface::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 518 of file KinectInterface.cpp.

References startDepth(), and stopDepth().

{
    if(_mode == true)
    {
        startDepth();
    }
    else
    {
        stopDepth();
    }
}

+ Here is the call graph for this function:

this toggles the tracking flag START/STOP

Definition at line 556 of file KinectInterface.cpp.

References m_toggleTracking.

+ Here is the caller graph for this function:

void KinectInterface::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 506 of file KinectInterface.cpp.

References startVideo(), and stopVideo().

{
    if(_mode ==true)
    {
        startVideo();
    }
    else
    {
        stopVideo();
    }
}

+ Here is the call graph for this function:

static void KinectInterface::videoCallback ( freenect_device *  _dev,
void *  _video,
uint32_t  _timestamp = 0 
) [inline, static, private]

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 441 of file KinectInterface.h.

References grabVideo(), and instance().

    {
        Q_UNUSED(_dev);

        KinectInterface *kinect=KinectInterface::instance();
        kinect->grabVideo(_video, _timestamp);
    }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:


Member Data Documentation

cv::Mat KinectInterface::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 293 of file KinectInterface.h.

float KinectInterface::m_bufferDepthinM[640 *480] [private]

Definition at line 307 of file KinectInterface.h.

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 305 of file KinectInterface.h.

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

Definition at line 314 of file KinectInterface.h.

cv::Mat KinectInterface::m_bufferVideo [private]

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

Definition at line 298 of file KinectInterface.h.

Definition at line 298 of file KinectInterface.h.

freenect_context* KinectInterface::m_ctx [private]

the contex for the device

Definition at line 276 of file KinectInterface.h.

Definition at line 360 of file KinectInterface.h.

Definition at line 360 of file KinectInterface.h.

freenect_device* KinectInterface::m_dev [private]

our device pointer

Definition at line 280 of file KinectInterface.h.

flag to indicate if the device is active

Definition at line 336 of file KinectInterface.h.

cv::Mat KinectInterface::m_diffBuffer [private]

Definition at line 298 of file KinectInterface.h.

std::vector<float> KinectInterface::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 320 of file KinectInterface.h.

QMutex KinectInterface::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 355 of file KinectInterface.h.

flag to indicate if there is a new depth frame

Definition at line 328 of file KinectInterface.h.

flag to indicate if there is a new rgb frame

Definition at line 324 of file KinectInterface.h.

cv::Mat KinectInterface::m_nextBuffer [private]

Definition at line 298 of file KinectInterface.h.

cv::Mat KinectInterface::m_prevBuffer [private]

Definition at line 298 of file KinectInterface.h.

pointer to our thread process used to process the events

Definition at line 350 of file KinectInterface.h.

size of the depth buffer for the current mode

Definition at line 345 of file KinectInterface.h.

unsigned int KinectInterface::m_resolutionRGBBytes [private]

size of the RGB buffer for the current mode

Definition at line 341 of file KinectInterface.h.

Definition at line 362 of file KinectInterface.h.

Definition at line 364 of file KinectInterface.h.

flag to indicate if we need to stop the device

Definition at line 332 of file KinectInterface.h.

Definition at line 358 of file KinectInterface.h.

Definition at line 364 of file KinectInterface.h.

user device number

Definition at line 284 of file KinectInterface.h.

our instance of the Kinect device

Definition at line 272 of file KinectInterface.h.


The documentation for this class was generated from the following files:
 All Classes Files Functions Variables Enumerations Enumerator