KinectGrabber.cpp
Go to the documentation of this file.
1 
28 /*
29  * KinecGrabber.cpp
30  *
31  * Created on: 20.03.2012
32  * Author: Thomas Wiemann
33  */
34 
35 #include <iostream>
36 using std::cout;
37 using std::endl;
38 
40 #include "lvr2/io/Timestamp.hpp"
41 
42 namespace lvr2
43 {
44 
45 KinectGrabber::KinectGrabber(freenect_context *_ctx, int _index)
46  : Freenect::FreenectDevice(_ctx, _index),
47  m_haveData(false)
48 {
49  m_depthImage = std::vector<short>( 640 * 480, 0 );
50  m_colorImage = std::vector<uint8_t>(freenect_find_video_mode(FREENECT_RESOLUTION_MEDIUM, FREENECT_VIDEO_RGB).bytes,0 );
51 
52 }
53 
54 void KinectGrabber::VideoCallback(void* data, uint32_t timestamp)
55 {
56  m_colorMutex.lock();
57  uint8_t* rgb = static_cast<uint8_t*>(data);
58  std::copy(rgb, rgb+getVideoBufferSize(), m_colorImage.begin());
59  m_colorMutex.unlock();
60 }
61 
63 void KinectGrabber::getDepthImage(std::vector<short> &img)
64 {
65  if(m_haveData)
66  {
67  m_depthMutex.lock();
68  img.swap(m_depthImage);
69  m_depthMutex.unlock();
70  m_haveData = false;
71  }
72  else
73  {
74  img.clear();
75  img.resize(0);
76  }
77 }
78 
79 void KinectGrabber::getColorImage(std::vector<uint8_t> &img)
80 {
81  m_colorMutex.lock();
82  img.swap(m_colorImage);
83  m_colorMutex.unlock();
84 }
85 
86 
87 void KinectGrabber::DepthCallback(void* data, uint32_t timestamp)
88 {
89  m_depthMutex.lock();
90  short* depth = static_cast<short*>(data);
91  for( unsigned int i = 0 ; i < 640*480 ; i++) {
92  m_depthImage[i] = depth[i];
93  }
94  m_haveData = true;
95  m_depthMutex.unlock();
96 }
97 
98 
100 {
101 
102 
103 }
104 
105 } // namespace lvr2
void getDepthImage(std::vector< short > &img)
Returns the currently present point cloud data.
virtual void VideoCallback(void *data, uint32_t timestamp)
boost::mutex m_depthMutex
Mutex for save depth buffer access.
static Timestamp timestamp
A global time stamp object for program runtime measurement.
Definition: Timestamp.hpp:116
virtual void DepthCallback(void *data, uint32_t timestamp)
std::vector< uint8_t > m_colorImage
The raw color image.
KinectGrabber(freenect_context *_ctx, int _index)
boost::mutex m_colorMutex
Mutex for save color buffer access.
std::vector< short > m_depthImage
The raw depth image.
void getColorImage(std::vector< uint8_t > &img)


lvr2
Author(s): Thomas Wiemann , Sebastian Pütz , Alexander Mock , Lars Kiesow , Lukas Kalbertodt , Tristan Igelbrink , Johan M. von Behren , Dominik Feldschnieders , Alexander Löhr
autogenerated on Mon Feb 28 2022 22:46:06