supereight
reader_openni.hpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2014 University of Edinburgh, Imperial College London, University of Manchester
3  * SPDX-FileCopyrightText: 2016-2019 Emanuele Vespa
4  * SPDX-FileCopyrightText: 2020-2022 Smart Robotics Lab, Imperial College London, Technical University of Munich
5  * SPDX-FileCopyrightText: 2020-2022 Nils Funk
6  * SPDX-FileCopyrightText: 2020-2022 Sotiris Papatheodorou
7  * SPDX-License-Identifier: MIT
8  */
9 
10 #ifndef __READER_OPENNI_HPP
11 #define __READER_OPENNI_HPP
12 
13 #include <Eigen/Dense>
14 #include <cstdint>
15 #include <fstream>
16 #include <memory>
17 #include <string>
18 
19 #include "reader_base.hpp"
20 #include "se/image/image.hpp"
21 
22 #ifdef SE_USE_OPENNI
23 # include <openni2/OpenNI.h>
24 #endif
25 
26 
27 
28 namespace se {
29 
33 class OpenNIReader : public Reader {
34  public:
39  OpenNIReader(const ReaderConfig& c);
40 
41  ~OpenNIReader();
42 
44  void restart();
45 
50  std::string name() const;
51 
52  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
53 
54  private:
55 #ifdef SE_USE_OPENNI
56  template<typename T>
57  class MyFrameAllocator : public openni::VideoStream::FrameAllocator {
58  public:
59  MyFrameAllocator(T* buffer) : buffer_(buffer)
60  {
61  }
62  void* allocateFrameBuffer(int)
63  {
64  return buffer_;
65  }
66  void freeFrameBuffer(void*)
67  {
68  }
69 
70  private:
71  T* buffer_;
72  };
73 
74  std::unique_ptr<MyFrameAllocator<uint16_t>> depth_allocator_;
75  std::unique_ptr<MyFrameAllocator<uint8_t>> rgb_allocator_;
76 
77  openni::Status rc_;
78  openni::Device device_;
79  openni::VideoStream depth_stream_;
80  openni::VideoStream rgb_stream_;
81  openni::VideoFrameRef depth_frame_;
82  openni::VideoFrameRef rgb_frame_;
83  std::unique_ptr<uint16_t> depth_image_;
84  std::unique_ptr<uint8_t> rgb_image_;
85 #endif
86 
87  ReaderStatus nextDepth(Image<float>& depth_image);
88 
89  ReaderStatus nextRGBA(Image<uint32_t>& rgba_image);
90 };
91 
92 } // namespace se
93 
94 #endif
Definition: reader_base.hpp:46
OpenNIReader(const ReaderConfig &c)
Construct an OpenNIReader from a ReaderConfig.
Base abstract class for dataset readers.
Definition: reader_base.hpp:139
Reader for the Microsoft Kinect and Asus Xtion using the OpenNI2 driver.
Definition: reader_openni.hpp:33
void restart()
Restart reading from the beginning.
ReaderStatus
The result of trying to read a depth/RGB image or a pose.
Definition: reader_base.hpp:105
std::string name() const
The name of the reader.
int Status
Definition: dense_pooling_image.hpp:24
Helper wrapper to allocate and de-allocate octants in the octree.
Definition: colour_utils.hpp:17