MRPT  1.9.9
COpenNI2Generic.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2019, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #pragma once
10 
12 
13 namespace mrpt::hwdrivers
14 {
15 /** An abstract class for accessing OpenNI2 compatible sensors.
16  * This class permits to access several sensors simultaneously. The same
17  *options (resolution, fps, etc.) are used for every sensor.
18  *
19  * More references to read:
20  * - http://http://www.openni.org/
21  * \ingroup mrpt_hwdrivers_grp
22  */
24 {
25  public:
26  /** Default ctor (width=640, height=480, fps=30)
27  */
29  /** Ctor. \sa start()
30  */
32  int width, int height, float fps = 30.0f, bool open_streams_now = true);
33 
34  /** Default ctor
35  */
37 
38  /**Get the number of OpenNI2 cameras currently open via COpenNI2Generic*/
39  static int getNumInstances();
40 
41  /** The main data retrieving function, to be called after calling
42  * loadConfig() and initialize().
43  * \param out_img The output retrieved RGB image (only if
44  * there_is_obs=true).
45  * \param timestamp The timestamp of the capture (only if
46  * there_is_obs=true).
47  * \param there_is_obs If set to false, there was no new observation.
48  * \param hardware_error True on hardware/comms error.
49  * \param sensor_id The index of the sensor accessed. */
50  void getNextFrameRGB(
51  mrpt::img::CImage& rgb_img, mrpt::system::TTimeStamp& timestamp,
52  bool& there_is_obs, bool& hardware_error, unsigned sensor_id = 0);
53 
54  /** The main data retrieving function, to be called after calling
55  * loadConfig() and initialize().
56  * \param depth_img The output retrieved depth image (only if
57  * there_is_obs=true).
58  * \param timestamp The timestamp of the capture (only if
59  * there_is_obs=true).
60  * \param there_is_obs If set to false, there was no new observation.
61  * \param hardware_error True on hardware/comms error.
62  * \param sensor_id The index of the sensor accessed. */
63  void getNextFrameD(
64  mrpt::math::CMatrixF& depth_img, mrpt::system::TTimeStamp& timestamp,
65  bool& there_is_obs, bool& hardware_error, unsigned sensor_id = 0);
66 
67  /** The main data retrieving function, to be called after calling
68  * loadConfig() and initialize().
69  * \param out_obs The output retrieved observation (only if
70  * there_is_obs=true).
71  * \param there_is_obs If set to false, there was no new observation.
72  * \param hardware_error True on hardware/comms error.
73  * \param sensor_id The index of the sensor accessed.
74  *
75  * \sa doProcess
76  */
77  void getNextFrameRGBD(
78  mrpt::obs::CObservation3DRangeScan& out_obs, bool& there_is_obs,
79  bool& hardware_error, unsigned sensor_id = 0);
80 
81  /** @name Open/Close device methods
82  @{ */
83  /** Try to open the camera (all the parameters [resolution,fps,...] must be
84  * set before calling this) - users may also call initialize(), which in
85  * turn calls this method.
86  * Raises an exception upon error.
87  * \exception std::exception A textual description of the error.
88  */
89  void open(unsigned sensor_id = 0);
90 
91  /** Open a set of RGBD devices specified by their serial number. Raises an
92  * exception when the demanded serial numbers
93  * are not among the connected devices. This function also fills a vector
94  * with the serial numbers of the connected
95  * OpenNI2 sensors (this requires openning the sensors which are still
96  * closed to read their serial)
97  */
98  unsigned int openDevicesBySerialNum(
99  const std::set<unsigned>& vSerialRequired);
100 
101  /** Open a RGBD device specified by its serial number. This method is a
102  * wrapper for
103  * openDevicesBySerialNum(const std::set<unsigned>& vSerialRequired)
104  * This method requires to open the sensors which are still closed to read
105  * their serial.
106  */
107  unsigned int openDeviceBySerial(const unsigned int SerialRequired);
108 
109  /** Get the ID of the device corresponding to 'SerialRequired'.
110  */
112  const unsigned int SerialRequired, int& sensor_id) const;
113  /** Open all sensor streams (normally called automatically at constructor,
114  * no need to call it manually). \return false on error \sa kill() to close
115  */
116  bool start();
117  /** Kill the OpenNI2 driver \sa start()
118  */
119  void kill();
120  /** Whether there is a working connection to the sensor
121  */
122  bool isOpen(const unsigned sensor_id) const;
123  /** Close the connection to the sensor (no need to call it manually unless
124  * desired for some reason, since it's called at destructor
125  */
126  void close(unsigned sensor_id = 0);
127  /** The number of available devices at initialization
128  */
129  int getNumDevices() const;
130  /** Get a list of the connected OpenNI2 sensors.
131  */
132  int getConnectedDevices();
133 
134  /** @} */
135 
136  void setVerbose(bool verbose);
137  bool isVerbose() const;
138 
139  bool getColorSensorParam(
140  mrpt::img::TCamera& param, unsigned sensor_id = 0) const;
141  bool getDepthSensorParam(
142  mrpt::img::TCamera& param, unsigned sensor_id = 0) const;
143 
144  class CDevice;
145 
146  protected:
147  /** A vector with the serial numbers of the available devices */
148  std::vector<int> vSerialNums;
149 
150  /** The same options (width, height and fps) are set for all the sensors.
151  * (This could be changed if necessary) */
152  int m_width{640}, m_height{480};
153  float m_fps{30.0f};
155  bool m_verbose{false};
156  void showLog(const std::string& message) const;
157  /** The data that the RGBD sensors can return */
158  /** Default: all true
159  */
160  bool m_grab_image{true}, m_grab_depth{true}, m_grab_3D_points{true};
161 }; // End of class
162 } // namespace mrpt::hwdrivers
bool m_grab_image
The data that the RGBD sensors can return.
int getNumDevices() const
The number of available devices at initialization.
bool getDepthSensorParam(mrpt::img::TCamera &param, unsigned sensor_id=0) const
void getNextFrameRGB(mrpt::img::CImage &rgb_img, mrpt::system::TTimeStamp &timestamp, bool &there_is_obs, bool &hardware_error, unsigned sensor_id=0)
The main data retrieving function, to be called after calling loadConfig() and initialize().
Declares a class derived from "CObservation" that encapsules a 3D range scan measurement, as from a time-of-flight range camera or any other RGBD sensor.
void getNextFrameRGBD(mrpt::obs::CObservation3DRangeScan &out_obs, bool &there_is_obs, bool &hardware_error, unsigned sensor_id=0)
The main data retrieving function, to be called after calling loadConfig() and initialize().
Contains classes for various device interfaces.
COpenNI2Generic()
Default ctor (width=640, height=480, fps=30)
GLenum GLsizei width
Definition: glext.h:3535
int m_width
The same options (width, height and fps) are set for all the sensors.
void kill()
Kill the OpenNI2 driver.
mrpt::Clock::time_point TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1...
Definition: datetime.h:40
unsigned int openDeviceBySerial(const unsigned int SerialRequired)
Open a RGBD device specified by its serial number.
bool start()
Open all sensor streams (normally called automatically at constructor, no need to call it manually)...
bool getColorSensorParam(mrpt::img::TCamera &param, unsigned sensor_id=0) const
bool isOpen(const unsigned sensor_id) const
Whether there is a working connection to the sensor.
static int getNumInstances()
Get the number of OpenNI2 cameras currently open via COpenNI2Generic.
void close(unsigned sensor_id=0)
Close the connection to the sensor (no need to call it manually unless desired for some reason...
Structure to hold the parameters of a pinhole camera model.
Definition: TCamera.h:25
An abstract class for accessing OpenNI2 compatible sensors.
std::vector< int > vSerialNums
A vector with the serial numbers of the available devices.
GLsizei const GLchar ** string
Definition: glext.h:4116
unsigned int openDevicesBySerialNum(const std::set< unsigned > &vSerialRequired)
Open a set of RGBD devices specified by their serial number.
void getNextFrameD(mrpt::math::CMatrixF &depth_img, mrpt::system::TTimeStamp &timestamp, bool &there_is_obs, bool &hardware_error, unsigned sensor_id=0)
The main data retrieving function, to be called after calling loadConfig() and initialize().
This class is a "CSerializable" wrapper for "CMatrixFloat".
Definition: CMatrixF.h:22
void open(unsigned sensor_id=0)
Try to open the camera (all the parameters [resolution,fps,...] must be set before calling this) - us...
bool getDeviceIDFromSerialNum(const unsigned int SerialRequired, int &sensor_id) const
Get the ID of the device corresponding to &#39;SerialRequired&#39;.
int getConnectedDevices()
Get a list of the connected OpenNI2 sensors.
void showLog(const std::string &message) const
GLenum GLsizei GLsizei height
Definition: glext.h:3558
GLfloat param
Definition: glext.h:3838
A class for storing images as grayscale or RGB bitmaps.
Definition: img/CImage.h:147



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 8fe78517f Sun Jul 14 19:43:28 2019 +0200 at lun oct 28 02:10:00 CET 2019