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



Page generated by Doxygen 1.9.1 for MRPT 1.9.9 Git: 814d80880 Fri Aug 24 01:51:28 2018 +0200 at mar 26 may 2026 12:30:59 CEST