gml_FingerFinderPlus.h

00001 // gml_FingerFinderPlus.h --
00002 //
00003 //    Define the gml_TFingerFinderPlus class.
00004 //
00005 //  Copyright (c) 2003-2004 CLIPS-IMAG
00006 //
00007 //  See the file "gml_LicenseTerms.txt" for information on usage and redistribution
00008 //  of this file, and for a DISCLAIMER OF ALL WARRANTIES.
00009 //
00010 //  Created in April 2003 (JL).
00011 //  Revamped in February 2004 (JL).
00012 
00013 #ifndef __GML_FINGER_FINDER_PLUS__
00014 #define __GML_FINGER_FINDER_PLUS__
00015 
00016 #include "gml/base/gml_Errors.h"
00017 #include "gml/base/gml_Types.h"
00018 #include "gml/image/gml_Geometry.h"
00019 #include "gml/image/gml_Bitmap.h"
00020 #include "gml/vision/gml_Connexer.h"
00021 
00022 
00023 ////////////////////////////////////////////////////////////////////////////////
00024 //                                                                            //
00025 //                         gml_TFinger class declaration                      //
00026 //                                                                            //
00027 ////////////////////////////////////////////////////////////////////////////////
00028 
00029 ///
00030 /// Represent fingers found in images
00031 ///
00032 struct gml_TFinger
00033 {
00034   gml_TPoint fCenter;        ///< position of the fingertip center (pixels)
00035   int index;            /// hand's index
00036   gml_TPointFloat fOrientation;   ///< vector giving the finger orientation (pixels)
00037   Float32         fRadius;        ///< fingertip radius (pixels)
00038 } ;
00039 
00040 ////////////////////////////////////////////////////////////////////////////////
00041 //                                                                            //
00042 //                     gml_TFingerFinderPlus class declaration                    //
00043 //                                                                            //
00044 ////////////////////////////////////////////////////////////////////////////////
00045 
00046 
00047 /// A complex scanner that processes a segmentation map (scalar image) and
00048 /// detects fingertip-shaped regions.
00049 ///
00050 /// @warning
00051 /// the data members are made public so the <finger_finder> scanner can
00052 /// access them; they are *not* to be modified by client code !
00053 
00054 class gml_TFingerFinderPlus
00055 {
00056 public:
00057 
00058   ///
00059   /// Init --
00060   ///   Setup the data structures.
00061   ///
00062   gml_TError Init ();
00063   
00064   ///
00065   /// Dispose --
00066   ///   Release the data structures.
00067   ///
00068   void Dispose ();
00069   
00070   ///
00071   /// Setup --
00072   ///   Setup the data structures for a given view scale.
00073   /// If the <reqViewScale> hasn't changed the data structures no
00074   /// allocation or computation will occur.
00075   ///
00076   gml_TError Setup (
00077     Float64 reqViewScale            ///< requested view scale (meters/pixel)
00078   );
00079   
00080   ///
00081   /// Process --
00082   ///   Process the <source> bitmap and place in <fingers> the detected fingertips.
00083   ///
00084   gml_TError Process (
00085     gml_TBitmap* source,            ///< [in]    source bitmap (binary image)
00086     gml_TRect*   sourceRect,        ///< [in]    source region of interest
00087     gml_TBoolean flagRejectMap,     ///< [in]    if true, <source> will be overwritten with a rejection map
00088     UInt32       reqTipFillFactor,  ///< [in]    minimal density around a fingertip
00089     UInt16      &nbFingers,         ///< [inout] input: maximum number of fingers (size of the <finger> array);
00090                                     ///<         output: actual number of detected fingers
00091     gml_TFinger* fingers            ///< [out]   detected fingertips
00092   );
00093 
00094   ///
00095   /// Dump --
00096   ///   Write the fields' value to stdout.
00097   ///
00098   void Dump ();
00099   
00100 public:
00101   // 
00102   // Defaults and constants
00103   //
00104 
00105   /// fingers are between 9 and 20 millimiters wide
00106   static Float64 sMinFingerRadius  () { return 4.5e-3;  }    ///< meters
00107   //static Float64 sMinFingerRadius  () { return 4.8e-3;  }    ///< meters
00108   static Float64 sMaxFingerRadius  () { return 10.0e-3; }    ///< meters
00109   //static Float64 sMaxFingerRadius  () { return 14.4e-3; }    ///< meters
00110 
00111   /// default view ratio
00112   //static Float64 sDefaultViewScale () { return 2.0e-3;  }    ///< meters / pixel
00113   static Float64 sDefaultViewScale () { return 1.8e-3;  }    ///< meters / pixel  
00114   /// default required fill factor for fingertip regions
00115   static UInt8 sDefaultTipFillFactor () { return 90;    }    ///< percentage
00116 
00117 public:
00118   //
00119   // Private fields
00120   //
00121     
00122   Float64 fViewScale;           ///< the view ratio, expressed in meters / pixel
00123   UInt32  fTipFillFactor;       ///< the required fill factor of fingertips, percentage
00124 
00125   UInt32  fMinFingerRadius;     ///< the minimum finger radius, pixels
00126   UInt32  fMaxFingerRadius;     ///< the maximum finger radius, pixels
00127   int maxHandArea;
00128   
00129   SInt32  fDiskDiameter;        ///< pixels
00130   UInt8  *fDiskMask;            ///< as given by gml_Bresenham_DiskMask
00131   UInt32  fDiskArea;            ///< disk area
00132 
00133   SInt32  fCircleDiameter;      ///< pixels
00134   UInt32  fCircleNbPoints;      ///< number of contour points
00135   gml_TPoint *fCirclePointList; ///< list of relative contour points as given by gml_Bresenham_CirclePoints
00136   UInt32 *fPointsBuffer;        ///< temporary storage for contour points
00137   
00138   UInt32  fMinContourPoints;    ///< minimum number of contour pixels for a valid finger
00139   UInt32  fMaxContourPoints;    ///< maximum number of contour pixels for a valid finger
00140 
00141 protected:  
00142   gml_TConnexer *fConnexer;     ///< analyzer used to pre- and post-process the bitmap
00143   gml_TBitmap   *fFingerMap;    ///< output of the finger-finding scanner
00144   gml_TBitmap *fConnexerMap;  ///<outpout of the fconnexer, step 1
00145   
00146 protected:
00147   //
00148   // Protected utility methods
00149   //
00150   
00151   /// Allocate <fFingerMap> as a G_8 bitmap the same size as <source> (if necessary)
00152   /// and zero it
00153   gml_TError AllocateAndZeroMap (gml_TBitmap *source);
00154 
00155 } ;
00156 
00157 
00158   
00159 
00160 #endif /* __GML_FINGER_FINDER_PLUS__ */
00161 
Generated on Tue Jun 12 14:03:28 2007 for gml by Doxygen 1.5.2.