Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

VisionObjectEvent.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_VisionObjectEvent_h
00003 #define INCLUDED_VisionObjectEvent_h
00004 
00005 #include "EventBase.h"
00006 
00007 //! Extends EventBase to also include location in the visual field and distance (though distance is not implimented yet)
00008 class VisionObjectEvent : public EventBase {
00009 public:
00010   //! Constructor, pass a source id and type id -- mainly useful for deactivate events since all object parameters are going to be set to 0
00011   /*! @param sid The source ID for the object being detected -- you can define your own values, some are already set in ProjectInterface, but can be reassigned during your project's startup
00012    *  @param tid The type ID for the event
00013    */
00014   explicit VisionObjectEvent(size_t sid=0,EventTypeID_t tid=EventBase::deactivateETID)
00015     : EventBase(EventBase::visObjEGID,sid,tid,0),
00016       _x1(0),_x2(0),_y1(0),_y2(0), _area(0),
00017       _clipLeft(false), _clipRight(false), _clipTop(false), _clipBottom(false),
00018       _xRange(0), _yRange(0), _frame(0)
00019   {}
00020     
00021   //! Constructor, pass the type id, source id, left, right, top, bottom, x range, and y range
00022   /*! @param sid The source ID for the object being detected -- you can define your own values, some are already set in ProjectInterface, but can be reassigned during your project's startup
00023    *  @param tid The type ID for the event
00024    *  @param x1 The leftmost extent of the object, in generalized coordinates (see #_x1)
00025    *  @param x2 The rightmost extent of the object in generalized coordinates (see #_x2)
00026    *  @param y1 The topmost extent of the object, in generalized coordinates (see #_y1)
00027    *  @param y2 The bottommost extent of the object, in generalized coordinates (see #_y2)
00028    *  @param objarea The area of the object being detected, in squared generalized coordinates (see #_area)
00029    *  @param rx The plus/minus range of the x coordinates (generally xres/xres for cameras which are wider than they are high)
00030    *  @param ry The plus/minus range of the y coordinates (camera yres/xres for cameras which are wider than they are high)
00031    */
00032   VisionObjectEvent(size_t sid, EventTypeID_t tid, float x1, float x2, float y1, float y2,float objarea, float rx, float ry)
00033     : EventBase(EventBase::visObjEGID,sid,tid,0),
00034       _x1(x1),_x2(x2),_y1(y1),_y2(y2), _area(objarea),
00035       _clipLeft(_x1<=-rx), _clipRight(_x2>=rx), _clipTop(_y1<=-ry), _clipBottom(_y2>=ry),
00036       _xRange(rx), _yRange(ry), _frame(0)
00037   {}
00038   
00039   //! Constructor, pass the type id, source id, left, right, top, bottom, x range, y range, and frame_number
00040   /*! @param sid The source ID for the object being detected -- you can define your own values, some are already set in ProjectInterface, but can be reassigned during your project's startup
00041    *  @param tid The type ID for the event
00042    *  @param x1 The leftmost extent of the object, in generalized coordinates (see #_x1)
00043    *  @param x2 The rightmost extent of the object in generalized coordinates (see #_x2)
00044    *  @param y1 The topmost extent of the object, in generalized coordinates (see #_y1)
00045    *  @param y2 The bottommost extent of the object, in generalized coordinates (see #_y2)
00046    *  @param objarea The area of the object being detected, in squared generalized coordinates (see #_area)
00047    *  @param rx The plus/minus range of the x coordinates (generally xres/xres for cameras which are wider than they are high)
00048    *  @param ry The plus/minus range of the y coordinates (camera yres/xres for cameras which are wider than they are high)
00049    *  @param frame The camera frame number the object was detected in (see #_frame)
00050    */
00051   VisionObjectEvent(size_t sid, EventTypeID_t tid, float x1, float x2, float y1, float y2, float objarea, float rx, float ry,unsigned int frame)
00052     : EventBase(EventBase::visObjEGID,sid,tid,0),
00053       _x1(x1),_x2(x2),_y1(y1),_y2(y2), _area(objarea),
00054       _clipLeft(_x1<=-rx), _clipRight(_x2>=rx), _clipTop(_y1<=-ry), _clipBottom(_y2>=ry),
00055       _xRange(rx),_yRange(ry), _frame(frame)
00056   {} 
00057   
00058   //! destructor
00059   virtual ~VisionObjectEvent() {}
00060   
00061   virtual EventBase* clone() const { return new VisionObjectEvent(*this); }
00062 
00063   virtual unsigned int getClassTypeID() const { return autoRegisterVisionObjectEvent; }
00064 
00065   //!@name Attribute Accessors
00066   float getLeft() const { return _x1;} //!< returns the initial x (#_x1) coordinate of the Bounding Box (inclusive value)
00067   VisionObjectEvent& setLeft(float x1) { _x1=x1; return *this;} //!< sets the initial x (#_x1) coordinate of the Bounding Box
00068   
00069   float getRight() const { return _x2;} //!< returns the final x (#_x2) coordinate of the Bounding Box (inclusive value)
00070   VisionObjectEvent& setRight(float x2) { _x2=x2; return *this;} //!< sets the final x (#_x2) coordinate of the Bounding Box
00071   
00072   float getTop() const { return _y1;} //!< returns the initial y (#_y1) coordinate of the Bounding Box (inclusive value)
00073   VisionObjectEvent& setTop(float y1) { _y1=y1; return *this;} //!< sets the initial y (#_y1) coordinate of the Bounding Box
00074   
00075   float getBottom() const { return _y2;} //!< returns the final y (#_y2) coordinate of the Bounding Box (inclusive value)
00076   VisionObjectEvent& setBottom(float y2) { _y2=y2; return *this;} //!< sets the final y (#_y2) coordinate of the Bounding Box
00077   
00078   float getObjectArea() const { return _area; } //!< returns the object's #_area within the camera, in squared generalized coordinates.  Multiply by the square of the major camera resolution (normally RobotInfo::CameraResolutionX if using full resolution) and divide by 4.0 to get pixel area.
00079   VisionObjectEvent& setObjectArea(float objarea) { _area=objarea; return *this; } //!< sets the object's #_area within the camera, in squared generalized coordinates (multiply by the major camera resolution to get pixel area)
00080   //@}
00081  
00082   //!@name Calculated Attributes
00083   float getDistanceEstimate(float diaMajor, float diaMinor=0) const; //!< returns an estimate of how far away the object is if its major (larger) physical dimension is @a diaMajor and the other dimension is @a diaMinor; pass 0 if to only use the major dimension
00084   static float calcDistance(float visArc, float physDia); //!< returns the distance of an object, given that it takes up @a visArc of the camera's visual arc, and the physical crossection is @a physDia
00085   float getCenterX() const { return (_x1+_x2)/2; } //!< returns the center along x
00086   float getCenterY() const { return (_y1+_y2)/2; } //!< returns the center along y
00087   float getWidth() const { return _x2-_x1; } //!< return width along x
00088   float getHeight() const { return _y2-_y1; } //!< return height along y
00089   float getBoundaryArea() const { return (_x2-_x1)*(_y2-_y1); } //!< returns the area of the bounding box, just multiplication of width*height, (multiply by the major camera resolution to get pixel area)
00090   float getXrange() const{ return  _xRange;}//!< returns the maximum x value
00091   float getYrange() const{return _yRange;}//!< returns the maximum y value
00092   unsigned int getFrame() const{return _frame;}//!< returns number of frame when the event was generated
00093   //@}
00094 
00095   //!@name Object out of bounds Detection Functions
00096   bool isClipped() const { return isClippedLeft() || isClippedRight() || isClippedTop() || isClippedBottom(); }
00097   bool isClippedLeft() const { return _clipLeft; } //!< returns #_clipLeft
00098   bool isClippedRight() const { return _clipRight; }  //!< returns #_clipRight
00099   bool isClippedTop() const { return _clipTop; } //!< returns #_clipTop
00100   bool isClippedBottom() const {return _clipBottom; } //!< returns #_clipBottom
00101   void setClipping(bool left, bool right, bool top, bool bottom) { _clipLeft=left; _clipRight=right; _clipTop=top; _clipBottom=bottom; } //!< sets clipping boundaries
00102   //@}
00103       
00104   virtual std::string getDescription(bool showTypeSpecific=true, unsigned int verbosity=0) const;
00105   
00106   virtual unsigned int getBinSize() const;
00107   virtual unsigned int loadBinaryBuffer(const char buf[], unsigned int len);
00108   virtual unsigned int saveBinaryBuffer(char buf[], unsigned int len) const;
00109   virtual void loadXML(xmlNode* node);
00110   virtual void saveXML(xmlNode * node) const;
00111 
00112 protected:
00113   float _x1;  //!< a value representing location in visual field - from -1 if on the left edge to 1 if it's on the right edge, see Config::vision_config::x_range
00114   float _x2;  //!< a value representing location in visual field - from -1 if on the left edge to 1 if it's on the right edge, see Config::vision_config::x_range
00115   float _y1;  //!< top boundary, in range of ±1/Config::vision_config::aspectRatio, see Config::vision_config::y_range
00116   float _y2;  //!< bottom boundary, in range of ±1/Config::vision_config::aspectRatio, see Config::vision_config::y_range
00117   float _area; //!< area of the actual object within bounding box as set by generator, in same units as getBoundaryArea().  Multiply by the square of the major camera resolution (normally RobotInfo::CameraResolutionX if using full resolution) and divide by 4.0 to get pixel area.
00118   bool _clipLeft;   //!< flag to indicate left boundary is on or beyond the camera image's boundary
00119   bool _clipRight;  //!< flag to indicate right boundary is on or beyond the camera image's boundary
00120   bool _clipTop;    //!< flag to indicate top boundary is on or beyond the camera image's boundary
00121   bool _clipBottom; //!< flag to indicate bottom boundary is on or beyond the camera image's boundary
00122   float _xRange; //!< Max range of X dimension (typically 1.0 for AIBO)
00123   float _yRange; //!< Max range of Y dimension (typically around 0.8 for AIBO due to camera aspect ratio)
00124   unsigned int _frame; //!< Number of frame when the event was generated.
00125   
00126   //! causes class type id to automatically be regsitered with EventBase's FamilyFactory (getTypeRegistry())
00127   static const EventBase::classTypeID_t autoRegisterVisionObjectEvent;
00128 };
00129 
00130 /*! @file
00131  * @brief Describes VisionObjectEvent, which provides information about objects recognized in the camera image
00132  * @author alokl (Creator)
00133  * @author Ignacio Herrero Reder &lt; nhr at dte uma es &gt; (VisionObjectInfo Boundary Box - bug 74, frame number - bug 143)
00134  */
00135 
00136 #endif

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:52 2016 by Doxygen 1.6.3