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