KinectV1Device.hpp
Go to the documentation of this file.
1 //
2 // Created by christoph on 22.08.19.
3 //
4 
5 #ifndef VISIONX_KINECTV1DEVICE_HPP
6 #define VISIONX_KINECTV1DEVICE_HPP
7 
8 #include <libfreenect.hpp>
9 #include <boost/thread/mutex.hpp>
10 #include <vector>
11 
12 
13 
14 class KinectV1Device : public Freenect::FreenectDevice
15 {
16 public:
17  KinectV1Device(freenect_context* _ctx, int _index)
18  : Freenect::FreenectDevice(_ctx, _index),
19  m_buffer_video(freenect_find_video_mode(FREENECT_RESOLUTION_MEDIUM, FREENECT_VIDEO_RGB).bytes),
20  m_buffer_depth(freenect_find_depth_mode(FREENECT_RESOLUTION_MEDIUM, FREENECT_DEPTH_REGISTERED).bytes / 2),
21  m_new_rgb_frame(false), m_new_depth_frame(false)
22  {
23  setDepthFormat(FREENECT_DEPTH_REGISTERED);
24  }
25 
26  // Do not call directly, even in child
27  void VideoCallback(void* _rgb, uint32_t timestamp)
28  {
29  boost::mutex::scoped_lock lock(m_rgb_mutex);
30  uint8_t* rgb = static_cast<uint8_t*>(_rgb);
31  copy(rgb, rgb + getVideoBufferSize(), m_buffer_video.begin());
32  m_new_rgb_frame = true;
33  }
34 
35  // Do not call directly, even in child
36  void DepthCallback(void* _depth, uint32_t timestamp)
37  {
38  boost::mutex::scoped_lock lock(m_depth_mutex);
39  uint16_t* depth = static_cast<uint16_t*>(_depth);
40  copy(depth, depth + getDepthBufferSize() / 2, m_buffer_depth.begin());
41  m_new_depth_frame = true;
42  }
43 
44  bool getRGB(std::vector<uint8_t>& buffer)
45  {
46  boost::mutex::scoped_lock lock(m_rgb_mutex);
47 
48  if (!m_new_rgb_frame)
49  {
50  return false;
51  }
52 
53  buffer.swap(m_buffer_video);
54  m_new_rgb_frame = false;
55 
56  return true;
57  }
58 
59  bool getDepth(std::vector<uint16_t>& buffer)
60  {
61  boost::mutex::scoped_lock lock(m_depth_mutex);
62 
63  if (!m_new_depth_frame)
64  {
65  return false;
66  }
67 
68  buffer.swap(m_buffer_depth);
69  m_new_depth_frame = false;
70 
71  return true;
72  }
73 
74 private:
75  mutable boost::mutex m_rgb_mutex;
76  mutable boost::mutex m_depth_mutex;
77  std::vector<uint8_t> m_buffer_video;
78  std::vector<uint16_t> m_buffer_depth;
79  bool m_new_rgb_frame;
80  bool m_new_depth_frame;
81 };
82 
83 #endif //VISIONX_KINECTV1DEVICE_HPP
KinectV1Device::KinectV1Device
KinectV1Device(freenect_context *_ctx, int _index)
Definition: KinectV1Device.hpp:17
KinectV1Device
Definition: KinectV1Device.hpp:14
KinectV1Device::getDepth
bool getDepth(std::vector< uint16_t > &buffer)
Definition: KinectV1Device.hpp:59
KinectV1Device::VideoCallback
void VideoCallback(void *_rgb, uint32_t timestamp)
Definition: KinectV1Device.hpp:27
copy
Use of this software is granted under one of the following two to be chosen freely by the user Boost Software License Version Marcin Kalicinski Permission is hereby free of to any person or organization obtaining a copy of the software and accompanying documentation covered by this and transmit the and to prepare derivative works of the and to permit third parties to whom the Software is furnished to do all subject to the including the above license this restriction and the following must be included in all copies of the in whole or in and all derivative works of the unless such copies or derivative works are solely in the form of machine executable object code generated by a source language processor THE SOFTWARE IS PROVIDED AS WITHOUT WARRANTY OF ANY EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF FITNESS FOR A PARTICULAR TITLE AND NON INFRINGEMENT IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN TORT OR ARISING OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE The MIT Marcin Kalicinski Permission is hereby free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to copy
Definition: license.txt:39
KinectV1Device::getRGB
bool getRGB(std::vector< uint8_t > &buffer)
Definition: KinectV1Device.hpp:44
KinectV1Device::DepthCallback
void DepthCallback(void *_depth, uint32_t timestamp)
Definition: KinectV1Device.hpp:36