latest version v1.9 - last update 10 Apr 2010 |
00001 /* 00002 * Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 00003 * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany 00004 * 00005 * This file is part of the LTI-Computer Vision Library (LTI-Lib) 00006 * 00007 * The LTI-Lib is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public License (LGPL) 00009 * as published by the Free Software Foundation; either version 2.1 of 00010 * the License, or (at your option) any later version. 00011 * 00012 * The LTI-Lib is distributed in the hope that it will be 00013 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty 00014 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with the LTI-Lib; see the file LICENSE. If 00019 * not, write to the Free Software Foundation, Inc., 59 Temple Place - 00020 * Suite 330, Boston, MA 02111-1307, USA. 00021 */ 00022 00023 00024 /*---------------------------------------------------------------- 00025 * project ....: LTI Digital Image/Signal Processing Library 00026 * file .......: ltiToUCam.h 00027 * authors ....: Pablo Alvarado 00028 * organization: LTI, RWTH Aachen 00029 * creation ...: 24.04.01 00030 * revisions ..: $Id: ltiToUCam.h,v 1.12 2007/04/03 02:15:13 alvarado Exp $ 00031 */ 00032 00033 #ifndef _LTI_TOUCAM_H_ 00034 #define _LTI_TOUCAM_H_ 00035 00036 #include "ltiFrameGrabber.h" 00037 00038 #ifdef _USE_PHILIPS_TOUCAM 00039 00040 #if __linux__ 00041 00042 #include <string> 00043 00044 #undef None 00045 00046 namespace lti { 00047 00048 /** 00049 * Philips USB ToUCam "frame grabber". 00050 * 00051 * This class allows capturing images from the USB camera ToUCam and 00052 * other compatible web-cams (see 00053 * <a href="http://www.saillard.org/linux/pwc/">here</a>). Even if 00054 * there is no physical frame-grabber, this class provides the 00055 * standard frameGrabber interface to simplify its use. 00056 * 00057 * At this time, only an implementation for Linux is provided. 00058 * 00059 * Don't forget to uncomment the line "#define _USE_PHILIPS_TOUCAM" 00060 * in the file ltiHardwareConfig.h before compiling, or at least 00061 * ensure that this symbol is defined. If you are using the LTI-Lib 00062 * Makefiles, you can also define that symbol in the 00063 * <code>ltilib/linux/extrapaths.mk</code> file. 00064 * 00065 * Please ensure that the file pwc-ioctl.h is in the standard include path. 00066 * This file is usually included in your Linux kernel sources 00067 * (/usr/src/linux/drivers/usb). 00068 * 00069 * This functor has been adapted to be used with the newest kernel modules 00070 * provided at http://www.saillard.org/linux/pwc/. Follow the instructions 00071 * there to install it. 00072 * 00073 * \warning When you install the module using module-assistant in any 00074 * Debian-based Linux, ensure that only the newest pwc.ko modules survives. 00075 * Otherwise you may get weird error messages due to the use of an obsolete 00076 * module in the standard kernel. 00077 * 00078 * You can also check the wiki page of the LTI-Lib for more information 00079 * (http://ltilib.pdoerfler.com/wiki/ToUCam). 00080 * 00081 */ 00082 class toUCam : public frameGrabber { 00083 public: 00084 /** 00085 * frameGrabber parameters class 00086 */ 00087 class parameters : public frameGrabber::parameters { 00088 public: 00089 /** 00090 * constructor to generate an invalid set of parameters (all values out 00091 * of range). 00092 * if valid is false, the parameter set will be invalid, otherwise 00093 * a default set will be generated. 00094 */ 00095 parameters(const bool valid=true); 00096 00097 /** 00098 * copy constructor 00099 */ 00100 parameters( const parameters& other ) 00101 : frameGrabber::parameters() { 00102 copy( other ); 00103 }; 00104 00105 /** 00106 * copy member 00107 */ 00108 parameters& copy( const parameters& other ); 00109 00110 /** 00111 * returns a pointer to a clone of the parameters. 00112 */ 00113 virtual functor::parameters* clone() const; 00114 00115 /** 00116 * returns the type name 00117 */ 00118 virtual const char* getTypeName() const; 00119 00120 /** 00121 * write the parameters in the given ioHandler 00122 * @param handler the ioHandler to be used 00123 * @param complete if true (the default) the enclosing begin/end will 00124 * be also written, otherwise only the data block will be written. 00125 * @return true if write was successful 00126 */ 00127 virtual bool write(ioHandler& handler,const bool complete=true) const; 00128 00129 /** 00130 * write the parameters in the given ioHandler 00131 * @param handler the ioHandler to be used 00132 * @param complete if true (the default) the enclosing begin/end will 00133 * be also written, otherwise only the data block will be written. 00134 * @return true if write was successful 00135 */ 00136 virtual bool read(ioHandler& handler,const bool complete=true); 00137 00138 # ifdef _LTI_MSC_6 00139 /** 00140 * this function is required by MSVC only, as a workaround for a 00141 * very awful bug, which exists since MSVC V.4.0, and still by 00142 * V.6.0 with all bugfixes (so called "service packs") remains 00143 * there... This method is also public due to another bug, so please 00144 * NEVER EVER call this method directly: use read() instead 00145 */ 00146 bool readMS(ioHandler& handler,const bool complete=true); 00147 00148 /** 00149 * this function is required by MSVC only, as a workaround for a 00150 * very awful bug, which exists since MSVC V.4.0, and still by 00151 * V.6.0 with all bugfixes (so called "service packs") remains 00152 * there... This method is also public due to another bug, so please 00153 * NEVER EVER call this method directly: use write() instead 00154 */ 00155 bool writeMS(ioHandler& handler,const bool complete=true) const; 00156 # endif 00157 00158 // ------------------------------------------------ 00159 // the parameters 00160 // ------------------------------------------------ 00161 00162 // If you add more parameters manually, do not forget to do following: 00163 // 1. indicate in the default constructor the default values 00164 // 2. make sure that the copy member also copy your new parameters 00165 // 3. make sure that the read and write members also read and 00166 // write your parameters 00167 00168 /** 00169 * the image size 00170 * 00171 * The following values are accepted by the camera: 128x96, 160x120, 00172 * 176x144, 320x240, 352x288 and 640x480. 00173 * 00174 * Default value: 320x240 00175 * 00176 * Following is an excerpt of the original driver pages: 00177 * 00178 * Resolution chart 00179 * 00180 * Below is a table that shows the possible resolutions and 00181 * framerates for the webcams. On the left, all possible 00182 * physical resolutions are listed; at the top, the various 00183 * framerates for the cameras. 00184 * 00185 * If a cell is blank, it means the combination of resolution 00186 * and framerate is not directly supported by the webcam. If an 00187 * unsupported image size is requested by a program, the first 00188 * smaller image size is selected and padded with a black or 00189 * gray border. 00190 * 00191 * A green cell means the combination is supported uncompressed; 00192 * a red cell indicates that combination is only available with 00193 * the decompressor module, <b>pwcx</b>. 00194 * \htmlonly 00195 <table border="1"> 00196 <tr> 00197 <th rowspan="2" valign="bottom">Size</th> 00198 <th colspan="8">PCA 645/646 & VC010</th> 00199 <th rowspan="8" width="15"> </td> 00200 <th colspan="6">PCVC 675/680/690</th> 00201 <th rowspan="8" width="15"> </th> 00202 <th colspan="6">PCVC 730/740</th> 00203 </tr> 00204 00205 <tr> 00206 <th width="30">3.75</th> 00207 <th width="30">5</th> 00208 <th width="30">7.5</th> 00209 <th width="30">10</th> 00210 <th width="30">12</th> 00211 <th width="30">15</th> 00212 <th width="30">20</th> 00213 <th width="30">24</th> 00214 <th width="30">5</th> 00215 <th width="30">10</th> 00216 <th width="30">15</th> 00217 <th width="30">20</th> 00218 <th width="30">25</th> 00219 <th width="30">30</th> 00220 <th width="30">5</th> 00221 <th width="30">10</th> 00222 <th width="30">15</th> 00223 <th width="30">20</th> 00224 <th width="30">25</th> 00225 <th width="30">30</th> 00226 </tr> 00227 <tr> 00228 <th>sQCIF<br>128x96</th> 00229 <td> </td> 00230 <td bgcolor="#00cc00"> </td> 00231 <td bgcolor="#00cc00"> </td> 00232 <td bgcolor="#00cc00"> </td> 00233 <td bgcolor="#00cc00"> </td> 00234 <td bgcolor="#00cc00"> </td> 00235 <td bgcolor="#00cc00"> </td> 00236 <td bgcolor="#00cc00"> </td> 00237 <td bgcolor="#00cc00"> </td> 00238 <td bgcolor="#00cc00"> </td> 00239 <td bgcolor="#00cc00"> </td> 00240 <td bgcolor="#00cc00"> </td> 00241 <td bgcolor="#00cc00"> </td> 00242 <td bgcolor="#00cc00"> </td> 00243 <td> </td> 00244 <td> </td> 00245 <td> </td> 00246 <td> </td> 00247 <td> </td> 00248 <td> </td> 00249 </tr> 00250 <tr> 00251 <th>QSIF<br>160x120</th> 00252 <td> </td> 00253 <td> </td> 00254 <td> </td> 00255 <td> </td> 00256 <td> </td> 00257 <td> </td> 00258 <td> </td> 00259 <td> </td> 00260 <td bgcolor="#00cc00"> </td> 00261 <td bgcolor="#00cc00"> </td> 00262 <td bgcolor="#00cc00"> </td> 00263 <td bgcolor="#00cc00"> </td> 00264 <td bgcolor="#00cc00"> </td> 00265 <td bgcolor="#00cc00"> </td> 00266 <td bgcolor="#00cc00"> </td> 00267 <td bgcolor="#00cc00"> </td> 00268 <td bgcolor="#00cc00"> </td> 00269 <td bgcolor="#00cc00"> </td> 00270 <td bgcolor="#00cc00"> </td> 00271 <td bgcolor="#00cc00"> </td> 00272 </tr> 00273 <tr> 00274 <th>QCIF<br>176x144</th> 00275 <td> </td> 00276 <td bgcolor="#00cc00"> </td> 00277 <td bgcolor="#00cc00"> </td> 00278 <td bgcolor="#00cc00"> </td> 00279 <td bgcolor="#00cc00"> </td> 00280 <td bgcolor="#00cc00"> </td> 00281 <td bgcolor="#00cc00"> </td> 00282 <td bgcolor="#00cc00"> </td> 00283 <td bgcolor="#00cc00"> </td> 00284 <td bgcolor="#00cc00"> </td> 00285 <td bgcolor="#00cc00"> </td> 00286 <td bgcolor="#00cc00"> </td> 00287 <td bgcolor="#00cc00"> </td> 00288 <td bgcolor="#cc0000"> </td> 00289 <td> </td> 00290 <td> </td> 00291 <td> </td> 00292 <td> </td> 00293 <td> </td> 00294 <td> </td> 00295 </tr> 00296 <tr> 00297 <th>SIF<br>320x240</th> 00298 <td> </td> 00299 <td> </td> 00300 <td> </td> 00301 <td> </td> 00302 <td> </td> 00303 <td> </td> 00304 <td> </td> 00305 <td> </td> 00306 <td bgcolor="#00cc00"> </td> 00307 <td bgcolor="#cc0000"> </td> 00308 <td bgcolor="#cc0000"> </td> 00309 <td bgcolor="#cc0000"> </td> 00310 <td bgcolor="#cc0000"> </td> 00311 <td bgcolor="#cc0000"> </td> 00312 <td bgcolor="#00cc00"> </td> 00313 <td bgcolor="#cc0000"> </td> 00314 <td bgcolor="#cc0000"> </td> 00315 <td bgcolor="#cc0000"> </td> 00316 <td bgcolor="#cc0000"> </td> 00317 <td bgcolor="#cc0000"> </td> 00318 </tr> 00319 <tr> 00320 <th>CIF<br>352x288</td> 00321 <td bgcolor="#00cc00"> </td> 00322 <td bgcolor="#00cc00"> </td> 00323 <td bgcolor="#00cc00"> </td> 00324 <td bgcolor="#00cc00"> </td> 00325 <td bgcolor="#00cc00"> </td> 00326 <td bgcolor="#00cc00"> </td> 00327 <td> </td> 00328 <td> </td> 00329 <td bgcolor="#00cc00"> </td> 00330 <td bgcolor="#cc0000"> </td> 00331 <td bgcolor="#cc0000"> </td> 00332 <td bgcolor="#cc0000"> </td> 00333 <td bgcolor="#cc0000"> </td> 00334 <td bgcolor="#cc0000"> </td> 00335 <td> </td> 00336 <td> </td> 00337 <td> </td> 00338 <td> </td> 00339 <td> </td> 00340 <td> </td> 00341 </tr> 00342 <tr> 00343 <th>VGA<br>640x480</td> 00344 <td> </td> 00345 <td> </td> 00346 <td> </td> 00347 <td> </td> 00348 <td> </td> 00349 <td> </td> 00350 <td> </td> 00351 <td> </td> 00352 <td bgcolor="#cc0000"> </td> 00353 <td bgcolor="#cc0000"> </td> 00354 <td bgcolor="#cc0000"> </td> 00355 <td> </td> 00356 <td> </td> 00357 <td> </td> 00358 <td bgcolor="#cc0000"> </td> 00359 <td bgcolor="#cc0000"> </td> 00360 <td bgcolor="#cc0000"> </td> 00361 <td> </td> 00362 <td> </td> 00363 <td> </td> 00364 </tr> 00365 </table> 00366 \endhtmlonly 00367 00368 * (Yes, VGA resolutions are limited to 15 fps: there isn't 00369 * enough bandwidth available on the USB bus to squeeze through 00370 * more, even with compression). 00371 * 00372 * The Philips driver now supports any image size between the 00373 * minimum and maximum size. For image sizes that are not an 00374 * 'integral' image size directly supported by the camera, the 00375 * image is now padded with a gray or black border, depending on 00376 * the palette. 00377 * 00378 * Note: the driver only pads the image; it selects a format 00379 * that is smaller or equal to the requested size; it does not 00380 * crop an image that is only a bit larger than the requested 00381 * current image. 00382 */ 00383 point size; 00384 00385 /** 00386 * image brightness (valid values between 0.0 and 1.0) 00387 * 00388 * Default value: 0.5 00389 */ 00390 float brightness; 00391 00392 /** 00393 * image hue (valid values between 0.0 and 1.0) 00394 * This value doesn't seem to be used by the ToUCams, but it 00395 * belongs to the V4L standard... 00396 * 00397 * Default value: 0.5 00398 */ 00399 float hue; 00400 00401 /** 00402 * image color saturation (valid values between 0.0 and 1.0) 00403 * 00404 * Default value: 0.5 00405 */ 00406 float saturation; 00407 00408 /** 00409 * image contrast (valid values between 0.0 and 1.0) 00410 * 00411 * Default value: 0.5 00412 */ 00413 float contrast; 00414 00415 /** 00416 * gamma correction (valid values between 0.0 and 1.0) 00417 * 00418 * Default value: 0.5 00419 */ 00420 float gamma; 00421 00422 /** 00423 * frame rate 00424 * This value shoud be between 0 and 60. 00425 * If 0 is given, the last frame rate will be used again. 00426 * Not all combination of frameRate and size are allowed. For more 00427 * details see parameters::size; 00428 * 00429 * Default value: 00430 */ 00431 int frameRate; 00432 00433 /** 00434 * snapshot mode 00435 * Default value: 00436 */ 00437 bool snapshotMode; 00438 00439 /** 00440 * the image compression rate 00441 */ 00442 enum eCompressionType { 00443 None = 0, /**< no compression will be used */ 00444 Low = 1, /**< low compression */ 00445 Medium = 2, /**< middle compression rate */ 00446 High = 3, /**< high compression */ 00447 Invalid = 4 /**< flag to denote invalid value */ 00448 00449 }; 00450 00451 /** 00452 * Set compression preference. 00453 * 00454 * The Philips webcams use losy compression techniques to get the 00455 * images across the (narrow) USB bus. With this parameter 00456 * you can specify if you like no compression, low, medium or 00457 * high compression. Higher compression means less bandwidth is 00458 * used, but it could introduce artefacts in the image. 00459 * 00460 * Default value: Medium 00461 */ 00462 eCompressionType compression; 00463 00464 /** 00465 * automatic gain control 00466 * 00467 * Default value: false 00468 */ 00469 bool agc; 00470 00471 /** 00472 * gain 00473 * valid values between 0.0 and 1.0 00474 * 00475 * Default value: 0.75 00476 */ 00477 float gain; 00478 00479 /** 00480 * automatic shutter speed 00481 * 00482 * Default value: false 00483 */ 00484 bool autoShutter; 00485 00486 /** 00487 * shutter speed. 00488 * Only used if autoShutter is false. 00489 * The value has no time units. It just means a long exposure time (1.0) 00490 * or a very short exposure time (0.0). 00491 * 00492 * Default value: 0.75 00493 */ 00494 float shutterSpeed; 00495 00496 /** 00497 * white balance mode 00498 */ 00499 enum eWhiteBalanceType { 00500 InvalidWB = -1, /**< Invalid value */ 00501 Indoor = 0, /**< Indoor lighting */ 00502 Outdoor = 1, /**< Outdoor lighting */ 00503 Fluorescent = 2, /**< Fluorescent lighting */ 00504 Manual = 3, /**< Manual mode. You need this mode to adjust the 00505 blue and red gains */ 00506 Auto = 4 /**< Automatic White Balance */ 00507 }; 00508 00509 /** 00510 * white balance 00511 * 00512 * Default value: Outdoor 00513 */ 00514 eWhiteBalanceType whiteBalance; 00515 00516 /** 00517 * Red gain. 00518 * 00519 * To see the effect of this gain factor you need to set the white 00520 * balance mode into "Manual". 00521 * 00522 * Valid values between 0.0 and 1.0 00523 * 00524 * Default value: 0.5 00525 */ 00526 float redGain; 00527 00528 /** 00529 * Blue gain 00530 * 00531 * Valid values between 0.0 and 1.0 00532 * 00533 * To see the effect of this gain factor you need to set the white 00534 * balance mode into "Manual". 00535 * 00536 * Default value: 0.5 00537 */ 00538 float blueGain; 00539 00540 /** 00541 * LED 00542 * 00543 * Specify a value of zero or negative for an "off LED" and a value of 00544 * exactly 1 for a LED always on. 00545 * 00546 * Otherwise, the led "on" time will be computed as "led%65536" and 00547 * the led "off" time as "led/65536". Both times will have a resolution 00548 * of 100ms and accept a maximum value of 25000. 00549 * 00550 * Default value: 1 (led on). 00551 */ 00552 int led; 00553 00554 /** 00555 * This string denotes the name of the device used. For Linux it 00556 * could be for example /dev/video or /dev/video0. There is a special 00557 * constructor that allows you to give this value directly. 00558 * 00559 * Default value: for Linux: /dev/video 00560 * for Windows: not implemented yet. 00561 */ 00562 std::string device; 00563 }; 00564 00565 /** 00566 * default constructor 00567 */ 00568 toUCam(const bool initialize=true); 00569 00570 /** 00571 * Constructor with initialization for the given device 00572 */ 00573 toUCam(const std::string& device,const bool initialize=true); 00574 00575 /** 00576 * copy constructor 00577 */ 00578 toUCam(const toUCam& other); 00579 00580 /** 00581 * constructor, sets the parameters 00582 */ 00583 toUCam(const parameters& theParam); 00584 00585 /** 00586 * destructor 00587 */ 00588 virtual ~toUCam( void ); 00589 00590 /** 00591 * returns current parameters. 00592 */ 00593 const parameters& getParameters() const; 00594 00595 /** 00596 * setParameters overload to allow changing the camera attributes 00597 */ 00598 virtual bool setParameters(const functor::parameters& theParam); 00599 00600 /** 00601 * returns the name of this type 00602 */ 00603 virtual const char* getTypeName() const; 00604 00605 /** 00606 * load an (color) image from the camera 00607 */ 00608 bool apply(image& theImage); 00609 00610 /** 00611 * load a grey value channel from the camera 00612 */ 00613 bool apply(channel8& theChannel); 00614 00615 /** 00616 * copy member 00617 */ 00618 toUCam& copy(const toUCam& other); 00619 00620 /** 00621 * clone member 00622 */ 00623 functor* clone() const; 00624 00625 /** 00626 * check if the frame grabber has been initialized 00627 */ 00628 bool isInitialized() const; 00629 00630 /** 00631 * initialize frame grabber 00632 */ 00633 bool init(); 00634 00635 protected: 00636 /** 00637 * the actual capture size for the images 00638 */ 00639 point size; 00640 00641 /** 00642 * When the camera is initialized, this value is set to the 00643 * minimum available image size 00644 */ 00645 point minSize; 00646 00647 /** 00648 * When the camera is initialized, this value is set to the 00649 * maximum available image size 00650 */ 00651 point maxSize; 00652 00653 /** 00654 * flag indicates if the camera interface has been initialized 00655 */ 00656 bool initialized; 00657 00658 /** 00659 * name of the camera being used 00660 */ 00661 std::string camName; 00662 00663 /** 00664 * the camera file handle. 00665 * this is valid only if <code>initialized</code> is true 00666 */ 00667 int cameraHndl; 00668 00669 /** 00670 * type to specify which kind of images (gray or color) 00671 * was grabbed the last time 00672 */ 00673 enum eLastGrabbedType { 00674 NotUsedYet, /**< no grabbing yet */ 00675 Gray, /**< gray channel grabbed */ 00676 Color /**< color channel grabbed */ 00677 }; 00678 00679 /** 00680 * last grabbed type 00681 */ 00682 eLastGrabbedType lastGrabbed; 00683 00684 /** 00685 * set the camera parameters 00686 */ 00687 bool setCameraParameters(); 00688 00689 /** 00690 * last used parameter values (used to check if a value needs to be 00691 * changed). These are needed to spare some time sending the new 00692 * parameters to the camera 00693 */ 00694 parameters lastUsedParams; 00695 00696 /** 00697 * look up table to accelerate computation of saturation 00698 */ 00699 static const ubyte* lutSaturation; 00700 00701 /** 00702 * look up tables to accelerate conversion Luv -> RGB 00703 */ 00704 //@{ 00705 static const int* lutUg; 00706 static const int* lutUb; 00707 static const int* lutVg; 00708 static const int* lutVr; 00709 //@} 00710 00711 /** 00712 * initialize the Look-Up-Tables 00713 */ 00714 void initializeLUTs(); 00715 }; 00716 } 00717 #endif // __linux__ 00718 #endif // _USE_PHILIPS_TOUCAM 00719 #endif // #ifdef _LTI_TOUCAM_H_