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
lvr2::KinectGrabber::m_haveData
bool m_haveData
Definition: KinectGrabber.hpp:76
lvr2::KinectGrabber::m_colorImage
std::vector< uint8_t > m_colorImage
The raw color image.
Definition: KinectGrabber.hpp:74
KinectGrabber.hpp
lvr2::KinectGrabber::~KinectGrabber
virtual ~KinectGrabber()
Definition: KinectGrabber.cpp:99
lvr2::KinectGrabber::DepthCallback
virtual void DepthCallback(void *data, uint32_t timestamp)
Definition: KinectGrabber.cpp:87
lvr2::KinectGrabber::VideoCallback
virtual void VideoCallback(void *data, uint32_t timestamp)
Definition: KinectGrabber.cpp:54
lvr2::timestamp
static Timestamp timestamp
A global time stamp object for program runtime measurement.
Definition: Timestamp.hpp:116
lvr2::KinectGrabber::getDepthImage
void getDepthImage(std::vector< short > &img)
Returns the currently present point cloud data.
Definition: KinectGrabber.cpp:63
lvr2::KinectGrabber::m_colorMutex
boost::mutex m_colorMutex
Mutex for save color buffer access.
Definition: KinectGrabber.hpp:68
lvr2
Definition: BaseBufferManipulators.hpp:39
lvr2::KinectGrabber::m_depthMutex
boost::mutex m_depthMutex
Mutex for save depth buffer access.
Definition: KinectGrabber.hpp:65
lvr2::KinectGrabber::KinectGrabber
KinectGrabber(freenect_context *_ctx, int _index)
Definition: KinectGrabber.cpp:45
Timestamp.hpp
lvr2::KinectGrabber::getColorImage
void getColorImage(std::vector< uint8_t > &img)
Definition: KinectGrabber.cpp:79
lvr2::KinectGrabber::m_depthImage
std::vector< short > m_depthImage
The raw depth image.
Definition: KinectGrabber.hpp:71


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 Wed Mar 2 2022 00:37:23