MRPT  2.0.4
CImageGrabber_FlyCapture2.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 
13 
14 namespace mrpt::hwdrivers
15 {
16 /** Options used when creating a camera capture object of type
17  * CImageGrabber_FlyCapture2 \ingroup mrpt_hwdrivers_grp */
19 {
21 
22  /** @name Camera to open
23  * @{ */
24  /** (Default=0) If open_by_guid==false, will open the i'th camera based on
25  * this 0-based index. */
26  unsigned int camera_index{0};
27  /** (Default=false) Set to true to force opening a camera by its GUID, in \a
28  * camera_guid */
29  bool open_by_guid{false};
30  /** GUID of the camera to open, only when open_by_guid==true. */
31  unsigned int camera_guid[4];
32  /** @} */
33 
34  /** @name Camera settings
35  * @{ */
36  /** (Default="", which means default) A string with a video mode, from the
37  * list available in
38  * [FlyCapture2::VideoMode](http://www.ptgrey.com/support/downloads/documents/flycapture/Doxygen/html/),
39  * eg. "VIDEOMODE_640x480Y8", etc. */
40  std::string videomode;
41  /** (Default="", which means default) A string with a framerate, from the
42  * list available in
43  * [FlyCapture2::FrameRate](http://www.ptgrey.com/support/downloads/documents/flycapture/Doxygen/html/),
44  * eg. "FRAMERATE_30", etc. */
45  std::string framerate;
46  /** (Default="BUFFER_FRAMES") A string with a grab mode, from the list
47  * available in
48  * [FlyCapture2::GrabMode](http://www.ptgrey.com/support/downloads/documents/flycapture/Doxygen/html/)
49  */
50  std::string grabmode;
51  /** (Default=30) Number of images that can be stored in the buffer, if
52  * enabled with grabMode. */
53  unsigned int numBuffers{30};
54  /** (Default=5000) Time in milliseconds that RetrieveBuffer() and
55  * WaitForBufferEvent() will wait for an image before timing out and
56  * returning. */
57  int grabTimeout{-1};
58 
59  /** (default=false) Enable non-free-running mode, only capturing when a
60  * given input trigger signal is detected. Refer to PGR docs. */
61  bool trigger_enabled{false};
62  /** (default=0) Refer to PGR docs. */
63  unsigned int trigger_polarity{0};
64  /** (default=0) Refer to PGR docs. */
65  unsigned int trigger_source{0};
66  /** (default=0) Refer to PGR docs. */
67  unsigned int trigger_mode{0};
68 
69  /** (default=false) Enable the generation of a strobe signal in GPIO. Refer
70  * to PGR docs. */
71  bool strobe_enabled{false};
72  /** (default=0) Refer to PGR docs. */
73  unsigned int strobe_source{0};
74  /** (default=0) Refer to PGR docs. */
75  unsigned int strobe_polarity{0};
76  /** (default=0.0) Delay in ms. Refer to PGR docs. */
77  float strobe_delay{0.0f};
78  /** (default=1.0) Pulse durationin ms. Refer to PGR docs. */
79  float strobe_duration{1.0f};
80 
81  /** (default=true) */
82  bool autoexposure_auto{true};
83  /** (default=true) Activate this feature */
84  bool autoexposure_onOff{true};
85  /** (default=true) Numeric mode (absolute or integer values) */
86  bool autoexposure_abs{true};
87  /** (default=0.0) Exposure Value, if autoexposure_auto=false */
88  float autoexposure_EV{0.0f};
89  /** (default=true) */
90  bool shutter_auto{true};
91  /** (default=true) Numeric mode (absolute or integer values) */
92  bool shutter_abs{true};
93  /** (default=4.0) Shutter time, if shutter_auto=false */
94  float shutter_time_ms{4.0f};
95  /** (default=true) */
96  bool gain_auto{true};
97  /** (default=true) Numeric mode (absolute or integer values) */
98  bool gain_abs{true};
99  /** (default=0.0) Sensor gain, if gain_auto=false */
100  float gain_dB{0.0f};
101 
102  /** (default=false) Obtain images as stereo pairs with Flycapture2 */
103  bool stereo_mode{false};
104  /** (default=800) Width for output rectified images */
105  unsigned int rect_width{800};
106  /** (default=600) Height for output rectified images */
107  unsigned int rect_height{600};
108  /** @} */
109 
110  // clang-format off
111  /** Loads all the options from a config file.
112  * Expected format:
113  *
114  * \code
115  * [sectionName]
116  * # Camera selection:
117  * camera_index = 0 // (Default=0) If open_by_guid==false, will open the i'th camera based on this 0-based index.
118  * open_by_guid = false // (Default=false) Set to true to force opening a camera by its GUID, in \a camera_guid
119  * camera_guid = 11223344-55667788-99AABBCC-DDEEFF00 // GUID of the camera to open, only when open_by_guid==true. Hexadecimal blocks separated by dashes ("-")
120  *
121  * # Camera settings:
122  * videomode = VIDEOMODE_640x480Y8 // (Default="", which means default) A string with a video mode, from the list available in [FlyCapture2::VideoMode](http://www.ptgrey.com/support/downloads/documents/flycapture/Doxygen/html/), eg. "VIDEOMODE_640x480Y8", etc.
123  * framerate = FRAMERATE_30 // (Default="", which means default) A string with a framerate, from the list available in [FlyCapture2::FrameRate](http://www.ptgrey.com/support/downloads/documents/flycapture/Doxygen/html/), eg. "FRAMERATE_30", etc.
124  * grabmode = BUFFER_FRAMES // (Default="BUFFER_FRAMES") A string with a grab mode, from the list available in
125  * [FlyCapture2::GrabMode](http://www.ptgrey.com/support/downloads/documents/flycapture/Doxygen/html/)
126  * numBuffers = 30 // (Default=30) Number of images that
127  * can be stored in the buffer, if enabled with grabMode.
128  * grabTimeout = 5000 // (Default=5000) Time in milliseconds that RetrieveBuffer() and WaitForBufferEvent() will wait for an image before timing out and returning.
129  *
130  * trigger_enabled = false // (default=false) Enable non-free-running mode, only capturing when a given input trigger signal is detected. Refer to PGR docs.
131  * #trigger_polarity = 0 // (default=0) Refer to PGR docs.
132  * #trigger_source = 0 // (default=0) Refer to PGR docs.
133  * #trigger_mode = 0 // (default=0) Refer to PGR docs.
134  *
135  * strobe_enabled = false // (default=false) Enable the generation of a strobe signal in GPIO. Refer to PGR docs.
136  * #strobe_source = 1 // (default=0) Refer to PGR docs.
137  * #strobe_polarity = 0 // (default=0) Refer to PGR docs.
138  * #strobe_delay = 0.0 // (default=0.0) Delay in ms. Refer to PGR docs.
139  * #strobe_duration = 1.0 // (default=1.0) Pulse durationin ms. Refer to PGR docs.
140  *
141  * #autoexposure_auto; //!< (default=true)
142  * #autoexposure_abs; //!< (default=true) Numeric mode (absolute or integer values)
143  * #autoexposure_onoff;//!< (default=true) Activate this feature
144  * #autoexposure_EV; //!< (default=0.0) Exposure Value, if autoexposure_auto=false
145  * #shutter_auto = false // (default=true)
146  * #shutter_abs; //!< (default=true) Numeric mode (absolute or integer values)
147  * #shutter_time_ms = 4.0 // (default=4.0) Shutter time, if shutter_auto=false
148  * #gain_auto; //!< (default=true)
149  * #gain_abs; //!< (default=true) Numeric mode (absolute or integer values)
150  * #gain_dB; //!< (default=0.0) Sensor gain, if gain_auto=false
151  *
152  * flycap_stereo_mode = 1 // (default=0) Obtain images as stereo pairs with Flycapture2
153  * flycap_rect_width = 320 // (default=640) Width for output rectified images
154  * flycap_rect_height = 240 // (default=480) Height for output rectified images
155  *
156  * \endcode
157  * \note All parameter names may have an optional prefix, set with the
158  * "prefix" parameter.
159  * For example, if prefix="LEFT_", the expected variable name
160  * "camera_index" in the config section will be "LEFT_camera_index", and so
161  * on.
162  */
163  void loadOptionsFrom(
164  const mrpt::config::CConfigFileBase& configSource,
165  const std::string& sectionName,
166  const std::string& prefix = std::string());
167  // clang-format on
168 };
169 
170 /** A wrapper for Point Gray Research (PGR) FlyCapture2 API for capturing images
171  * from Firewire, USB3 or GigaE cameras and stereo cameras.
172  * This class is only available when compiling MRPT with
173  * "MRPT_HAS_PGR_FLYCAPTURE2".
174  *
175  * \sa See the most generic camera grabber in MRPT:
176  * mrpt::hwdrivers::CCameraSensor
177  * \sa See example code in [samples]/captureVideoFlyCapture2 and
178  * [samples]/captureVideoFlyCapture2_stereo.
179  * \ingroup mrpt_hwdrivers_grp
180  */
182 {
183  protected:
184  /** Opaque pointer to the FlyCapture2::Camera object. nullptr if no camera
185  * is grabbing. */
186  void* m_camera{nullptr};
187  /** Opaque pointer to the FlyCapture2::CameraInfo object. nullptr if no
188  * camera is grabbing. */
189  void* m_camera_info{nullptr};
190  /** Opaque pointer to the FlyCapture2::Image, used as a temporary buffer and
191  * to avoid mem alloc/reallocs. */
192  void* m_img_buffer{nullptr};
193  /** Opaque pointer to the TriclopsContext objetc. nullptr if no context is
194  * active. */
195  void* m_triclops{nullptr};
196 
197  // Camera intrinsic calibration
198  /** Camera baseline (only for stereo cameras) */
199  float m_baseline;
200  /** Camera focal length */
202  /** Camera center coordinates */
204 
205  /** Camera options */
207 
208  public:
209  /** Constructor that does not open a camera. \sa open() */
211 
214  delete;
215 
216  /** Constructor: tries to open the camera with the given options. Raises an
217  * exception on error. \sa open() */
219 
220  /** Destructor */
221  virtual ~CImageGrabber_FlyCapture2();
222 
223  /** Returns the current settings of the camera */
225  {
226  return m_options;
227  }
228 
229  /** Tries to open the camera with the given options, and starts capture.
230  * Raises an exception on error.
231  * \param[in] startCapture If set to false, the camera is only opened and
232  * configured, but a posterior call to startCapture() is required to start
233  * grabbing images.
234  * \sa close(), startCapture()
235  */
236  void open(
237  const TCaptureOptions_FlyCapture2& options,
238  const bool startCapture = true);
239 
240  /** Start the actual image capture of the camera. Must be called after
241  * open(), only when "startCapture" was set to false.
242  * \sa startSyncCapture
243  */
244  void startCapture();
245 
246  /** Starts a synchronous capture of several cameras, which must have been
247  * already opened.
248  * NOTE: This method only works with Firewire cameras, not with USB3 or
249  * GigaE ones (as confirmed by PGR support service).
250  * \sa startCapture
251  */
252  static void startSyncCapture(
253  int numCameras, const CImageGrabber_FlyCapture2** cameras_array);
254 
255  /** Stop capture. */
256  void stopCapture();
257 
258  /** Stop capture and closes the opened camera, if any. Called automatically
259  * on object destruction. */
260  void close();
261 
262  /** Returns the PGR FlyCapture2 library version */
263  static std::string getFC2version();
264 
265  /** Grab mono image from the camera. This method blocks until the next frame
266  * is captured.
267  * \return false on any error. */
268  bool getObservation(mrpt::obs::CObservationImage& out_observation);
269 
270  /** Grab stereo image from the camera. This method blocks until the next
271  * frame is captured.
272  * \return false on any error. */
274 
275  /** Returns if current configuration is stereo or not */
276  inline bool isStereo() { return m_options.stereo_mode; }
277 }; // End of class
278 static_assert(
279  !std::is_copy_constructible_v<CImageGrabber_FlyCapture2> &&
280  !std::is_copy_assignable_v<CImageGrabber_FlyCapture2>,
281  "Copy Check");
282 } // namespace mrpt::hwdrivers
void close()
Stop capture and closes the opened camera, if any.
bool getObservation(mrpt::obs::CObservationImage &out_observation)
Grab mono image from the camera.
Declares a class derived from "CObservation" that encapsules an image from a camera, whose relative pose to robot is also stored.
bool strobe_enabled
(default=false) Enable the generation of a strobe signal in GPIO.
bool gain_abs
(default=true) Numeric mode (absolute or integer values)
float autoexposure_EV
(default=0.0) Exposure Value, if autoexposure_auto=false
void * m_img_buffer
Opaque pointer to the FlyCapture2::Image, used as a temporary buffer and to avoid mem alloc/reallocs...
A wrapper for Point Gray Research (PGR) FlyCapture2 API for capturing images from Firewire...
float m_baseline
Camera baseline (only for stereo cameras)
float strobe_duration
(default=1.0) Pulse durationin ms.
Contains classes for various device interfaces.
std::string grabmode
(Default="BUFFER_FRAMES") A string with a grab mode, from the list available in FlyCapture2::GrabMode...
void startCapture()
Start the actual image capture of the camera.
CImageGrabber_FlyCapture2()
Constructor that does not open a camera.
int grabTimeout
(Default=5000) Time in milliseconds that RetrieveBuffer() and WaitForBufferEvent() will wait for an i...
TCaptureOptions_FlyCapture2 m_options
Camera options.
This class allows loading and storing values and vectors of different types from a configuration text...
void * m_triclops
Opaque pointer to the TriclopsContext objetc.
unsigned int trigger_source
(default=0) Refer to PGR docs.
unsigned int strobe_source
(default=0) Refer to PGR docs.
unsigned int rect_width
(default=800) Width for output rectified images
void * m_camera_info
Opaque pointer to the FlyCapture2::CameraInfo object.
std::string videomode
(Default="", which means default) A string with a video mode, from the list available in FlyCapture2:...
Observation class for either a pair of left+right or left+disparity images from a stereo camera...
Options used when creating a camera capture object of type CImageGrabber_FlyCapture2.
unsigned int rect_height
(default=600) Height for output rectified images
bool autoexposure_abs
(default=true) Numeric mode (absolute or integer values)
bool stereo_mode
(default=false) Obtain images as stereo pairs with Flycapture2
bool trigger_enabled
(default=false) Enable non-free-running mode, only capturing when a given input trigger signal is det...
bool isStereo()
Returns if current configuration is stereo or not.
static void startSyncCapture(int numCameras, const CImageGrabber_FlyCapture2 **cameras_array)
Starts a synchronous capture of several cameras, which must have been already opened.
float shutter_time_ms
(default=4.0) Shutter time, if shutter_auto=false
bool shutter_abs
(default=true) Numeric mode (absolute or integer values)
void * m_camera
Opaque pointer to the FlyCapture2::Camera object.
static std::string getFC2version()
Returns the PGR FlyCapture2 library version.
void loadOptionsFrom(const mrpt::config::CConfigFileBase &configSource, const std::string &sectionName, const std::string &prefix=std::string())
Loads all the options from a config file.
unsigned int trigger_mode
(default=0) Refer to PGR docs.
std::string framerate
(Default="", which means default) A string with a framerate, from the list available in FlyCapture2::...
float gain_dB
(default=0.0) Sensor gain, if gain_auto=false
const TCaptureOptions_FlyCapture2 & getCameraOptions() const
Returns the current settings of the camera.
unsigned int camera_index
(Default=0) If open_by_guid==false, will open the i&#39;th camera based on this 0-based index...
CImageGrabber_FlyCapture2 & operator=(const CImageGrabber_FlyCapture2 &)=delete
unsigned int trigger_polarity
(default=0) Refer to PGR docs.
bool autoexposure_onOff
(default=true) Activate this feature
unsigned int camera_guid[4]
GUID of the camera to open, only when open_by_guid==true.
unsigned int strobe_polarity
(default=0) Refer to PGR docs.
void open(const TCaptureOptions_FlyCapture2 &options, const bool startCapture=true)
Tries to open the camera with the given options, and starts capture.
unsigned int numBuffers
(Default=30) Number of images that can be stored in the buffer, if enabled with grabMode.
bool open_by_guid
(Default=false) Set to true to force opening a camera by its GUID, in camera_guid ...



Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 33de1d0ad Sat Jun 20 11:02:42 2020 +0200 at sáb jun 20 17:35:17 CEST 2020