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