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 59 /*! 60 \file vp1394CMUGrabber.h 61 \brief Firewire cameras video capture based on CMU 1394 Digital Camera SDK. 62 */ 63 64 /*! 65 \class vp1394CMUGrabber 66 67 \ingroup group_sensor_camera 68 69 \brief Firewire cameras video capture based on CMU 1394 Digital Camera SDK. 70 71 Thus to be enabled, this class needs the optional CMU 1394 3rd party. 72 Installation instruction are provided here https://visp.inria.fr/3rd_cmu1394. 73 74 This block is based on the CMU 1394 Digital Camera SDK. The CMU 1394 75 Digital Camera Driver must be installed (go to 76 http://www.cs.cmu.edu/~iwan/1394/index.html to download it). 77 - Parameters: 78 - Camera index (0, 1, 2, ... or 10). First camera has index 0. 79 - Image format 80 - Frame rate. Real frame rate depends on device capacities. 81 - Control : shutter speed and gain can be internally set, but it is 82 possible to set manually them. 83 * Exposure time register value. Real exposure time depends on device 84 capacities. 85 * Gain register value. Real gain depends on device capacities. 86 87 This first example available in tutorial-grabber-CMU1394.cpp shows how to 88 grab and display images from a firewire camera under Windows. 89 90 \include tutorial-grabber-CMU1394.cpp 91 92 This other example shows how to consider more than one firewire camera, and 93 how to grab and display images from the first camera found on the bus. 94 95 \code 96 #include <iostream> 97 98 #include <visp3/core/vpImage.h> 99 #include <visp3/gui/vpDisplayOpenCV.h> 100 #include <visp3/sensor/vp1394CMUGrabber.h> 101 102 int main() 103 { 104 #if defined(VISP_HAVE_CMU1394) 105 std::cout << "ViSP Image acquisition example" << std::endl; 106 107 vpImage<unsigned char> I; 108 vp1394CMUGrabber g; 109 110 if( g.getNumberOfConnectedCameras() > 1 ) 111 std::cout << "There are " << g.getNumberOfConnectedCameras() << " connected cameras." << std::endl; 112 if( g.getNumberOfConnectedCameras() == 1 ) 113 std::cout << "There is " << g.getNumberOfConnectedCameras() << " connected camera." << std::endl; 114 else 115 std::cout << "There is no connected camera." << std::endl; 116 117 // Setting camera parameters manually 118 g.selectCamera(0); 119 g.setGain(0); 120 g.setShutter(2000); 121 g.setFramerate(3); // 15 FPS 122 g.setVideoMode(0, 5); // 640x480 - MONO 123 124 g.acquire(I); 125 126 // Display camera description 127 g.displayCameraDescription(0); 128 g.displayCameraModel(); 129 std::cout << "Height: " << g.getHeight() << " Width: " << g.getWidth() << std::endl; 130 131 vpDisplayOpenCV d(I); 132 vpDisplay::display(I); 133 134 for(;;) 135 { 136 g.acquire(I); 137 vpDisplay::display(I); 138 vpDisplay::flush(I); 139 if (vpDisplay::getClick(I, false)) // a click to exit 140 break; 141 } 142 143 g.close(); 144 #endif 145 std::cout << "ViSP exiting..." <<std::endl; 146 return 0; 147 } 148 \endcode 149 */ 150 151 class VISP_EXPORT vp1394CMUGrabber : public vpFrameGrabber 152 { 153 public: 154 /*! 155 Enumeration of color codings. 156 */ 157 typedef enum { YUV444, YUV422, YUV411, RGB8, MONO8, MONO16, UNKNOWN } vpColorCodingType; 158 159 private: 160 //! Current camera handle 161 C1394Camera *camera; 162 //! Camera index on the bus 163 int index; 164 //! Current video format 165 unsigned long _format; 166 //! Current video mode 167 unsigned long _mode; 168 //! Current video frame rate 169 unsigned long _fps; 170 //! Current auto mode 171 bool _modeauto; 172 //! Current gain 173 unsigned short _gain; 174 //! Current shutter 175 unsigned short _shutter; 176 //! Color coding 177 vpColorCodingType _color; 178 179 public: 180 // Constructor. 181 vp1394CMUGrabber(); 182 // Destructor. 183 virtual ~vp1394CMUGrabber(); 184 185 // Acquire one frame in a greyscale image. 186 void acquire(vpImage<unsigned char> &I); 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 213 //! Get the video color coding format. getVideoColorCoding()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 306 vp1394CMUGrabber &operator>>(vpImage<unsigned char> &I); 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 339