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 // W W I N N
11 // W W I NN N
12 // W W W I N N N
13 // WW WW I N NN
14 // W W I N N
15 
16 #ifndef __FIREWIRE_CAMERA_DR2_H__
17 #define __FIREWIRE_CAMERA_DR2_H__
18 
19 #include <stdio.h>
20 #include <memory.h>
21 #include <mutex>
22 #include <Flycapture2.h>
23 #include <yarp/os/Time.h>
24 #include <yarp/os/Stamp.h>
25 
26 #define DR_UNINIT 0
27 #define DR_RGB_HALF_RES 1
28 #define DR_RGB_FULL_RES 2
29 #define DR_BAYER_FULL_RES 3
30 
31 #define NUM_DMA_BUFFERS 8
32 
33 
34 class CFWCamera_DR2_2 : public yarp::dev::IFrameGrabberControlsDC1394
35 {
36 public:
37  CFWCamera_DR2_2(bool raw) : mRawDriver(raw)
38  {
39  }
40 
41  virtual ~CFWCamera_DR2_2()
42  {
43  Close();
44  }
45 
46  int width() { return m_XDim; }
47  int height(){ return m_YDim; }
48 
49  int getRawBufferSize(){ return m_pFrame->GetDataSize(); }
50 
51  const yarp::os::Stamp& getLastInputStamp(){ return m_Stamp; }
52 
53  bool SetVideoMode(FlyCapture2::VideoMode video_mode);
54  bool SetF7(int mode,int xdim,int ydim,int pixel_format,int speed,int x0,int y0);
55 
56  bool Create(yarp::os::Searchable& config);
57 
58  virtual void Close();
59 
60  bool CaptureImage(yarp::sig::ImageOf<yarp::sig::PixelRgb>& image)
61  {
62  return Capture(&image);
63  }
64 
65  bool CaptureImage(yarp::sig::ImageOf<yarp::sig::PixelMono>& image)
66  {
67  return Capture(&image);
68  }
69 
70  bool CaptureRgb(unsigned char* pBuffer)
71  {
72  return Capture(0,pBuffer);
73  }
74 
75  bool CaptureRaw(unsigned char* pBuffer)
76  {
77  return Capture(0,pBuffer,true);
78  }
79 
80  bool Capture(yarp::sig::ImageOf<yarp::sig::PixelRgb>* pImage,unsigned char *pBuffer=0,bool bRaw=false);
81  bool Capture(yarp::sig::ImageOf<yarp::sig::PixelMono>* pImage);
82 
83 protected:
84  bool mRawDriver;
85 
86  FlyCapture2::BusManager *m_pBusManager;
87  FlyCapture2::Camera *m_pCamera;
88  FlyCapture2::Error error;
89 
90  bool mHires;
91  FlyCapture2::CameraInfo m_CameraInfo;
93 
94  FlyCapture2::FC2Config m_CamConfig;
95 
96  FlyCapture2::Format7ImageSettings m_F7ImageSettings;
98  unsigned int m_F7PacketSize;
99  FlyCapture2::Format7Info m_F7Info;
100  bool m_bTxOn;
101 
102  unsigned int m_nNumCameras;
103  int m_nActiveCams;
104 
106 
108  bool m_bCameraOn;
109 
110  unsigned int m_XDim,m_YDim;
111 
112  unsigned int m_iMin[FlyCapture2::UNSPECIFIED_PROPERTY_TYPE],m_iMax[FlyCapture2::UNSPECIFIED_PROPERTY_TYPE];
113 
114  FlyCapture2::Image *m_pFrame,*m_pBayer;
115  std::mutex m_AcqMutex;
116  yarp::os::Stamp m_Stamp;
117 
118  int DC2Fly(int feature);
119 
120  inline unsigned int NormToValue(double& dVal,int feature);
121  inline double ValueToNorm(unsigned int iVal,int feature);
122 
123  int maxFPS(FlyCapture2::Mode mode,FlyCapture2::PixelFormat pixelFormat);
124  double bytesPerPixel(FlyCapture2::PixelFormat pixelFormat);
125 
126  bool manage(FlyCapture2::Error& error)
127  {
128  if (error.GetType()!=FlyCapture2::PGRERROR_OK)
129  {
130  yError("%s\n",error.GetDescription());
131  if (pToUnlock)
132  {
133  pToUnlock->post();
134  }
135  return true;
136  }
137 
138  return false;
139  }
140 
141  int checkInt(yarp::os::Searchable& config,const char* key)
142  {
143  if (config.check(key))
144  {
145  return config.find(key).asInt32();
146  }
147 
148  return 0;
149  }
150 
151  double checkDouble(yarp::os::Searchable& config,const char* key)
152  {
153  if (config.check(key))
154  {
155  return config.find(key).asFloat64();
156  }
157 
158  return -1.0;
159  }
160 
164 
165 public:
166 
168  // feature functions
170 
171  // 00
172  virtual bool hasFeatureDC1394(int feature);
173 
174  // 01
175  virtual bool setFeatureDC1394(int feature,double value);
176 
177  // 02
178  virtual double getFeatureDC1394(int feature);
179 
180  // 03
181  virtual bool hasOnOffDC1394(int feature);
182 
183  // 04
184  virtual bool setActiveDC1394(int feature, bool onoff);
185 
186  // 05
187  virtual bool getActiveDC1394(int feature);
188 
189  // 06
190  virtual bool hasManualDC1394(int feature);
191 
192  // 07
193  virtual bool hasAutoDC1394(int feature);
194 
195  // 08
196  virtual bool hasOnePushDC1394(int feature);
197 
198  // 09
199  virtual bool setModeDC1394(int feature, bool auto_onoff);
200 
201  // 10
202  virtual bool getModeDC1394(int feature);
203 
204  // 11
205  virtual bool setOnePushDC1394(int feature);
206 
207  // 23
208  virtual bool setWhiteBalanceDC1394(double b, double r);
209 
210  // 24
211  virtual bool getWhiteBalanceDC1394(double &b, double &r);
212 
214  // end features functions
216 
217  // 12
218  virtual unsigned int getVideoModeMaskDC1394();
219 
220  // 13
221  virtual bool setVideoModeDC1394(int video_mode);
222 
223  // 14
224  virtual unsigned int getVideoModeDC1394();
225 
226  // 15
227  virtual unsigned int getFPSMaskDC1394();
228 
229  // 16
230  virtual unsigned int getFPSDC1394();
231 
232  // 17
233  virtual bool setFPSDC1394(int fps);
234 
235  // 18
236  virtual unsigned int getISOSpeedDC1394();
237 
238  // 19
239  virtual bool setISOSpeedDC1394(int speed);
240 
241  // 20
242  virtual unsigned int getColorCodingMaskDC1394(unsigned int video_mode);
243  virtual unsigned int getActualColorCodingMaskDC1394();
244 
245  // 21
246  virtual unsigned int getColorCodingDC1394();
247 
248  // 22
249  virtual bool setColorCodingDC1394(int coding);
250 
251  // 25
252  virtual bool getFormat7MaxWindowDC1394(unsigned int &xdim,unsigned int &ydim,unsigned int &xstep,unsigned int &ystep,unsigned int &xoffstep,unsigned int &yoffstep);
253 
254  // 26
255  virtual bool setFormat7WindowDC1394(unsigned int xdim,unsigned int ydim,int x0,int y0);
256 
257  // 27
258  virtual bool getFormat7WindowDC1394(unsigned int &xdim,unsigned int &ydim,int &x0,int &y0);
259 
260  // 28
261  virtual bool setOperationModeDC1394(bool b1394b);
262 
263  // 29
264  virtual bool getOperationModeDC1394();
265 
266  // 30
267  virtual bool setTransmissionDC1394(bool bTxON);
268 
269  // 31
270  virtual bool getTransmissionDC1394();
271 
272  // 32 setBayer
273  // 33 getBayer
274 
275  // 34
276  virtual bool setBroadcastDC1394(bool onoff);
277 
278  // 35
279  virtual bool setDefaultsDC1394();
280 
281  // 36
282  virtual bool setResetDC1394();
283 
284  // 37
285  virtual bool setPowerDC1394(bool onoff);
286 
287  // 38
288  virtual bool setCaptureDC1394(bool bON);
289 
290  // 39
291  virtual unsigned int getBytesPerPacketDC1394();
292 
293  // 40
294  virtual bool setBytesPerPacketDC1394(unsigned int bpp);
295 
297  // base class implementation
299 
300  // SET
301 
302  virtual bool setBrightness(double v);
303  virtual bool setExposure(double v);
304  virtual bool setSharpness(double v);
305  virtual bool setWhiteBalance(double blue, double red);
306  virtual bool setHue(double v);
307  virtual bool setSaturation(double v);
308  virtual bool setGamma(double v);
309  virtual bool setShutter(double v);
310  virtual bool setGain(double v);
311  virtual bool setIris(double v);
312 
313  // GET
314 
315  virtual double getBrightness();
316  virtual double getExposure();
317  virtual double getSharpness();
318  virtual bool getWhiteBalance(double &blue, double &red);
319  virtual double getHue();
320  virtual double getSaturation();
321  virtual double getGamma();
322  virtual double getShutter();
323  virtual double getGain();
324  virtual double getIris();
325 };
326 
327 #endif
bool Capture(yarp::sig::ImageOf< yarp::sig::PixelRgb > *pImage, unsigned char *pBuffer=0, bool bRaw=false)
virtual unsigned int getBytesPerPacketDC1394()
bool CaptureRaw(unsigned char *pBuffer)
virtual bool setPowerDC1394(bool onoff)
virtual bool setWhiteBalance(double blue, double red)
virtual bool hasAutoDC1394(int feature)
virtual double getExposure()
virtual bool hasOnePushDC1394(int feature)
virtual bool getOperationModeDC1394()
FlyCapture2::Error error
virtual bool getTransmissionDC1394()
bool SetF7(int mode, int xdim, int ydim, int pixel_format, int speed, int x0, int y0)
virtual bool setSharpness(double v)
virtual unsigned int getColorCodingDC1394()
bool Capture(yarp::sig::ImageOf< yarp::sig::PixelMono > *pImage)
virtual bool setCaptureDC1394(bool bON)
bool SetVideoMode(dc1394video_mode_t videoMode)
uint32_t m_iMax[DC1394_FEATURE_NUM]
FlyCapture2::BusManager * m_pBusManager
virtual unsigned int getActualColorCodingMaskDC1394()
virtual double getFeatureDC1394(int feature)
virtual double getGamma()
double checkDouble(yarp::os::Searchable &config, const char *key)
virtual bool setHue(double v)
virtual bool setSaturation(double v)
virtual bool setOperationModeDC1394(bool b1394b)
virtual bool setActiveDC1394(int feature, bool onoff)
unsigned int NormToValue(double &dVal, int feature)
virtual void Close()
virtual bool setISOSpeedDC1394(int speed)
virtual bool getWhiteBalanceDC1394(double &b, double &r)
bool manage(FlyCapture2::Error &error)
virtual unsigned int getColorCodingMaskDC1394(unsigned int video_mode)
virtual bool setModeDC1394(int feature, bool auto_onoff)
virtual bool getFormat7WindowDC1394(unsigned int &xdim, unsigned int &ydim, int &x0, int &y0)
virtual unsigned int getFPSDC1394()
bool CaptureImage(yarp::sig::ImageOf< yarp::sig::PixelRgb > &image)
FlyCapture2::Format7ImageSettings m_F7ImageSettings
virtual double getGain()
virtual bool setExposure(double v)
virtual double getShutter()
double ValueToNorm(uint32_t iVal, int feature)
virtual bool setOnePushDC1394(int feature)
virtual bool setShutter(double v)
virtual bool hasOnOffDC1394(int feature)
virtual double getBrightness()
virtual bool setColorCodingDC1394(int coding)
FlyCapture2::Image * m_pBayer
virtual bool setIris(double v)
virtual bool setResetDC1394()
virtual unsigned int getISOSpeedDC1394()
FlyCapture2::Format7Info m_F7Info
virtual bool setFPSDC1394(int fps)
virtual unsigned int getVideoModeMaskDC1394()
virtual bool getFormat7MaxWindowDC1394(unsigned int &xdim, unsigned int &ydim, unsigned int &xstep, unsigned int &ystep, unsigned int &xoffstep, unsigned int &yoffstep)
FlyCapture2::CameraInfo m_CameraInfo
virtual bool setGain(double v)
virtual bool setFeatureDC1394(int feature, double value)
virtual bool getModeDC1394(int feature)
double bytesPerPixel(dc1394color_coding_t pixelFormat)
virtual bool hasManualDC1394(int feature)
uint32_t m_iMin[DC1394_FEATURE_NUM]
int checkInt(yarp::os::Searchable &config, const char *key)
virtual double getSaturation()
virtual bool setGamma(double v)
virtual double getIris()
virtual bool setWhiteBalanceDC1394(double b, double r)
dc1394video_frame_t * m_pFrame
bool CaptureRgb(unsigned char *pBuffer)
virtual bool setBytesPerPacketDC1394(unsigned int bpp)
virtual bool setFormat7WindowDC1394(unsigned int xdim, unsigned int ydim, int x0, int y0)
virtual unsigned int getVideoModeDC1394()
virtual unsigned int getFPSMaskDC1394()
FlyCapture2::Camera * m_pCamera
virtual bool setBroadcastDC1394(bool onoff)
FlyCapture2::FC2Config m_CamConfig
int maxFPS(dc1394video_mode_t mode, dc1394color_coding_t pixelFormat)
virtual double getSharpness()
virtual double getHue()
virtual bool getWhiteBalance(double &blue, double &red)
const yarp::os::Stamp & getLastInputStamp()
virtual bool setVideoModeDC1394(int video_mode)
virtual bool setDefaultsDC1394()
bool Create(yarp::os::Searchable &config)
virtual bool hasFeatureDC1394(int feature)
virtual bool setTransmissionDC1394(bool bTxON)
bool CaptureImage(yarp::sig::ImageOf< yarp::sig::PixelMono > &image)
virtual bool setBrightness(double v)
virtual bool getActiveDC1394(int feature)