iCub-main
FirewireCameraDC1394-DR2_2.h
Go to the documentation of this file.
1 // -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2 
3 /*
4  * Copyright (C) 2007 RobotCub Consortium
5  * Author: Alessandro Scalzo alessandro.scalzo@iit.it
6  * CopyPolicy: Released under the terms of the GNU GPL v2.0.
7  *
8  */
9 
10 // L I N N U U X X
11 // L I NN N U U X X
12 // L I N N N U U X
13 // L I N NN U U X X
14 // LLLLL I N N UUU X X
15 
16 // Added modes 3,4,5 by Alexis Maldonado and Federico Ruiz Ugalde
17 
18 #ifndef __FIREWIRE_CAMERA_DR2_H__
19 #define __FIREWIRE_CAMERA_DR2_H__
20 
21 #include <stdio.h>
22 #include <memory.h>
23 #include <mutex>
24 #include <dc1394/dc1394.h>
25 #include <yarp/os/Time.h>
26 #include <yarp/os/Stamp.h>
27 #include <yarp/os/Log.h>
28 #include <yarp/os/LogStream.h>
29 #include <yarp/os/Value.h>
30 #include <yarp/dev/IVisualParams.h>
31 #include <yarp/dev/IFrameGrabberControlsDC1394.h>
32 #include <yarp/dev/IFrameGrabberControls.h>
33 
34 #define NUM_DMA_BUFFERS 4
35 
36 // formats
37 
38 #define DR_UNINIT 0
39 #define DR_RGB_320x240 1
40 #define DR_RGB_640x480 2
41 #define DR_BAYER_640x480 3
42 #define DR_BAYER16_640x480 4
43 #define DR_YUV_640x480 5
44 
45 //#define DR_YUV_320x240
46 #define DR_RGB_512x384 6
47 #define DR_RGB_800x600 7
48 #define DR_YUV_800x600 8
49 #define DR_RGB_1024x768 9
50 #define DR_YUV_1024x768 10
51 #define DR_BAYER_1024x768 11
52 
53 class CFWCamera_DR2_2 : public yarp::dev::IFrameGrabberControlsDC1394,
54  public yarp::dev::IRgbVisualParams
55 {
56 public:
57  CFWCamera_DR2_2(bool raw);
58 
59  virtual ~CFWCamera_DR2_2()
60  {
61  if (m_pCamera) Close();
62  }
63 
64  int width();
65  int height();
66  int getRawBufferSize();
67 
68  const yarp::os::Stamp& getLastInputStamp();
69 
70  bool Create(yarp::os::Searchable& config);
71 
72  virtual void Close();
73 
74  bool CaptureImage(yarp::sig::ImageOf<yarp::sig::PixelRgb>& image);
75 
76  bool CaptureImage(yarp::sig::ImageOf<yarp::sig::PixelMono>& image);
77 
78  bool CaptureRgb(unsigned char* pBuffer);
79 
80  bool CaptureRaw(unsigned char* pBuffer);
81 
82  bool SetVideoMode(dc1394video_mode_t videoMode);
83  bool SetF7(int newVideoMode,int newXdim,int newYdim,int newColorCoding,int newSpeed,int x0,int y0);
84 
85  bool Capture(yarp::sig::ImageOf<yarp::sig::PixelRgb>* pImage,unsigned char *pBuffer=0,bool bRaw=false);
86  bool Capture(yarp::sig::ImageOf<yarp::sig::PixelMono>* pImage);
87 
88 protected:
89  bool mRawDriver;
90 
91  dc1394_t *m_dc1394_handle;
92  dc1394camera_list_t *m_pCameraList;
93  dc1394video_frame_t m_ConvFrame;
94  dc1394video_frame_t m_ConvFrame_tmp;
95 
98 
101  bool mHires;
103 
104  unsigned int m_RawBufferSize;
105  unsigned int m_XDim,m_YDim;
107 
110 
111  uint32_t m_iMin[DC1394_FEATURE_NUM],m_iMax[DC1394_FEATURE_NUM];
112 
113  dc1394video_frame_t *m_pFrame,*m_pFramePoll;
114  std::mutex m_AcqMutex;
115  yarp::os::Stamp m_Stamp;
118 
119  dc1394camera_t *m_pCamera;
120 
122  double verticalFov;
123  yarp::os::Property intrinsic;
128 
129  inline uint32_t NormToValue(double& dVal,int feature);
130  inline double ValueToNorm(uint32_t iVal,int feature);
131 
132  int TRANSL(int feature);
133 
134  bool manage(dc1394error_t error);
135 
136  int checkInt(yarp::os::Searchable& config,const char* key);
137 
138  double checkDouble(yarp::os::Searchable& config,const char* key);
139 
140  int maxFPS(dc1394video_mode_t mode,dc1394color_coding_t pixelFormat);
141  double bytesPerPixel(dc1394color_coding_t pixelFormat);
142 
146 
147 public:
148 
150  // feature functions
152 
153  // 00
154  virtual bool hasFeatureDC1394(int feature);
155 
156  // 01
157  virtual bool setFeatureDC1394(int feature, double value);
158 
159  // 02
160  virtual double getFeatureDC1394(int feature);
161 
162  // 03
163  virtual bool hasOnOffDC1394(int feature);
164 
165  // 04
166  virtual bool setActiveDC1394(int feature, bool onoff);
167 
168  // 05
169  virtual bool getActiveDC1394(int feature);
170 
171  // 06
172  virtual bool hasManualDC1394(int feature);
173 
174  // 07
175  virtual bool hasAutoDC1394(int feature);
176 
177  // 08
178  virtual bool hasOnePushDC1394(int feature);
179 
180  // 09
181  virtual bool setModeDC1394(int feature, bool auto_onoff);
182 
183  // 10
184  virtual bool getModeDC1394(int feature);
185 
186  // 11
187  virtual bool setOnePushDC1394(int feature);
188 
189  // 23
190  virtual bool setWhiteBalanceDC1394(double b, double r);
191 
192  // 24
193  virtual bool getWhiteBalanceDC1394(double &b, double &r);
194 
196  // end features functions
198 
200  // format functions
202 
203  // 12
204  virtual unsigned int getVideoModeMaskDC1394();
205 
206  // 13
207  virtual bool setVideoModeDC1394(int video_mode);
208 
209  // 14
210  virtual unsigned int getVideoModeDC1394();
211 
212  // 15
213  virtual unsigned int getFPSMaskDC1394();
214 
215  // 16
216  virtual unsigned int getFPSDC1394();
217 
218  // 17
219  virtual bool setFPSDC1394(int fps);
220 
221  // 18
222  virtual unsigned int getISOSpeedDC1394();
223 
224  // 19
225  virtual bool setISOSpeedDC1394(int speed);
226 
227  // 20
228  virtual unsigned int getColorCodingMaskDC1394(unsigned int video_mode);
229  virtual unsigned int getActualColorCodingMaskDC1394();
230 
231  // 21
232  virtual unsigned int getColorCodingDC1394();
233 
234  // 22
235  virtual bool setColorCodingDC1394(int coding);
236 
237  // 25
238  virtual bool getFormat7MaxWindowDC1394(unsigned int &xdim,unsigned int &ydim,unsigned int &xstep,unsigned int &ystep,unsigned int &xoffstep,unsigned int &yoffstep);
239 
240  // 26
241  virtual bool setFormat7WindowDC1394(unsigned int xdim,unsigned int ydim,int x0,int y0);
242 
243  // 27
244  virtual bool getFormat7WindowDC1394(unsigned int &xdim,unsigned int &ydim,int &x0,int &y0);
245 
246  // 28
247  virtual bool setOperationModeDC1394(bool b1394b);
248 
249  // 29
250  virtual bool getOperationModeDC1394();
251 
252  // 30
253  virtual bool setTransmissionDC1394(bool bTxON);
254 
255  // 31
256  virtual bool getTransmissionDC1394();
257 
258  // 32 setBayer
259  // 33 getBayer
260 
261  // 34
262  virtual bool setBroadcastDC1394(bool onoff);
263 
264  // 35
265  virtual bool setDefaultsDC1394();
266 
267  // 36
268  virtual bool setResetDC1394();
269 
270  // 37
271  virtual bool setPowerDC1394(bool onoff);
272 
273  // 38
274  virtual bool setCaptureDC1394(bool bON);
275 
276  // 39
277  virtual unsigned int getBytesPerPacketDC1394();
278 
279  // 40
280  virtual bool setBytesPerPacketDC1394(unsigned int bpp);
281 
283  // end format functions
285 
287  // base class implementation
289 
290  // SET
291 
292  virtual bool setBrightness(double v);
293  virtual bool setExposure(double v);
294  virtual bool setSharpness(double v);
295  virtual bool setWhiteBalance(double blue, double red);
296  virtual bool setHue(double v);
297  virtual bool setSaturation(double v);
298  virtual bool setGamma(double v);
299  virtual bool setShutter(double v);
300  virtual bool setGain(double v);
301  virtual bool setIris(double v);
302 
303  // GET
304 
305  virtual double getBrightness();
306  virtual double getExposure();
307  virtual double getSharpness();
308  virtual bool getWhiteBalance(double &blue, double &red);
309  virtual double getHue();
310  virtual double getSaturation();
311  virtual double getGamma();
312  virtual double getShutter();
313  virtual double getGain();
314  virtual double getIris();
315 
316  /*Implementation of IRgbVisualParams interface*/
317  virtual int getRgbHeight();
318  virtual int getRgbWidth();
319  virtual bool getRgbSupportedConfigurations(yarp::sig::VectorOf<yarp::dev::CameraConfig> &configurations);
320  virtual bool getRgbResolution(int &width, int &height);
321  virtual bool setRgbResolution(int width, int height);
322  virtual bool getRgbFOV(double &horizontalFov, double &verticalFov);
323  virtual bool setRgbFOV(double horizontalFov, double verticalFov);
324  virtual bool getRgbIntrinsicParam(yarp::os::Property &intrinsic);
325  virtual bool getRgbMirroring(bool &mirror);
326  virtual bool setRgbMirroring(bool mirror);
327 
328 };
329 
330 #endif
virtual bool setModeDC1394(int feature, bool auto_onoff)
virtual bool setTransmissionDC1394(bool bTxON)
virtual unsigned int getISOSpeedDC1394()
bool Capture(yarp::sig::ImageOf< yarp::sig::PixelRgb > *pImage, unsigned char *pBuffer=0, bool bRaw=false)
bool CaptureRaw(unsigned char *pBuffer)
virtual unsigned int getFPSDC1394()
FlyCapture2::Error error
virtual unsigned int getColorCodingDC1394()
bool SetVideoMode(dc1394video_mode_t videoMode)
uint32_t m_iMax[DC1394_FEATURE_NUM]
dc1394video_frame_t m_ConvFrame_tmp
double checkDouble(yarp::os::Searchable &config, const char *key)
const yarp::os::Stamp & getLastInputStamp()
uint32_t NormToValue(double &dVal, int feature)
dc1394video_frame_t m_ConvFrame
virtual bool hasFeatureDC1394(int feature)
virtual bool getWhiteBalanceDC1394(double &b, double &r)
bool SetF7(int newVideoMode, int newXdim, int newYdim, int newColorCoding, int newSpeed, int x0, int y0)
virtual unsigned int getVideoModeMaskDC1394()
virtual bool setPowerDC1394(bool onoff)
virtual bool setHue(double v)
virtual bool setShutter(double v)
virtual unsigned int getBytesPerPacketDC1394()
virtual bool setWhiteBalanceDC1394(double b, double r)
virtual unsigned int getVideoModeDC1394()
virtual bool setCaptureDC1394(bool bON)
virtual bool setBrightness(double v)
bool manage(dc1394error_t error)
bool CaptureImage(yarp::sig::ImageOf< yarp::sig::PixelRgb > &image)
virtual bool setFeatureDC1394(int feature, double value)
virtual bool getWhiteBalance(double &blue, double &red)
yarp::os::Property intrinsic
virtual bool hasOnePushDC1394(int feature)
double ValueToNorm(uint32_t iVal, int feature)
virtual bool setRgbFOV(double horizontalFov, double verticalFov)
virtual bool getFormat7WindowDC1394(unsigned int &xdim, unsigned int &ydim, int &x0, int &y0)
virtual bool setOperationModeDC1394(bool b1394b)
virtual bool setBytesPerPacketDC1394(unsigned int bpp)
virtual unsigned int getFPSMaskDC1394()
virtual bool setRgbMirroring(bool mirror)
virtual bool hasAutoDC1394(int feature)
dc1394feature_mode_t m_ShutterSaveModeAuto
virtual bool getRgbFOV(double &horizontalFov, double &verticalFov)
virtual bool setBroadcastDC1394(bool onoff)
virtual bool getRgbSupportedConfigurations(yarp::sig::VectorOf< yarp::dev::CameraConfig > &configurations)
dc1394feature_mode_t m_GainSaveModeAuto
virtual bool getRgbResolution(int &width, int &height)
double bytesPerPixel(dc1394color_coding_t pixelFormat)
virtual bool setExposure(double v)
virtual bool setRgbResolution(int width, int height)
dc1394video_frame_t * m_pFramePoll
virtual bool setSharpness(double v)
uint32_t m_iMin[DC1394_FEATURE_NUM]
int checkInt(yarp::os::Searchable &config, const char *key)
virtual bool hasManualDC1394(int feature)
virtual double getFeatureDC1394(int feature)
virtual unsigned int getActualColorCodingMaskDC1394()
virtual bool getFormat7MaxWindowDC1394(unsigned int &xdim, unsigned int &ydim, unsigned int &xstep, unsigned int &ystep, unsigned int &xoffstep, unsigned int &yoffstep)
dc1394video_frame_t * m_pFrame
bool CaptureRgb(unsigned char *pBuffer)
dc1394camera_list_t * m_pCameraList
virtual bool getRgbIntrinsicParam(yarp::os::Property &intrinsic)
virtual bool setGamma(double v)
virtual bool setActiveDC1394(int feature, bool onoff)
virtual bool setIris(double v)
virtual bool setFPSDC1394(int fps)
virtual unsigned int getColorCodingMaskDC1394(unsigned int video_mode)
virtual bool hasOnOffDC1394(int feature)
virtual bool getActiveDC1394(int feature)
virtual bool setISOSpeedDC1394(int speed)
virtual bool setColorCodingDC1394(int coding)
virtual bool getModeDC1394(int feature)
virtual bool setFormat7WindowDC1394(unsigned int xdim, unsigned int ydim, int x0, int y0)
virtual bool setWhiteBalance(double blue, double red)
virtual bool getRgbMirroring(bool &mirror)
virtual bool setVideoModeDC1394(int video_mode)
int maxFPS(dc1394video_mode_t mode, dc1394color_coding_t pixelFormat)
virtual bool setOnePushDC1394(int feature)
virtual bool setSaturation(double v)
bool Create(yarp::os::Searchable &config)
virtual bool setGain(double v)