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

Tekkotsu v2.1
Generated Tue Mar 16 23:19:12 2004 by Doxygen 1.3.5