KINECT STATS GENERATOR FOR SPORTS VISUALISATION
1.0
|
#include <Kinect.h>
Public Member Functions | |
Kinect (freenect_context *_ctx, int _index) | |
~Kinect () | |
void | VideoCallback (void *_rgb, uint32_t timestamp) |
void | DepthCallback (void *_depth, uint32_t timestamp) |
bool | getRGB (std::vector< uint8_t > &buffer) |
bool | getDepth (std::vector< uint8_t > &buffer) |
void | setAngle (double _angle) |
void | setRedLed () |
void | setGreenLed () |
void | setYellowLed () |
void | setRedLedFlash () |
void | setGreenLedFlash () |
void | setYellowLedFlash () |
void | setVideoMode (int _mode) |
void | resetAngle () |
Private Attributes | |
std::vector< uint8_t > | m_buffer_depth |
std::vector< uint8_t > | m_buffer_video |
std::vector< uint16_t > | m_gamma |
Mutex | m_rgb_mutex |
Mutex | m_depth_mutex |
bool | m_new_rgb_frame |
bool | m_new_depth_frame |
Kinect::Kinect | ( | freenect_context * | _ctx, |
int | _index | ||
) |
Definition at line 6 of file Kinect.cpp.
References m_buffer_depth, m_buffer_video, m_gamma, m_new_depth_frame, and m_new_rgb_frame.
:FreenectDevice(_ctx, _index) { m_buffer_depth.resize(FREENECT_VIDEO_RGB_SIZE); m_buffer_video.resize(FREENECT_VIDEO_RGB_SIZE); m_gamma.resize(2048); m_new_rgb_frame=false; m_new_depth_frame=false; for( unsigned int i = 0 ; i < 2048 ; i++) { float v = i/2048.0; v = std::pow(v, 3)* 6; m_gamma[i] = v*6*256; } //m_device = &freenect.createDevice(0); //m_device->startVideo(); //m_device->startDepth(); }
Kinect::~Kinect | ( | ) | [inline] |
void Kinect::DepthCallback | ( | void * | _depth, |
uint32_t | timestamp | ||
) |
Definition at line 39 of file Kinect.cpp.
References Mutex::lock(), m_buffer_depth, m_depth_mutex, m_gamma, m_new_depth_frame, and Mutex::unlock().
{ // std::cout << "Depth callback" << std::endl; m_depth_mutex.lock(); uint16_t* depth = static_cast<uint16_t*>(_depth); for( unsigned int i = 0 ; i < FREENECT_FRAME_PIX ; i++) { int pval = m_gamma[depth[i]]; int lb = pval & 0xff; switch (pval>>8) { case 0: m_buffer_depth[3*i+0] = 255; m_buffer_depth[3*i+1] = 255-lb; m_buffer_depth[3*i+2] = 255-lb; break; case 1: m_buffer_depth[3*i+0] = 255; m_buffer_depth[3*i+1] = lb; m_buffer_depth[3*i+2] = 0; break; case 2: m_buffer_depth[3*i+0] = 255-lb; m_buffer_depth[3*i+1] = 255; m_buffer_depth[3*i+2] = 0; break; case 3: m_buffer_depth[3*i+0] = 0; m_buffer_depth[3*i+1] = 255; m_buffer_depth[3*i+2] = lb; break; case 4: m_buffer_depth[3*i+0] = 0; m_buffer_depth[3*i+1] = 255-lb; m_buffer_depth[3*i+2] = 255; break; case 5: m_buffer_depth[3*i+0] = 0; m_buffer_depth[3*i+1] = 0; m_buffer_depth[3*i+2] = 255-lb; break; default: m_buffer_depth[3*i+0] = 0; m_buffer_depth[3*i+1] = 0; m_buffer_depth[3*i+2] = 0; break; } } m_new_depth_frame = true; m_depth_mutex.unlock(); }
bool Kinect::getDepth | ( | std::vector< uint8_t > & | buffer | ) |
Definition at line 103 of file Kinect.cpp.
References Mutex::lock(), m_buffer_depth, m_depth_mutex, m_new_depth_frame, and Mutex::unlock().
{ m_depth_mutex.lock(); if(m_new_depth_frame) { buffer.swap(m_buffer_depth); m_new_depth_frame = false; m_depth_mutex.unlock(); return true; } else { m_depth_mutex.unlock(); return false; } }
bool Kinect::getRGB | ( | std::vector< uint8_t > & | buffer | ) |
Definition at line 89 of file Kinect.cpp.
References Mutex::lock(), m_buffer_video, m_new_rgb_frame, m_rgb_mutex, and Mutex::unlock().
{ m_rgb_mutex.lock(); if(m_new_rgb_frame) { buffer.swap(m_buffer_video); m_new_rgb_frame = false; m_rgb_mutex.unlock(); return true; } else { m_rgb_mutex.unlock(); return false; } }
void Kinect::resetAngle | ( | ) |
Definition at line 160 of file Kinect.cpp.
{ this->setTiltDegrees(0); }
void Kinect::setAngle | ( | double | _angle | ) |
Definition at line 117 of file Kinect.cpp.
{ if(_angle > 30) { _angle = 30; } else if(_angle <-30) { _angle=-30; } this->setTiltDegrees(_angle); }
void Kinect::setGreenLed | ( | ) |
Definition at line 134 of file Kinect.cpp.
{ this->setLed(LED_GREEN); }
void Kinect::setGreenLedFlash | ( | ) |
Definition at line 146 of file Kinect.cpp.
{ this->setLed(LED_BLINK_GREEN); }
void Kinect::setRedLed | ( | ) |
Definition at line 130 of file Kinect.cpp.
{ this->setLed(LED_RED); }
void Kinect::setRedLedFlash | ( | ) |
Definition at line 142 of file Kinect.cpp.
{ this->setLed(LED_BLINK_RED_YELLOW); }
void Kinect::setVideoMode | ( | int | _mode | ) |
Definition at line 156 of file Kinect.cpp.
{ }
void Kinect::setYellowLed | ( | ) |
Definition at line 138 of file Kinect.cpp.
{ this->setLed(LED_YELLOW); }
void Kinect::setYellowLedFlash | ( | ) |
Definition at line 151 of file Kinect.cpp.
{ this->setLed(LED_BLINK_YELLOW); }
void Kinect::VideoCallback | ( | void * | _rgb, |
uint32_t | timestamp | ||
) |
Definition at line 29 of file Kinect.cpp.
References Mutex::lock(), m_buffer_video, m_new_rgb_frame, m_rgb_mutex, and Mutex::unlock().
{ // std::cout << "RGB callback" << std::endl; m_rgb_mutex.lock(); uint8_t* rgb = static_cast<uint8_t*>(_rgb); std::copy(rgb, rgb+FREENECT_VIDEO_RGB_SIZE, m_buffer_video.begin()); m_new_rgb_frame = true; m_rgb_mutex.unlock(); };
std::vector<uint8_t> Kinect::m_buffer_depth [private] |
std::vector<uint8_t> Kinect::m_buffer_video [private] |
Mutex Kinect::m_depth_mutex [private] |
std::vector<uint16_t> Kinect::m_gamma [private] |
bool Kinect::m_new_depth_frame [private] |
bool Kinect::m_new_rgb_frame [private] |
Mutex Kinect::m_rgb_mutex [private] |