Visual Servoing Platform  version 3.3.0 under development (2020-02-17)
vp1394TwoGrabber.h
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 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 http://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  * Authors:
35  * Fabien Spindler
36  *
37  *****************************************************************************/
38 
55 #ifndef vp1394TwoGrabber_h
56 #define vp1394TwoGrabber_h
57 
58 #include <visp3/core/vpConfig.h>
59 
60 #include <list>
61 
62 #if defined(VISP_HAVE_DC1394)
63 
171 /*
172  * Interface with libdc1394 2.x
173  */
174 #include <string.h>
175 
176 #include <dc1394/control.h>
177 #include <dc1394/utils.h>
178 #include <dc1394/vendor/avt.h>
179 
180 #include <visp3/core/vpFrameGrabber.h>
181 #include <visp3/core/vpImage.h>
182 #include <visp3/core/vpRGBa.h>
183 
184 class VISP_EXPORT vp1394TwoGrabber : public vpFrameGrabber
185 {
186 
187 public:
188  static const char *strVideoMode[DC1394_VIDEO_MODE_NUM];
189  static const char *strFramerate[DC1394_FRAMERATE_NUM];
190  static const char *strColorCoding[DC1394_COLOR_CODING_NUM];
191 
196  typedef enum {
197  vpISO_SPEED_100 = DC1394_ISO_SPEED_100,
198  vpISO_SPEED_200 = DC1394_ISO_SPEED_200,
199  vpISO_SPEED_400 = DC1394_ISO_SPEED_400,
200  vpISO_SPEED_800 = DC1394_ISO_SPEED_800,
201  vpISO_SPEED_1600 = DC1394_ISO_SPEED_1600,
202  vpISO_SPEED_3200 = DC1394_ISO_SPEED_3200
204 
209  typedef enum {
210  vpVIDEO_MODE_160x120_YUV444 = DC1394_VIDEO_MODE_160x120_YUV444,
211  vpVIDEO_MODE_320x240_YUV422 = DC1394_VIDEO_MODE_320x240_YUV422,
212  vpVIDEO_MODE_640x480_YUV411 = DC1394_VIDEO_MODE_640x480_YUV411,
213  vpVIDEO_MODE_640x480_YUV422 = DC1394_VIDEO_MODE_640x480_YUV422,
214  vpVIDEO_MODE_640x480_RGB8 = DC1394_VIDEO_MODE_640x480_RGB8,
215  vpVIDEO_MODE_640x480_MONO8 = DC1394_VIDEO_MODE_640x480_MONO8,
216  vpVIDEO_MODE_640x480_MONO16 = DC1394_VIDEO_MODE_640x480_MONO16,
217  vpVIDEO_MODE_800x600_YUV422 = DC1394_VIDEO_MODE_800x600_YUV422,
218  vpVIDEO_MODE_800x600_RGB8 = DC1394_VIDEO_MODE_800x600_RGB8,
219  vpVIDEO_MODE_800x600_MONO8 = DC1394_VIDEO_MODE_800x600_MONO8,
220  vpVIDEO_MODE_1024x768_YUV422 = DC1394_VIDEO_MODE_1024x768_YUV422,
221  vpVIDEO_MODE_1024x768_RGB8 = DC1394_VIDEO_MODE_1024x768_RGB8,
222  vpVIDEO_MODE_1024x768_MONO8 = DC1394_VIDEO_MODE_1024x768_MONO8,
223  vpVIDEO_MODE_800x600_MONO16 = DC1394_VIDEO_MODE_800x600_MONO16,
224  vpVIDEO_MODE_1024x768_MONO16 = DC1394_VIDEO_MODE_1024x768_MONO16,
225  vpVIDEO_MODE_1280x960_YUV422 = DC1394_VIDEO_MODE_1280x960_YUV422,
226  vpVIDEO_MODE_1280x960_RGB8 = DC1394_VIDEO_MODE_1280x960_RGB8,
227  vpVIDEO_MODE_1280x960_MONO8 = DC1394_VIDEO_MODE_1280x960_MONO8,
228  vpVIDEO_MODE_1600x1200_YUV422 = DC1394_VIDEO_MODE_1600x1200_YUV422,
229  vpVIDEO_MODE_1600x1200_RGB8 = DC1394_VIDEO_MODE_1600x1200_RGB8,
230  vpVIDEO_MODE_1600x1200_MONO8 = DC1394_VIDEO_MODE_1600x1200_MONO8,
231  vpVIDEO_MODE_1280x960_MONO16 = DC1394_VIDEO_MODE_1280x960_MONO16,
232  vpVIDEO_MODE_1600x1200_MONO16 = DC1394_VIDEO_MODE_1600x1200_MONO16,
233  vpVIDEO_MODE_EXIF = DC1394_VIDEO_MODE_EXIF,
234  vpVIDEO_MODE_FORMAT7_0 = DC1394_VIDEO_MODE_FORMAT7_0,
235  vpVIDEO_MODE_FORMAT7_1 = DC1394_VIDEO_MODE_FORMAT7_1,
236  vpVIDEO_MODE_FORMAT7_2 = DC1394_VIDEO_MODE_FORMAT7_2,
237  vpVIDEO_MODE_FORMAT7_3 = DC1394_VIDEO_MODE_FORMAT7_3,
238  vpVIDEO_MODE_FORMAT7_4 = DC1394_VIDEO_MODE_FORMAT7_4,
239  vpVIDEO_MODE_FORMAT7_5 = DC1394_VIDEO_MODE_FORMAT7_5,
240  vpVIDEO_MODE_FORMAT7_6 = DC1394_VIDEO_MODE_FORMAT7_6,
241  vpVIDEO_MODE_FORMAT7_7 = DC1394_VIDEO_MODE_FORMAT7_7
243 
248  typedef enum {
249  vpFRAMERATE_1_875 = DC1394_FRAMERATE_1_875,
250  vpFRAMERATE_3_75 = DC1394_FRAMERATE_3_75,
251  vpFRAMERATE_7_5 = DC1394_FRAMERATE_7_5,
252  vpFRAMERATE_15 = DC1394_FRAMERATE_15,
253  vpFRAMERATE_30 = DC1394_FRAMERATE_30,
254  vpFRAMERATE_60 = DC1394_FRAMERATE_60,
255  vpFRAMERATE_120 = DC1394_FRAMERATE_120,
256  vpFRAMERATE_240 = DC1394_FRAMERATE_240
258 
263  typedef enum {
264  vpCOLOR_CODING_MONO8 = DC1394_COLOR_CODING_MONO8,
265  vpCOLOR_CODING_YUV411 = DC1394_COLOR_CODING_YUV411,
266  vpCOLOR_CODING_YUV422 = DC1394_COLOR_CODING_YUV422,
267  vpCOLOR_CODING_YUV444 = DC1394_COLOR_CODING_YUV444,
268  vpCOLOR_CODING_RGB8 = DC1394_COLOR_CODING_RGB8,
269  vpCOLOR_CODING_MONO16 = DC1394_COLOR_CODING_MONO16,
270  vpCOLOR_CODING_RGB16 = DC1394_COLOR_CODING_RGB16,
271  vpCOLOR_CODING_MONO16S = DC1394_COLOR_CODING_MONO16S,
272  vpCOLOR_CODING_RGB16S = DC1394_COLOR_CODING_RGB16S,
273  vpCOLOR_CODING_RAW8 = DC1394_COLOR_CODING_RAW8,
274  vpCOLOR_CODING_RAW16 = DC1394_COLOR_CODING_RAW16
276 
281  typedef enum {
282  vpFEATURE_BRIGHTNESS = DC1394_FEATURE_BRIGHTNESS,
283  vpFEATURE_EXPOSURE = DC1394_FEATURE_EXPOSURE,
284  vpFEATURE_SHARPNESS = DC1394_FEATURE_SHARPNESS,
285  // vpFEATURE_WHITE_BALANCE = DC1394_FEATURE_WHITE_BALANCE,
286  vpFEATURE_HUE = DC1394_FEATURE_HUE,
287  vpFEATURE_SATURATION = DC1394_FEATURE_SATURATION,
288  vpFEATURE_GAMMA = DC1394_FEATURE_GAMMA,
289  vpFEATURE_SHUTTER = DC1394_FEATURE_SHUTTER,
290  vpFEATURE_GAIN = DC1394_FEATURE_GAIN,
291  vpFEATURE_IRIS = DC1394_FEATURE_IRIS,
292  // vpFEATURE_FOCUS = DC1394_FEATURE_FOCUS,
293  // vpFEATURE_TEMPERATURE = DC1394_FEATURE_TEMPERATURE,
294  // vpFEATURE_TRIGGER = DC1394_FEATURE_TRIGGER,
295  // vpFEATURE_TRIGGER_DELAY = DC1394_FEATURE_TRIGGER_DELAY,
296  // vpFEATURE_WHITE_SHADING = DC1394_FEATURE_WHITE_SHADING,
297  // vpFEATURE_FRAME_RATE = DC1394_FEATURE_FRAME_RATE,
298  // vpFEATURE_ZOOM = DC1394_FEATURE_ZOOM,
299  // vpFEATURE_PAN = DC1394_FEATURE_PAN,
300  // vpFEATURE_TILT = DC1394_FEATURE_TILT,
301  // vpFEATURE_OPTICAL_FILTER = DC1394_FEATURE_OPTICAL_FILTER,
302  // vpFEATURE_CAPTURE_SIZE = DC1394_FEATURE_CAPTURE_SIZE,
303  // vpFEATURE_CAPTURE_QUALITY = DC1394_FEATURE_CAPTURE_QUALITY
305 
306 private:
310  typedef struct {
311  uint32_t brightness;
312  uint32_t exposure;
313  uint32_t sharpness;
314  // uint32_t whiteBalance;
315  uint32_t hue;
316  uint32_t saturation;
317  uint32_t gamma;
318  uint32_t shutter;
319  uint32_t gain;
320  uint32_t iris;
321  // uint32_t focus;
322  // uint32_t temperature ;
323  // uint32_t trigger ;
324  // uint32_t triggerDelay ;
325  // uint32_t whiteShadding ;
326  // uint32_t frameRate ;
327  // uint32_t zoom;
328  // uint32_t pan;
329  // uint32_t tilt ;
330  // uint32_t opticalFilter ;
331  // uint32_t captureSize;
332  // uint32_t captureQuality ;
333  } vpDc1394TwoCameraParametersData;
334 
335  // private:
336  //#ifndef DOXYGEN_SHOULD_SKIP_THIS
337  // vp1394TwoGrabber(const vp1394TwoGrabber &)
338  // : camera(NULL), cameras(NULL), num_cameras(0), camera_id(0),
339  // verbose(false), camIsOpen(NULL),
340  // num_buffers(4), // ring buffer size
341  // isDataModified(NULL), initialShutterMode(NULL), dataCam(NULL)
342  // #ifdef VISP_HAVE_DC1394_CAMERA_ENUMERATE // new API >
343  // libdc1394-2.0.0-rc7 , d(NULL),
344  // list(NULL)
345  // #endif
346  // {
347  // throw vpException(vpException::functionNotImplementedError,"Not
348  // implemented!");
349  // }
350  // vp1394TwoGrabber &operator=(const vp1394TwoGrabber &){
351  // throw vpException(vpException::functionNotImplementedError,"Not
352  // implemented!"); return *this;
353  // }
354  //#endif
355 
356 public:
357  explicit vp1394TwoGrabber(bool reset = true);
358  virtual ~vp1394TwoGrabber();
359 
361  void acquire(vpImage<unsigned char> &I, uint64_t &timestamp, uint32_t &id);
362  void acquire(vpImage<vpRGBa> &I);
363  void acquire(vpImage<vpRGBa> &I, uint64_t &timestamp, uint32_t &id);
364 
365  void close();
366 
367  static std::string colorCoding2string(vp1394TwoColorCodingType colorcoding);
368 
369  dc1394video_frame_t *dequeue();
370  dc1394video_frame_t *dequeue(vpImage<unsigned char> &I);
371  dc1394video_frame_t *dequeue(vpImage<unsigned char> &I, uint64_t &timestamp, uint32_t &id);
372  dc1394video_frame_t *dequeue(vpImage<vpRGBa> &I);
373  dc1394video_frame_t *dequeue(vpImage<vpRGBa> &I, uint64_t &timestamp, uint32_t &id);
374  void enqueue(dc1394video_frame_t *frame);
375 
376  static std::string framerate2string(vp1394TwoFramerateType fps);
377 
378  void getAutoGain(unsigned int &minvalue, unsigned int &maxvalue);
379  void getAutoShutter(unsigned int &minvalue, unsigned int &maxvalue);
380 
381  uint64_t getCamera();
382  void getCamera(uint64_t &camera);
383  void getColorCoding(vp1394TwoColorCodingType &coding);
384  uint32_t getColorCodingSupported(vp1394TwoVideoModeType videomode, std::list<vp1394TwoColorCodingType> &codings);
385  void getFramerate(vp1394TwoFramerateType &fps);
386  uint32_t getFramerateSupported(vp1394TwoVideoModeType videomode, std::list<vp1394TwoFramerateType> &fps);
387  uint64_t getGuid();
388  void getGuid(uint64_t &guid);
389  void getHeight(unsigned int &height);
390  unsigned int getHeight();
391  void getNumCameras(unsigned int &ncameras) const;
392  unsigned int getNumCameras() const;
393  unsigned int getParameterValue(vp1394TwoParametersType param);
394  unsigned int getRingBufferSize() const;
395  void getVideoMode(vp1394TwoVideoModeType &videomode);
396  uint32_t getVideoModeSupported(std::list<vp1394TwoVideoModeType> &videomodes);
397  void getWidth(unsigned int &width);
398  unsigned int getWidth();
399 
400  bool isColor();
401  bool isColorCodingSupported(vp1394TwoVideoModeType videomode, vp1394TwoColorCodingType coding);
402  bool isFramerateSupported(vp1394TwoVideoModeType videomode, vp1394TwoFramerateType fps);
403  bool isVideoModeSupported(vp1394TwoVideoModeType videomode);
404  bool isVideoModeFormat7(vp1394TwoVideoModeType videomode);
405 
406  void open(vpImage<unsigned char> &I);
407  void open(vpImage<vpRGBa> &I);
408 
410  vp1394TwoGrabber &operator>>(vpImage<vpRGBa> &I);
411 
412  void printCameraInfo();
413 
414  void resetBus();
415 
416  void setAutoGain(bool enable = true);
417  void setAutoGain(unsigned int minvalue, unsigned int maxvalue);
418  void setAutoShutter(bool enable = true);
419  void setAutoShutter(unsigned int minvalue, unsigned int maxvalue);
420  void setCamera(uint64_t camera);
421  void setColorCoding(vp1394TwoColorCodingType coding);
422  void setFormat7ROI(unsigned int left = 0, unsigned int top = 0, unsigned int width = 0, unsigned int height = 0);
423  void setFramerate(vp1394TwoFramerateType fps);
424  void setIsoTransmissionSpeed(vp1394TwoIsoSpeedType isospeed);
425  void setPanControl(unsigned int panControlValue);
426  void setParameterValue(vp1394TwoParametersType param, unsigned int val);
427  void setRingBufferSize(unsigned int size);
428  void setVideoMode(vp1394TwoVideoModeType videomode);
429 
430  static vp1394TwoVideoModeType string2videoMode(std::string videomode);
431  static vp1394TwoFramerateType string2framerate(std::string fps);
432  static vp1394TwoColorCodingType string2colorCoding(std::string colorcoding);
433 
434  static std::string videoMode2string(vp1394TwoVideoModeType videomode);
435 
436 private:
437  void open();
438  void initialize(bool reset);
439  void setCapture(dc1394switch_t _switch);
440  void setTransmission(dc1394switch_t _switch);
441  inline void updateDataCamToStruct();
442  inline void updateDataStructToCam();
443 
444 private:
445  dc1394camera_t *camera, **cameras;
446  unsigned int num_cameras;
447  unsigned int camera_id;
448 
449  bool verbose;
450  bool *camIsOpen;
451  unsigned int num_buffers;
452 
453  /* parameters for the cameras */
454  bool *isDataModified;
455  dc1394feature_mode_t *initialShutterMode;
456  vpDc1394TwoCameraParametersData *dataCam;
457 
458 #ifdef VISP_HAVE_DC1394_CAMERA_ENUMERATE
459  dc1394_t *d;
460  dc1394camera_list_t *list;
461 #endif
462 };
463 
464 #endif
465 #endif
unsigned int getHeight() const
Return the number of rows in the image.
virtual void open(vpImage< unsigned char > &I)=0
Base class for all video devices. It is designed to provide a front end to video sources.
unsigned int getWidth() const
Return the number of columns in the image.
virtual void close()=0
Class for firewire ieee1394 video devices using libdc1394-2.x api.
virtual void acquire(vpImage< unsigned char > &I)=0