Homepage Demos Overview Downloads Tutorials Reference
Credits

BallDetectionGenerator.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_BallDetectionGenerator_h_
00003 #define INCLUDED_BallDetectionGenerator_h_
00004 
00005 #include "Events/EventGeneratorBase.h"
00006 
00007 class FilterBankEvent;
00008 
00009 //! Uses segmented color region information to detect round objects
00010 /*! This expects its events to come from a BallDetectionGenerator (or
00011  *  its subclass)
00012  *  
00013  *  Sends an event only for the largest ball found.
00014  *
00015  */
00016 class BallDetectionGenerator : public EventGeneratorBase {
00017 public:
00018   //! constructor
00019   BallDetectionGenerator(EventBase::EventGeneratorID_t gid, unsigned int sid, unsigned int mysid, unsigned int colorIdx, unsigned int threshmapChan, unsigned int noiseFiltering, float confidence);
00020 
00021   static std::string getClassDescription() { return "Detects round-ish regions"; }
00022 
00023   //! see class notes above for what data this can handle
00024   virtual void processEvent(const EventBase& event);
00025 
00026 protected:
00027   typedef unsigned char uchar; //!< shorthand
00028 
00029   //!@name Edge masks
00030   static const uchar OFF_EDGE_LEFT   = 1<<1; //!< bitmask for calcEdgeMask results
00031   static const uchar OFF_EDGE_RIGHT  = 1<<2;
00032   static const uchar OFF_EDGE_TOP    = 1<<3;
00033   static const uchar OFF_EDGE_BOTTOM = 1<<4;
00034   //@}
00035 
00036   static const unsigned int NUM_CHECK = 10; //!< the number of regions to check (from largest to smallest)
00037 
00038   //! High level vision ouput structure for detected objects
00039   struct VObject {
00040     double confidence; //!< [0,1] Estimate of certainty
00041     //vector3d loc;      //!< Relative to front of robot (on ground)
00042     //double left,right; //!< Angle to left and right of object (egocentric)
00043     //double distance;   //!< Distance of object (on ground)
00044     //uchar edge;        //!< Is object on edge of image (bitmasks above)
00045   };
00046 
00047   //! decides wether to actually send the event based on confidence threshold.
00048   void testSendEvent(const FilterBankEvent& ev, float conf, int regcenX, int regcenY);
00049   //! does the actual event sending
00050   void createEvent(EventBase::EventTypeID_t etid, float centerX, float centerY) const;
00051   //! returns a bit mask corresponding to edges touched by the coordinates passed
00052   static int calcEdgeMask(int x1,int x2,int y1,int y2, int width, int height);
00053   //! returns @f[ \left|\frac{a-b}{a+b}\right| @f]
00054   inline static float pct_from_mean(float a,float b) {
00055     float s = (a - b) / (a + b);
00056     return fabs(s);
00057   }
00058 
00059   unsigned int clrIdx;  //!< the index of the color of the ball we're looking for
00060   unsigned int tmIdx;   //!< the index of the theshold map (channel) of the FilterBankEvent
00061   VObject ball;         //!< information about the best ball found
00062   bool present;         //!< if true, we think we have a ball in front of us
00063   unsigned int count;   //!< for each frame where we don't agree with present's value, this is incremented and compared against noiseFilter.
00064   unsigned int noiseThreshold; //!< the number of frames to wait to make sure an object has dissappeared/reappeared 
00065   float confidenceThreshold; //!< how sure we should be it's a ball before declaring it as such.
00066   
00067 private:
00068   BallDetectionGenerator(const BallDetectionGenerator& fbk); //!< don't call
00069   const BallDetectionGenerator& operator=(const BallDetectionGenerator& fbk); //!< don't call
00070 };
00071 
00072 /*! @file 
00073  * @brief Describes BallDetectionGenerator, which uses segmented color region information to detect round objects
00074  * @author alokl (Creator)
00075  * @author ejt (reorganized)
00076  *
00077  * History is old, may have grown from CMPack (CMU Robosoccer) roots?
00078  * I think if there's any of their code left, it's probably *mostly*
00079  * the commented out stuff I (ejt) left for posterity when
00080  * reorganizing.  But alokl didn't flag this as CMPack's prior to
00081  * inital release, and they didn't request credit for it when they
00082  * reviewed the code, so I guess it's all ours...
00083  *
00084  * $Author: ejt $
00085  * $Name: tekkotsu-2_0 $
00086  * $Revision: 1.3 $
00087  * $State: Exp $
00088  * $Date: 2004/01/18 10:16:58 $
00089  */
00090 
00091 #endif

Tekkotsu v2.0
Generated Wed Jan 21 03:20:27 2004 by Doxygen 1.3.4