LTI-Lib latest version v1.9 - last update 10 Apr 2010

ltiLeutronFrameGrabber.h

00001 /*
00002  * Copyright (C) 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-Lib: Image Processing and Computer Vision Library
00026  * file .......: ltiLeutronFrameGrabber.h
00027  * authors ....: Claudia Goenner
00028  * organization: LTI, RWTH Aachen
00029  * creation ...: 02.01.2003
00030  * revisions ..: $Id: ltiLeutronFrameGrabber.h,v 1.8 2007/01/10 02:26:12 alvarado Exp $
00031  */
00032 
00033 #ifndef _LTI_LEUTRON_FRAME_GRABBER_H_
00034 #define _LTI_LEUTRON_FRAME_GRABBER_H_
00035 
00036 #include "ltiHardwareConfig.h"
00037 #ifdef _USE_LEUTRON_GRABBER
00038 
00039 #include "ltiFrameGrabber.h"
00040 #include "ltiImage.h"
00041 #include "lvutil.h"
00042 #include "lvdef.h"
00043 #include "dsylib.h"
00044 #include "grabber.h"
00045 
00046 namespace lti {
00047 
00048   /**
00049    * Interface to all Leutron framegrabbers in the system. If more than one
00050    * framegrabber is installed, they will be considered all. If framegrabber
00051    * specific settings like monochrome VS. color or the number targets on the
00052    * boards vary, the minimal common set is supported. In particular if a
00053    * monochrome framegrabber is installed together with color framegrabbers
00054    * all images acquired will be monochrome.
00055    *
00056    * This implementation is rather slow because the camera is frozen while
00057    * grabbing and woke up afterwards, which takes about 15 ms. For a faster
00058    * access use the leutronMultiPlexFrameGrabber, which is not public yet.
00059    *
00060    * For some strange reason the hardware path via the high performance
00061    * scaler (HPS) is faster than via the binary ratio scaler (BRS).
00062    *
00063    * This class is not thread safe. If used as a singleton, thread safety 
00064    * should be added. It also should be tested that all initialization,
00065    * camera connection and camera activation methods are only called once.
00066    *
00067    * CAVEATS:
00068    * 1) This class is only tested with a PicPortColor framegrabber.
00069    *
00070    * BUGS:
00071    * 1) If two targets are enabled only the BRS path produces a useful image.
00072    */
00073   class leutronFrameGrabber : public frameGrabber {
00074   public:
00075     /**
00076      * the parameters for the class leutronFrameGrabber
00077      */
00078     class parameters : public frameGrabber::parameters {
00079     public:
00080       /**
00081        * default constructor
00082        */
00083       parameters();
00084 
00085       /**
00086        * copy constructor
00087        * @param other the parameters object to be copied
00088        */
00089       parameters(const parameters& other);
00090 
00091       /**
00092        * destructor
00093        */
00094       ~parameters();
00095 
00096       /**
00097        * returns name of this type
00098        */
00099       const char* getTypeName() const;
00100 
00101       /**
00102        * copy the contents of a parameters object
00103        * @param other the parameters object to be copied
00104        * @return a reference to this parameters object
00105        */
00106       parameters& copy(const parameters& other);
00107    
00108       /**
00109        * copy the contents of a parameters object
00110        * @param other the parameters object to be copied
00111        * @return a reference to this parameters object
00112        */
00113       parameters& operator=(const parameters& other);
00114 
00115 
00116       /**
00117        * returns a pointer to a clone of the parameters
00118        */
00119       virtual functor::parameters* clone() const;
00120 
00121       /**
00122        * write the parameters in the given ioHandler
00123        * @param handler the ioHandler to be used
00124        * @param complete if true (the default) the enclosing begin/end will
00125        *        be also written, otherwise only the data block will be written.
00126        * @return true if write was successful
00127        */
00128       virtual bool write(ioHandler& handler,const bool complete=true) const;
00129 
00130       /**
00131        * read the parameters from the given ioHandler
00132        * @param handler the ioHandler to be used
00133        * @param complete if true (the default) the enclosing begin/end will
00134        *        be also written, otherwise only the data block will be written.
00135        * @return true if write was successful
00136        */
00137       virtual bool read(ioHandler& handler,const bool complete=true);
00138 
00139 #     ifdef _LTI_WIN32 
00140       /**
00141        * this function is required by MSVC only, as a workaround for a
00142        * very awful bug, which exists since MSVC V.4.0, and still by
00143        * V.6.0 with all bugfixes (so called "service packs") remains
00144        * there...  This method is also public due to another bug, so please
00145        * NEVER EVER call this method directly: use read() instead
00146        */
00147       bool readMS(ioHandler& handler,const bool complete=true);
00148 
00149       /**
00150        * this function is required by MSVC only, as a workaround for a
00151        * very awful bug, which exists since MSVC V.4.0, and still by
00152        * V.6.0 with all bugfixes (so called "service packs") remains
00153        * there...  This method is also public due to another bug, so please
00154        * NEVER EVER call this method directly: use write() instead
00155        */
00156       bool writeMS(ioHandler& handler,const bool complete=true) const;
00157 #     endif
00158 
00159       // ------------------------------------------------
00160       // the parameters
00161       // ------------------------------------------------
00162 
00163       /**
00164        * The target currently selected (HPS 0, BPS 1, ...). Some
00165        * framegrabbers like the picport color support two targets, others
00166        * may have even more targets. If several framegrabbers are installed
00167        * in the system, the number of targets is limited by the smallest
00168        * number of targets supported by one of the grabbers. Actually a more
00169        * sophisticated implementation would not need this implementation,
00170        * unless multi plexing.
00171        *
00172        * The framegrabbers supports two paths: high performance scaling (HPS)
00173        * or binary ratio scaling (BRS). On the BRS path only YUV and grey
00174        * formats are possible.
00175        * If RGB color is choosen it will be set to YUV on the BRS path. 
00176        * Specifying a targetIndex turns on the according field in the parameter target.
00177        * Default: 0.
00178        */
00179       int targetIndex;
00180 
00181       /**
00182        * A camera name known to daisy. It must be specified in lvcamera.dat.
00183        * For Robocup roboter use "PAL_S_CCIR" (full mode) or
00184        * "PAL_S_CCIR_Halbbild_50" (half mode). For Victoria use
00185        * "Leutron_LV2000CE" (full mode) or
00186        * "PAL_S_CCIR_HalbbildLV2000_50" (half mode).
00187        * All cameras must be of the same type. Default: PAL_S_CCIR
00188        */
00189       std::string camera;
00190 
00191       /**
00192        * The camera currently selected. The hardware supports connection
00193        * of 4 cameras.
00194        * Default: 0 (first camera).
00195        */
00196       int cameraIndex;
00197 
00198       /**
00199        * The scale factor of the image acquired by the HPS path. The maximum
00200        * image size
00201        * of the camera is detected by the framegrabber. Default: (1,1).
00202        */
00203       tpoint<float> scaleFactorHPS;
00204 
00205       /**
00206        * If true the framegrabber will auto detect the cameras. Otherwise 
00207        * the grabber will check whether the camera name given in camera is
00208        * supported and take those settings. This overrides the camera string.
00209        * Default: true.
00210        */
00211       bool autoDetectCamera;
00212 
00213       /**
00214        * The scale factor of the image acquired by the BRS path. The maximum
00215        * image size of the camera is detected by the framegrabber.
00216        * Default: (1,1).
00217        */
00218       point scaleFactorBRS;
00219 
00220       enum eWaitSyncType {Field1, Field2, Frame, VertSync, None};
00221       /**
00222        * The type synchronization with the camera: no synchronization, with
00223        * start of field 0, with start of field 1, with start of frame or with
00224        * vertical sync puls. The default is no synchronization.
00225        * Default: None.
00226        */
00227       eWaitSyncType waitSync;
00228 
00229       /**
00230        * Offset in grabbed image. Default value is 0. Negative values are not
00231        * allowed. The values refer to the original image size of the camera.
00232        * Default: (0,0)
00233        */
00234       point offset;
00235 
00236       /**
00237        * Scale (true) or Clip (false) the grabbed image to specified
00238        * dimensions. In half image mode, which has higher priority, only
00239        * scaling is supported. The image mode is specified implicitly by
00240        * the camera. Default: true.
00241        */
00242       bool scale;
00243 
00244       /**
00245        * Specifies which targets will grabbed by apply(vector<..> ..). For
00246        * details on the targets see the description of targetIndex.
00247        * Default: grap HPS-target only.
00248        */
00249       bool target[4];
00250 
00251       enum eColorType {RGBa, YUV, Grey};
00252       /**
00253        * Grab a RGB-alpha color image, YUV or 8-bit grey. Default: RGBa.
00254        */
00255       eColorType color;
00256 
00257     };
00258 
00259     /**
00260      * the optocouplers that can be set
00261      */
00262     enum eOptocouplerType {Deactivate, OPTO_0, OPTO_1, OPTO_2, OPTO_3, OPTO_4,
00263          OPTO_5, OPTO_6, OPTO_7, OPTO_8, OPTO_9, OPTO_10,
00264          OPTO_11, OPTO_12, OPTO_13, OPTO_14, OPTO_15,
00265          OPTO_16, OPTO_17, OPTO_18, OPTO_19, OPTO_20, 
00266          OPTO_21, OPTO_22, OPTO_23, OPTO_24, OPTO_25,
00267          OPTO_26, OPTO_27, OPTO_28, OPTO_29, OPTO_30, 
00268          OPTO_31};
00269 
00270     /**
00271      * default constructor
00272      */
00273     leutronFrameGrabber();
00274 
00275     /**
00276      * Construct a functor using the given parameters
00277      * @param par the parameters to be used
00278      */
00279     leutronFrameGrabber(const parameters& par);
00280 
00281     /**
00282      * copy constructor
00283      * @param other the object to be copied
00284      */
00285     leutronFrameGrabber(const leutronFrameGrabber& other);
00286 
00287     /**
00288      * destructor
00289      */
00290     virtual ~leutronFrameGrabber();
00291 
00292     /**
00293      * returns the name of this type ("leutronFrameGrabber")
00294      */
00295     virtual const char* getTypeName() const;
00296 
00297     /**
00298      * Grabs a grey image.
00299      * operates on the given %parameter.
00300      * @param srcdest where the grabbed channel8 will be left
00301      * @return true if apply successful or false otherwise.
00302      */
00303     virtual bool apply(channel8& srcdest);
00304 
00305     /**
00306      * Grabs an image from the current camera. 
00307      * operates on the given %parameter.
00308      * @param srcdest where the grabbed image will be left
00309      * @return true if apply successful or false otherwise.
00310      */
00311     virtual bool apply(image& srcdest);
00312 
00313     /**
00314      * Grabs an image split in 3 separate channels. This useful if the
00315      * application distinguishes between chromacity (Y) and color
00316      * information (U,V).
00317      * @param band1 where the grabbed Y band will be left
00318      * @param band2 where the grabbed Y band will be left
00319      * @param band3 where the grabbed Y band will be left
00320      * @return true if apply successful or false otherwise.
00321      */
00322     virtual bool apply(channel8& band1, channel8& band2, channel8& band3);
00323 
00324     /**
00325      * Sets one optocoupler or deactivates all optocouplers of the grabber that
00326      * has been accessed last. ToDo: think of method where you can tell the
00327      * grabber on which the optocoupler shall be set.
00328      * @param theOpto the optocoupler to be set
00329      * @return true on success or false otherwise.
00330      */
00331     bool setOptocoupler(eOptocouplerType theOpto);    
00332 
00333     /**
00334      * Sets or deactivates the optocouplers of the grabber that has been
00335      * accessed last. ToDo: think of method where you can tell the
00336      * grabber on which the optocouplers shall be set.
00337      * @param theOptos the optocouplers to be set
00338      * @return true on success or false otherwise.
00339      */
00340     bool setOptocoupler(const std::vector<eOptocouplerType>& theOptos);
00341 
00342     /**
00343      * copy data of "other" functor.
00344      * @param other the functor to be copied
00345      * @return a reference to this functor object
00346      */
00347     leutronFrameGrabber& copy(const leutronFrameGrabber& other);
00348 
00349     /**
00350      * alias for copy member
00351      * @param other the functor to be copied
00352      * @return a reference to this functor object
00353      */
00354     leutronFrameGrabber& operator=(const leutronFrameGrabber& other);
00355 
00356     /**
00357      * returns a pointer to a clone of this functor.
00358      */
00359     virtual functor* clone() const;
00360 
00361     /**
00362      * returns used parameters
00363      */
00364     const leutronFrameGrabber::parameters& getParameters() const;
00365 
00366     /**
00367      * Set the paramters. Adjusts non supported values internally.
00368      * @param theParams the parameters to be set
00369      * @return true if the parameters could be set and processed by the
00370      *              hardware or false otherwise
00371      */
00372     bool setParameters(const leutronFrameGrabber::parameters &theParams);
00373     
00374     /**
00375      * Initializes and opens the framegrabber. It is not necessary to call
00376      * this method.
00377      * @return true on success or false otherwise
00378      */
00379     virtual bool init();
00380 
00381     /**
00382      * Switches the current camera. On switch, the camera has to be activated
00383      * which is time consuming.
00384      * @param cameraIndex the index of the camera from which will be grabbed
00385      * @return true on success or false otherwise
00386      */
00387     virtual bool setCamera(int cameraIndex);
00388 
00389     /**
00390      * Switches the target, from which is grabbed. If the target buffer is
00391      * not already connected to the camera(s) this is time consuming. This
00392      * method affects the parameters targetIndex and target[].
00393      * @param targetIndex the index of the target will be grabbed
00394      * @return true on success or false otherwise
00395      */
00396     virtual bool setTarget(int targetIndex);
00397 
00398     /**
00399      * Get the number of connected cameras
00400      * @return the number of connected cameras
00401      */
00402     virtual int getNumberOfConnectedCameras();
00403 
00404 protected:
00405     /**
00406      * returns used parameters
00407      */
00408     leutronFrameGrabber::parameters& getWritableParameters();
00409 
00410     /**
00411      * check parameters
00412      * @param theParams the parameters to be checked
00413      * @return true on success or false otherwise
00414      */
00415     virtual bool 
00416       checkParameters(const leutronFrameGrabber::parameters &theParams);
00417 
00418     /**
00419      * put a camera in live mode and start the acquisition
00420      * @return true on success or false otherwise
00421      */
00422     virtual bool startAquisition() const;
00423 
00424     /**
00425      * put a camera in freeze mode and stop the acquisition
00426      * @return true on success or false otherwise
00427      */
00428     virtual bool stopAquisition() const;
00429 
00430     /**
00431      * Detect and connect all cameras
00432      * @return true on success or false otherwise
00433      */
00434     virtual bool detectCameras();
00435 
00436     /**
00437      * Activate the current camera
00438      * @return true on success or false otherwise
00439      */
00440     virtual bool activateCameras();
00441 
00442 
00443     /**
00444      * Get the leutron error and write it into the status string
00445      * @param status the leutron status
00446      * @param error the prefix of the concatenated status string
00447      * @return true on success or false otherwise
00448      */
00449     virtual bool setDsyErrorInStatusString(STATUS& status, const char* error);
00450 
00451     /**
00452      * Initialize the roi from where the data is copied into a lti object
00453      * @param roi the leutron region of interest object
00454      * @return true on success or false otherwise
00455      */
00456     virtual bool initRoi(LvROI& roi);
00457 
00458     //pointers to the current grabber
00459     static LvGrabberNode *m_pGrabber;       
00460     //stores the grabber handle of each camera 
00461     static HGRABBER *m_pGrabberHandle;
00462     //stores the connector of each camera
00463     static HCONNECTOR *m_pConnectorHandle;  
00464 
00465     static int m_numConnectedCameras;
00466     static int m_numTargets;
00467     //will be used when monochrome grabbers will be supported
00468     static bool m_greyOnly;
00469     static int m_instanceCount;
00470 
00471     static U16BIT m_masterCameraType;   //camera on master grabber
00472     static U16BIT m_slaveCameraType;    //camera on slave grabber
00473     
00474     static int m_srcWidth;   //width  in the srcInfo
00475     static int m_srcHeight;  //height in the srcInfo
00476 
00477     static bool m_connect;
00478     static bool m_activate;
00479     static bool m_otherCamera;
00480     static bool m_turnaround;
00481     static U8BIT m_tgt[4];
00482    
00483     //ToDo:   Do I need a static copy of the parameters ???
00484     //Answer: At least which are important for the internal status,
00485     //        i.e. hardware settings !!!
00486     //        But this can wait until semaphores are added and a singleton
00487     //        for testing exists
00488  
00489   private:
00490     /**
00491      * set mirror mode
00492      */
00493     virtual bool turnaround();
00494   };
00495 }
00496 
00497 #endif //USE_LEUTRON_GRABBER
00498 
00499 #endif

Generated on Sat Apr 10 15:25:43 2010 for LTI-Lib by Doxygen 1.6.1