Visual Servoing Platform  version 3.3.0 under development (2020-02-17)
vp1394CMUGrabber.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 based on CMU 1394 Digital Camera SDK.
33  *
34  * Authors:
35  * Lucas Lopes Lemos FEMTO-ST, AS2M departement, Besancon
36  * Guillaume Laurent FEMTO-ST, AS2M departement, Besancon
37  * Fabien Spindler
38  *
39  *****************************************************************************/
40 
41 #ifndef vp1394CMUGrabber_h
42 #define vp1394CMUGrabber_h
43 
44 #include <visp3/core/vpConfig.h>
45 
46 #ifdef VISP_HAVE_CMU1394
47 
48 // Include WinSock2.h before windows.h to ensure that winsock.h is not
49 // included by windows.h since winsock.h and winsock2.h are incompatible
50 #include <1394Camera.h> // CMU library
51 #include <WinSock2.h>
52 #include <windows.h>
53 
54 #include <visp3/core/vpFrameGrabber.h>
55 #include <visp3/core/vpFrameGrabberException.h>
56 #include <visp3/core/vpImage.h>
57 #include <visp3/core/vpRGBa.h>
58 
151 class VISP_EXPORT vp1394CMUGrabber : public vpFrameGrabber
152 {
153 public:
157  typedef enum { YUV444, YUV422, YUV411, RGB8, MONO8, MONO16, UNKNOWN } vpColorCodingType;
158 
159 private:
161  C1394Camera *camera;
163  int index;
165  unsigned long _format;
167  unsigned long _mode;
169  unsigned long _fps;
171  bool _modeauto;
173  unsigned short _gain;
175  unsigned short _shutter;
177  vpColorCodingType _color;
178 
179 public:
180  // Constructor.
182  // Destructor.
183  virtual ~vp1394CMUGrabber();
184 
185  // Acquire one frame in a greyscale image.
187 
188  // Acquire one frame in a color image.
189  void acquire(vpImage<vpRGBa> &I);
190 
191  // Stop the acquisition.
192  void close();
193 
194  // Display information about the camera on the standard output.
195  void displayCameraDescription(int cam_id);
196 
197  // Display camera model on the standard output. Call it after open the
198  // grabber.
199  void displayCameraModel();
200 
201  // Get the video framerate
202  int getFramerate();
203 
204  // Get the gain min and max values.
205  void getGainMinMax(unsigned short &min, unsigned short &max);
206 
207  // Get the number of connected cameras.
208  int getNumberOfConnectedCameras() const;
209 
210  // Get the shutter min and max values.
211  void getShutterMinMax(unsigned short &min, unsigned short &max);
212 
214  vpColorCodingType getVideoColorCoding() const
215  {
216  vpColorCodingType color = vp1394CMUGrabber::UNKNOWN;
217  if (_format == 0) {
218  switch (_mode) {
219  case 0:
220  color = vp1394CMUGrabber::YUV444;
221  break;
222  case 1:
223  color = vp1394CMUGrabber::YUV422;
224  break;
225  case 2:
226  color = vp1394CMUGrabber::YUV411;
227  break;
228  case 3:
229  color = vp1394CMUGrabber::YUV422;
230  break;
231  case 4:
232  color = vp1394CMUGrabber::RGB8;
233  break;
234  case 5:
235  color = vp1394CMUGrabber::MONO8;
236  break;
237  case 6:
238  color = vp1394CMUGrabber::MONO16;
239  break;
240  }
241  } else if (_format == 1) {
242  switch (_mode) {
243  case 0:
244  color = vp1394CMUGrabber::YUV422;
245  break;
246  case 1:
247  color = vp1394CMUGrabber::RGB8;
248  break;
249  case 2:
250  color = vp1394CMUGrabber::MONO8;
251  break;
252  case 3:
253  color = vp1394CMUGrabber::YUV422;
254  break;
255  case 4:
256  color = vp1394CMUGrabber::RGB8;
257  break;
258  case 5:
259  color = vp1394CMUGrabber::MONO8;
260  break;
261  case 6:
262  color = vp1394CMUGrabber::MONO16;
263  break;
264  case 7:
265  color = vp1394CMUGrabber::MONO16;
266  break;
267  }
268  } else if (_format == 2) {
269  switch (_mode) {
270  case 0:
271  color = vp1394CMUGrabber::YUV422;
272  break;
273  case 1:
274  color = vp1394CMUGrabber::RGB8;
275  break;
276  case 2:
277  color = vp1394CMUGrabber::MONO8;
278  break;
279  case 3:
280  color = vp1394CMUGrabber::YUV422;
281  break;
282  case 4:
283  color = vp1394CMUGrabber::RGB8;
284  break;
285  case 5:
286  color = vp1394CMUGrabber::MONO8;
287  break;
288  case 6:
289  color = vp1394CMUGrabber::MONO16;
290  break;
291  case 7:
292  color = vp1394CMUGrabber::MONO16;
293  break;
294  }
295  }
296 
297  return color;
298  }
299 
300  // Initialization of the grabber using a greyscale image.
301  void open(vpImage<unsigned char> &I);
302 
303  // Initialization of the grabber using a color image.
304  void open(vpImage<vpRGBa> &I);
305 
307  vp1394CMUGrabber &operator>>(vpImage<vpRGBa> &I);
308 
309  // Select the camera on the bus. Call it before open the grabber.
310  void selectCamera(int cam_id);
311 
312  // Enable auto gain
313  void setAutoGain();
314 
315  // Enable auto shutter
316  void setAutoShutter();
317 
318  // Set the gain and the shutter values. Call it before open the grabber
319  void setControl(unsigned short gain, unsigned short shutter);
320 
321  // Set the frame rate. Call it before open the grabber.
322  void setFramerate(unsigned long fps);
323 
324  // Set the shutter value. Call it before open the grabber
325  void setShutter(unsigned short shutter);
326 
327  // Set the gain value. Call it before open the grabber
328  void setGain(unsigned short gain);
329 
330  // Set the video format and mode. Call it before open the grabber.
331  void setVideoMode(unsigned long format, unsigned long mode);
332 
333 private:
334  void initCamera();
335 };
336 
337 #endif
338 #endif
virtual void open(vpImage< unsigned char > &I)=0
Firewire cameras video capture based on CMU 1394 Digital Camera SDK.
vpColorCodingType getVideoColorCoding() const
Get the video color coding format.
Base class for all video devices. It is designed to provide a front end to video sources.
virtual void close()=0
virtual void acquire(vpImage< unsigned char > &I)=0