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