Visual Servoing Platform  version 3.6.1 under development (2024-07-17)
vp1394TwoGrabber.h
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2023 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See https://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Firewire cameras video capture.
33  *
34 *****************************************************************************/
35 
52 #ifndef vp1394TwoGrabber_h
53 #define vp1394TwoGrabber_h
54 
55 #include <visp3/core/vpConfig.h>
56 
57 #include <list>
58 
59 #if defined(VISP_HAVE_DC1394)
60 
61 /*
62  * Interface with libdc1394 2.x
63  */
64 #include <string.h>
65 
66 #include <dc1394/control.h>
67 #include <dc1394/utils.h>
68 #include <dc1394/vendor/avt.h>
69 
70 #include <visp3/core/vpFrameGrabber.h>
71 #include <visp3/core/vpImage.h>
72 #include <visp3/core/vpRGBa.h>
73 
186 class VISP_EXPORT vp1394TwoGrabber : public vpFrameGrabber
187 {
188 
189 public:
190  static const char *strVideoMode[DC1394_VIDEO_MODE_NUM];
191  static const char *strFramerate[DC1394_FRAMERATE_NUM];
192  static const char *strColorCoding[DC1394_COLOR_CODING_NUM];
193 
198  typedef enum
199  {
200  vpISO_SPEED_100 = DC1394_ISO_SPEED_100,
201  vpISO_SPEED_200 = DC1394_ISO_SPEED_200,
202  vpISO_SPEED_400 = DC1394_ISO_SPEED_400,
203  vpISO_SPEED_800 = DC1394_ISO_SPEED_800,
204  vpISO_SPEED_1600 = DC1394_ISO_SPEED_1600,
205  vpISO_SPEED_3200 = DC1394_ISO_SPEED_3200
206  } vp1394TwoIsoSpeedType;
207 
212  typedef enum
213  {
214  vpVIDEO_MODE_160x120_YUV444 = DC1394_VIDEO_MODE_160x120_YUV444,
215  vpVIDEO_MODE_320x240_YUV422 = DC1394_VIDEO_MODE_320x240_YUV422,
216  vpVIDEO_MODE_640x480_YUV411 = DC1394_VIDEO_MODE_640x480_YUV411,
217  vpVIDEO_MODE_640x480_YUV422 = DC1394_VIDEO_MODE_640x480_YUV422,
218  vpVIDEO_MODE_640x480_RGB8 = DC1394_VIDEO_MODE_640x480_RGB8,
219  vpVIDEO_MODE_640x480_MONO8 = DC1394_VIDEO_MODE_640x480_MONO8,
220  vpVIDEO_MODE_640x480_MONO16 = DC1394_VIDEO_MODE_640x480_MONO16,
221  vpVIDEO_MODE_800x600_YUV422 = DC1394_VIDEO_MODE_800x600_YUV422,
222  vpVIDEO_MODE_800x600_RGB8 = DC1394_VIDEO_MODE_800x600_RGB8,
223  vpVIDEO_MODE_800x600_MONO8 = DC1394_VIDEO_MODE_800x600_MONO8,
224  vpVIDEO_MODE_1024x768_YUV422 = DC1394_VIDEO_MODE_1024x768_YUV422,
225  vpVIDEO_MODE_1024x768_RGB8 = DC1394_VIDEO_MODE_1024x768_RGB8,
226  vpVIDEO_MODE_1024x768_MONO8 = DC1394_VIDEO_MODE_1024x768_MONO8,
227  vpVIDEO_MODE_800x600_MONO16 = DC1394_VIDEO_MODE_800x600_MONO16,
228  vpVIDEO_MODE_1024x768_MONO16 = DC1394_VIDEO_MODE_1024x768_MONO16,
229  vpVIDEO_MODE_1280x960_YUV422 = DC1394_VIDEO_MODE_1280x960_YUV422,
230  vpVIDEO_MODE_1280x960_RGB8 = DC1394_VIDEO_MODE_1280x960_RGB8,
231  vpVIDEO_MODE_1280x960_MONO8 = DC1394_VIDEO_MODE_1280x960_MONO8,
232  vpVIDEO_MODE_1600x1200_YUV422 = DC1394_VIDEO_MODE_1600x1200_YUV422,
233  vpVIDEO_MODE_1600x1200_RGB8 = DC1394_VIDEO_MODE_1600x1200_RGB8,
234  vpVIDEO_MODE_1600x1200_MONO8 = DC1394_VIDEO_MODE_1600x1200_MONO8,
235  vpVIDEO_MODE_1280x960_MONO16 = DC1394_VIDEO_MODE_1280x960_MONO16,
236  vpVIDEO_MODE_1600x1200_MONO16 = DC1394_VIDEO_MODE_1600x1200_MONO16,
237  vpVIDEO_MODE_EXIF = DC1394_VIDEO_MODE_EXIF,
238  vpVIDEO_MODE_FORMAT7_0 = DC1394_VIDEO_MODE_FORMAT7_0,
239  vpVIDEO_MODE_FORMAT7_1 = DC1394_VIDEO_MODE_FORMAT7_1,
240  vpVIDEO_MODE_FORMAT7_2 = DC1394_VIDEO_MODE_FORMAT7_2,
241  vpVIDEO_MODE_FORMAT7_3 = DC1394_VIDEO_MODE_FORMAT7_3,
242  vpVIDEO_MODE_FORMAT7_4 = DC1394_VIDEO_MODE_FORMAT7_4,
243  vpVIDEO_MODE_FORMAT7_5 = DC1394_VIDEO_MODE_FORMAT7_5,
244  vpVIDEO_MODE_FORMAT7_6 = DC1394_VIDEO_MODE_FORMAT7_6,
245  vpVIDEO_MODE_FORMAT7_7 = DC1394_VIDEO_MODE_FORMAT7_7
246  } vp1394TwoVideoModeType;
247 
252  typedef enum
253  {
254  vpFRAMERATE_1_875 = DC1394_FRAMERATE_1_875,
255  vpFRAMERATE_3_75 = DC1394_FRAMERATE_3_75,
256  vpFRAMERATE_7_5 = DC1394_FRAMERATE_7_5,
257  vpFRAMERATE_15 = DC1394_FRAMERATE_15,
258  vpFRAMERATE_30 = DC1394_FRAMERATE_30,
259  vpFRAMERATE_60 = DC1394_FRAMERATE_60,
260  vpFRAMERATE_120 = DC1394_FRAMERATE_120,
261  vpFRAMERATE_240 = DC1394_FRAMERATE_240
262  } vp1394TwoFramerateType;
263 
268  typedef enum
269  {
270  vpCOLOR_CODING_MONO8 = DC1394_COLOR_CODING_MONO8,
271  vpCOLOR_CODING_YUV411 = DC1394_COLOR_CODING_YUV411,
272  vpCOLOR_CODING_YUV422 = DC1394_COLOR_CODING_YUV422,
273  vpCOLOR_CODING_YUV444 = DC1394_COLOR_CODING_YUV444,
274  vpCOLOR_CODING_RGB8 = DC1394_COLOR_CODING_RGB8,
275  vpCOLOR_CODING_MONO16 = DC1394_COLOR_CODING_MONO16,
276  vpCOLOR_CODING_RGB16 = DC1394_COLOR_CODING_RGB16,
277  vpCOLOR_CODING_MONO16S = DC1394_COLOR_CODING_MONO16S,
278  vpCOLOR_CODING_RGB16S = DC1394_COLOR_CODING_RGB16S,
279  vpCOLOR_CODING_RAW8 = DC1394_COLOR_CODING_RAW8,
280  vpCOLOR_CODING_RAW16 = DC1394_COLOR_CODING_RAW16
281  } vp1394TwoColorCodingType;
282 
287  typedef enum
288  {
289  vpFEATURE_BRIGHTNESS = DC1394_FEATURE_BRIGHTNESS,
290  vpFEATURE_EXPOSURE = DC1394_FEATURE_EXPOSURE,
291  vpFEATURE_SHARPNESS = DC1394_FEATURE_SHARPNESS,
292  // vpFEATURE_WHITE_BALANCE = DC1394_FEATURE_WHITE_BALANCE,
293  vpFEATURE_HUE = DC1394_FEATURE_HUE,
294  vpFEATURE_SATURATION = DC1394_FEATURE_SATURATION,
295  vpFEATURE_GAMMA = DC1394_FEATURE_GAMMA,
296  vpFEATURE_SHUTTER = DC1394_FEATURE_SHUTTER,
297  vpFEATURE_GAIN = DC1394_FEATURE_GAIN,
298  vpFEATURE_IRIS = DC1394_FEATURE_IRIS,
299  // vpFEATURE_FOCUS = DC1394_FEATURE_FOCUS,
300  // vpFEATURE_TEMPERATURE = DC1394_FEATURE_TEMPERATURE,
301  // vpFEATURE_TRIGGER = DC1394_FEATURE_TRIGGER,
302  // vpFEATURE_TRIGGER_DELAY = DC1394_FEATURE_TRIGGER_DELAY,
303  // vpFEATURE_WHITE_SHADING = DC1394_FEATURE_WHITE_SHADING,
304  // vpFEATURE_FRAME_RATE = DC1394_FEATURE_FRAME_RATE,
305  // vpFEATURE_ZOOM = DC1394_FEATURE_ZOOM,
306  // vpFEATURE_PAN = DC1394_FEATURE_PAN,
307  // vpFEATURE_TILT = DC1394_FEATURE_TILT,
308  // vpFEATURE_OPTICAL_FILTER = DC1394_FEATURE_OPTICAL_FILTER,
309  // vpFEATURE_CAPTURE_SIZE = DC1394_FEATURE_CAPTURE_SIZE,
310  // vpFEATURE_CAPTURE_QUALITY = DC1394_FEATURE_CAPTURE_QUALITY
311  } vp1394TwoParametersType;
312 
313 private:
317  typedef struct
318  {
319  uint32_t brightness;
320  uint32_t exposure;
321  uint32_t sharpness;
322  // uint32_t whiteBalance;
323  uint32_t hue;
324  uint32_t saturation;
325  uint32_t gamma;
326  uint32_t shutter;
327  uint32_t gain;
328  uint32_t iris;
329  // uint32_t focus;
330  // uint32_t temperature ;
331  // uint32_t trigger ;
332  // uint32_t triggerDelay ;
333  // uint32_t whiteShadding ;
334  // uint32_t frameRate ;
335  // uint32_t zoom;
336  // uint32_t pan;
337  // uint32_t tilt ;
338  // uint32_t opticalFilter ;
339  // uint32_t captureSize;
340  // uint32_t captureQuality ;
341  } vpDc1394TwoCameraParametersData;
342 
343  // private:
344  //#ifndef DOXYGEN_SHOULD_SKIP_THIS
345  // vp1394TwoGrabber(const vp1394TwoGrabber &)
346  // : camera(nullptr), cameras(nullptr), num_cameras(0), camera_id(0),
347  // verbose(false), camIsOpen(nullptr),
348  // num_buffers(4), // ring buffer size
349  // isDataModified(nullptr), initialShutterMode(nullptr), dataCam(nullptr)
350  // #ifdef VISP_HAVE_DC1394_CAMERA_ENUMERATE // new API >
351  // libdc1394-2.0.0-rc7 , d(nullptr),
352  // list(nullptr)
353  // #endif
354  // {
355  // throw vpException(vpException::functionNotImplementedError,"Not
356  // implemented!");
357  // }
358  // vp1394TwoGrabber &operator=(const vp1394TwoGrabber &){
359  // throw vpException(vpException::functionNotImplementedError,"Not
360  // implemented!"); return *this;
361  // }
362  //#endif
363 
364 public:
365  VP_EXPLICIT vp1394TwoGrabber(bool reset = true);
366  virtual ~vp1394TwoGrabber();
367 
369  void acquire(vpImage<unsigned char> &I, uint64_t &timestamp, uint32_t &id);
370  void acquire(vpImage<vpRGBa> &I);
371  void acquire(vpImage<vpRGBa> &I, uint64_t &timestamp, uint32_t &id);
372 
373  void close();
374 
375  static std::string colorCoding2string(vp1394TwoColorCodingType colorcoding);
376 
377  dc1394video_frame_t *dequeue();
378  dc1394video_frame_t *dequeue(vpImage<unsigned char> &I);
379  dc1394video_frame_t *dequeue(vpImage<unsigned char> &I, uint64_t &timestamp, uint32_t &id);
380  dc1394video_frame_t *dequeue(vpImage<vpRGBa> &I);
381  dc1394video_frame_t *dequeue(vpImage<vpRGBa> &I, uint64_t &timestamp, uint32_t &id);
382  void enqueue(dc1394video_frame_t *frame);
383 
384  static std::string framerate2string(vp1394TwoFramerateType fps);
385 
386  void getAutoGain(unsigned int &minvalue, unsigned int &maxvalue);
387  void getAutoShutter(unsigned int &minvalue, unsigned int &maxvalue);
388 
389  uint64_t getCamera();
390  void getCamera(uint64_t &camera);
391  void getColorCoding(vp1394TwoColorCodingType &coding);
392  uint32_t getColorCodingSupported(vp1394TwoVideoModeType videomode, std::list<vp1394TwoColorCodingType> &codings);
393  void getFramerate(vp1394TwoFramerateType &fps);
394  uint32_t getFramerateSupported(vp1394TwoVideoModeType videomode, std::list<vp1394TwoFramerateType> &fps);
395  uint64_t getGuid();
396  void getGuid(uint64_t &guid);
397  void getHeight(unsigned int &height);
398  unsigned int getHeight();
399  void getNumCameras(unsigned int &ncameras) const;
400  unsigned int getNumCameras() const;
401  unsigned int getParameterValue(vp1394TwoParametersType param);
402  unsigned int getRingBufferSize() const;
403  void getVideoMode(vp1394TwoVideoModeType &videomode);
404  uint32_t getVideoModeSupported(std::list<vp1394TwoVideoModeType> &videomodes);
405  void getWidth(unsigned int &width);
406  unsigned int getWidth();
407 
408  bool isColor();
409  bool isColorCodingSupported(vp1394TwoVideoModeType videomode, vp1394TwoColorCodingType coding);
410  bool isFramerateSupported(vp1394TwoVideoModeType videomode, vp1394TwoFramerateType fps);
411  bool isVideoModeSupported(vp1394TwoVideoModeType videomode);
412  bool isVideoModeFormat7(vp1394TwoVideoModeType videomode);
413 
414  void open(vpImage<unsigned char> &I);
415  void open(vpImage<vpRGBa> &I);
416 
418  vp1394TwoGrabber &operator>>(vpImage<vpRGBa> &I);
419 
420  void printCameraInfo();
421 
422  void resetBus();
423 
424  void setAutoGain(bool enable = true);
425  void setAutoGain(unsigned int minvalue, unsigned int maxvalue);
426  void setAutoShutter(bool enable = true);
427  void setAutoShutter(unsigned int minvalue, unsigned int maxvalue);
428  void setCamera(uint64_t camera);
429  void setColorCoding(vp1394TwoColorCodingType coding);
430  void setFormat7ROI(unsigned int left = 0, unsigned int top = 0, unsigned int width = 0, unsigned int height = 0);
431  void setFramerate(vp1394TwoFramerateType fps);
432  void setIsoTransmissionSpeed(vp1394TwoIsoSpeedType isospeed);
433  void setPanControl(unsigned int panControlValue);
434  void setParameterValue(vp1394TwoParametersType param, unsigned int val);
435  void setRingBufferSize(unsigned int size);
436  void setVideoMode(vp1394TwoVideoModeType videomode);
437 
438  static vp1394TwoVideoModeType string2videoMode(std::string videomode);
439  static vp1394TwoFramerateType string2framerate(std::string fps);
440  static vp1394TwoColorCodingType string2colorCoding(std::string colorcoding);
441 
442  static std::string videoMode2string(vp1394TwoVideoModeType videomode);
443 
444 private:
445  void open();
446  void initialize(bool reset);
447  void setCapture(dc1394switch_t _switch);
448  void setTransmission(dc1394switch_t _switch);
449  inline void updateDataCamToStruct();
450  inline void updateDataStructToCam();
451 
452 private:
453  dc1394camera_t *camera, **cameras;
454  unsigned int num_cameras;
455  unsigned int camera_id;
456 
457  bool verbose;
458  bool *camIsOpen;
459  unsigned int num_buffers;
460 
461  /* parameters for the cameras */
462  bool *isDataModified;
463  dc1394feature_mode_t *initialShutterMode;
464  vpDc1394TwoCameraParametersData *dataCam;
465 
466 #ifdef VISP_HAVE_DC1394_CAMERA_ENUMERATE
467  dc1394_t *d;
468  dc1394camera_list_t *list;
469 #endif
470 };
471 END_VISP_NAMESPACE
472 #endif
473 #endif
Class for firewire ieee1394 video devices using libdc1394-2.x api.
Base class for all video devices. It is designed to provide a front end to video sources.
virtual void open(vpImage< unsigned char > &I)=0
unsigned int getWidth() const
Return the number of columns in the image.
virtual void acquire(vpImage< unsigned char > &I)=0
unsigned int getHeight() const
Return the number of rows in the image.
virtual void close()=0