MRPT  2.0.4
CSwissRanger3DCamera.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-2020, 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 
14 
16 
17 namespace mrpt::hwdrivers
18 {
19 /** A class for grabing "range images" from a MESA imaging SwissRanger 3D
20  *cameras (SR-2, SR-3000, SR-4k).
21  *
22  * NOTES:
23  * - This class requires a vendor specific driver installed in the system
24  *in
25  *order to build MRPT with support for this sensor. Download and install the
26  *driver from: http://www.mesa-imaging.ch/drivers.php
27  * - The intensity channel (grayscale image) is converted from 16bit to
28  *standard 8bit-per-pixel using a logarithmic, modified A-law compression. This
29  *allows exploiting the full dynamic range of the sensor and provides quite
30  *good results.
31  *
32  * As with any other CGenericSensor class, the normal sequence of methods to be
33  *called is:
34  * - loadConfig() - Or calls to the individual setXXX() to configure the
35  *camera parameters.
36  * - initialize() - to init the comms with the camera
37  * - call getNextObservation() for getting the frames.
38  *
39  * This sensor can be also used from within rawlog-grabber.
40  *
41  * \code
42  * PARAMETERS IN THE ".INI"-LIKE CONFIGURATION STRINGS:
43  * -------------------------------------------------------
44  * [supplied_section_name]
45  * sensorLabel = CAM3D // A text description
46  * preview_window = true // Show a window with a preview of the
47  *grabbed data in real-time
48  *
49  * open_USB = true // false means ethernet (default: true)
50  * USB_serial = 0x4000002f // only for open_USB=true. If not set, the
51  *first camera will be open. Serial is the last part of S/N (e.g. for the
52  *camera SN: 00-00-40-00-00-2F).
53  * IP_address = 192.168.2.14 // only for open_USB=false. The IP of the
54  *camera.
55  *
56  * // Options for the data to save in each CObservation3DRangeScan
57  * save_3d = true // Save the 3D point cloud (default:
58  *true)
59  * save_range_img = true // Save the 2D range image (default:
60  *true)
61  * save_intensity_img = true // Save the 2D intensity image
62  *(default:
63  *true)
64  * save_confidence = true // Save the estimated confidence 2D
65  *image
66  *(default: false)
67  *
68  * enable_img_hist_equal = false // Enable intensity image histogram
69  *equalization (default: false)
70  * enable_median_filter = true // Enable median filter in range
71  *data
72  *(default: true)
73  * enable_mediancross_filter = false // Enable median cross-filter
74  *(default:
75  *false)
76  * enable_conv_gray = false // Enable intensity image scale with
77  *range
78  *(default: false)
79  * enable_denoise_anf = true // Enable this noise filter
80  *(default:
81  *true)
82  *
83  * // Camera calibration parameters: See mrpt::img::TCamera
84  * // If not provided, a set of default parameters for a SR4000 camera will
85  *be loaded.
86  * resolution = [176 144]
87  * cx = 87.99958
88  * cy = 68.99957
89  * fx = 262.9201
90  * fy = 262.9218
91  * dist = [-8.258543e-01 6.561022e-01 2.699818e-06 -3.263559e-05 0]
92  *
93  * // For externaly stored images, the format of image files (default=jpg)
94  * //external_images_format = jpg
95  * // (Only when external_images_format=jpg): Optional parameter to set the
96  *JPEG compression quality:
97  * //external_images_jpeg_quality = 95 // [1-100]. Default: 95
98  *
99  * pose_x=0.21 // Camera position in the robot (meters)
100  * pose_y=0
101  * pose_z=0.34
102  * pose_yaw=0 // Angles in degrees
103  * pose_pitch=0
104  * pose_roll=0
105  *
106  * \endcode
107  * \ingroup mrpt_hwdrivers_grp
108  */
110 {
112 
113  public:
114  /** Default ctor */
116  /** Default ctor */
117  ~CSwissRanger3DCamera() override;
118 
119  /** Initializes the 3D camera - should be invoked after calling loadConfig()
120  * \exception This method must throw an exception with a descriptive
121  * message if some critical error is found.
122  */
123  void initialize() override;
124 
125  /** To be called at a high rate (>XX Hz), this method populates the
126  * internal buffer of received observations.
127  * This method is mainly intended for usage within rawlog-grabber or
128  * similar programs.
129  * For an alternative, see getNextObservation()
130  * \exception This method must throw an exception with a descriptive
131  * message if some critical error is found.
132  * \sa getNextObservation
133  */
134  void doProcess() override;
135 
136  /** The main data retrieving function, to be called after calling
137  * loadConfig() and initialize().
138  * \param out_obs The output retrieved observation (only if
139  * there_is_obs=true).
140  * \param there_is_obs If set to false, there was no new observation.
141  * \param hardware_error True on hardware/comms error.
142  *
143  * \sa doProcess
144  */
145  void getNextObservation(
146  mrpt::obs::CObservation3DRangeScan& out_obs, bool& there_is_obs,
147  bool& hardware_error);
148 
149  /** return false on error - Called automatically from initialize(), no need
150  * normally for the user to call this. */
151  bool open();
152  void close();
153 
154  /** whether the camera is open and comms work ok. To be called after
155  * initialize() */
156  bool isOpen() const;
157 
158  /** Get the row count in the camera images, loaded automatically upon camera
159  * open(). */
160  size_t rows() const { return m_rows; }
161  /** Get the col count in the camera images, loaded automatically upon camera
162  * open(). */
163  size_t cols() const { return m_cols; }
164  /** Get the camera serial number, loaded automatically upon camera open().
165  */
166  unsigned int getCameraSerialNumber() const { return m_cam_serial_num; }
167  /** Returns the maximum camera range, as deduced from its operating
168  * frequency. */
169  double getMaxRange() const { return m_maxRange; }
170  /** Set the path where to save off-rawlog image files (this class DOES take
171  * into account this path).
172  * An empty string (the default value at construction) means to save
173  * images embedded in the rawlog, instead of on separate files.
174  * \exception std::exception If the directory doesn't exists and cannot be
175  * created.
176  */
177  void setPathForExternalImages(const std::string& directory) override;
178 
179  /** @name Capture configuration methods (apart from loadConfig)
180  @{ */
181 
182  /** true: open from USB, false: open from ethernet. */
183  inline void setOpenFromUSB(bool USB) { m_open_from_usb = USB; }
184  inline bool getOpenFromUSBMode() const { return m_open_from_usb; }
185  inline void setOpenIPAddress(const std::string& IP) { m_ip_address = IP; }
186  inline std::string getOpenIPAddress() const { return m_ip_address; }
187  inline void setSave3D(bool save) { m_save_3d = save; }
188  inline void setSaveRangeImage(bool save) { m_save_range_img = save; }
189  inline void setSaveIntensityImage(bool save)
190  {
191  m_save_intensity_img = save;
192  }
193  inline void setSaveConfidenceImage(bool save) { m_save_confidence = save; }
194  inline void enableImageHistEqualization(bool enable)
195  {
196  m_enable_img_hist_equal = enable;
197  }
198  inline bool isEnabledImageHistEqualization() const
199  {
201  }
202 
203  inline void enableMedianFilter(bool enable)
204  {
205  m_enable_median_filter = enable;
207  }
208  inline bool isEnabledMedianFilter() const { return m_enable_median_filter; }
209  inline void enableMedianCrossFilter(bool enable)
210  {
213  }
214  inline bool isEnabledMedianCrossFilter() const
215  {
217  }
218 
219  inline void enableConvGray(bool enable)
220  {
221  m_enable_conv_gray = enable;
223  }
224  inline bool isEnabledConvGray() const { return m_enable_conv_gray; }
225  inline void enableDenoiseANF(bool enable)
226  {
227  m_enable_denoise_anf = enable;
229  }
230  inline bool isEnabledDenoiseANF() const { return m_enable_denoise_anf; }
231  inline void enablePreviewWindow(bool enable = true)
232  {
233  m_preview_window = enable;
234  }
235  inline bool isEnabledPreviewWindow() const { return m_preview_window; }
236  /** @} */
237 
238  // List of small functions to be implemented differently in Win/Lin.
239 
240  /** Get the version of the MESA library.
241  * \return false on error
242  */
243  bool getMesaLibVersion(std::string& out_version) const;
244 
245  protected:
246  /** See the class documentation at the top for expected parameters */
248  const mrpt::config::CConfigFileBase& configSource,
249  const std::string& section) override;
250 
251  void internal_resendParamsToCamera() const;
252 
254 
255  /** Save the 3D point cloud (default: true) */
256  bool m_save_3d{true};
257  /** Save the 2D range image (default: true) */
258  bool m_save_range_img{true};
259  /** Save the 2D intensity image (default: true) */
261  /** Save the estimated confidence 2D image (default: false) */
262  bool m_save_confidence{false};
263 
267  bool m_enable_conv_gray{false};
269 
270  /** true: USB, false: ETH */
271  bool m_open_from_usb{true};
272  size_t m_usb_serial{0};
273  std::string m_ip_address;
274 
275  /** Size of camera images, set on open() */
276  size_t m_rows{0}, m_cols{0};
277  /** Serial number of the camera, set on open() */
278  unsigned int m_cam_serial_num{0};
279  /** Max range, as deducted from the camera frequency. */
280  double m_maxRange{5};
281 
282  /** Show preview window while grabbing */
283  bool m_preview_window{false};
285 
286  /** opaque handler to SRCAM. nullptr means it's not open yet. */
287  void* m_cam;
288 
290 
291  private:
292 }; // End of class
293 
294 } // namespace mrpt::hwdrivers
A generic interface for a wide-variety of sensors designed to be used in the application RawLogGrabbe...
size_t m_rows
Size of camera images, set on open()
void setOpenFromUSB(bool USB)
true: open from USB, false: open from ethernet.
A class for grabing "range images" from a MESA imaging SwissRanger 3D cameras (SR-2, SR-3000, SR-4k).
A range or depth 3D scan measurement, as from a time-of-flight range camera or a structured-light dep...
double getMaxRange() const
Returns the maximum camera range, as deduced from its operating frequency.
Contains classes for various device interfaces.
void setPathForExternalImages(const std::string &directory) override
Set the path where to save off-rawlog image files (this class DOES take into account this path)...
bool m_save_3d
Save the 3D point cloud (default: true)
bool m_save_confidence
Save the estimated confidence 2D image (default: false)
void loadConfig_sensorSpecific(const mrpt::config::CConfigFileBase &configSource, const std::string &section) override
See the class documentation at the top for expected parameters.
void initialize() override
Initializes the 3D camera - should be invoked after calling loadConfig()
void doProcess() override
To be called at a high rate (>XX Hz), this method populates the internal buffer of received observati...
mrpt::gui::CDisplayWindow::Ptr m_win_range
This class allows loading and storing values and vectors of different types from a configuration text...
bool getMesaLibVersion(std::string &out_version) const
Get the version of the MESA library.
bool m_save_intensity_img
Save the 2D intensity image (default: true)
size_t rows() const
Get the row count in the camera images, loaded automatically upon camera open().
bool m_open_from_usb
true: USB, false: ETH
Parameters for the Brown-Conrady camera lens distortion model.
Definition: TCamera.h:26
double m_maxRange
Max range, as deducted from the camera frequency.
bool m_save_range_img
Save the 2D range image (default: true)
void setOpenIPAddress(const std::string &IP)
bool m_preview_window
Show preview window while grabbing.
#define DEFINE_GENERIC_SENSOR(class_name)
This declaration must be inserted in all CGenericSensor classes definition, within the class declarat...
~CSwissRanger3DCamera() override
Default ctor.
bool isOpen() const
whether the camera is open and comms work ok.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:85
unsigned int m_cam_serial_num
Serial number of the camera, set on open()
void getNextObservation(mrpt::obs::CObservation3DRangeScan &out_obs, bool &there_is_obs, bool &hardware_error)
The main data retrieving function, to be called after calling loadConfig() and initialize().
unsigned int getCameraSerialNumber() const
Get the camera serial number, loaded automatically upon camera open().
size_t cols() const
Get the col count in the camera images, loaded automatically upon camera open().
void * m_cam
opaque handler to SRCAM.
mrpt::gui::CDisplayWindow::Ptr m_win_int
bool open()
return false on error - Called automatically from initialize(), no need normally for the user to call...



Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 5711e29ae Wed May 27 14:29:47 2020 +0200 at miƩ may 27 14:30:10 CEST 2020