Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

BlobData.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef _BLOBDATA_H_
00003 #define _BLOBDATA_H_
00004 
00005 #include <vector>
00006 #include <set>
00007 #include <map>
00008 #include <iostream>
00009 #include <string>
00010 
00011 #include "Shared/fmatSpatial.h"
00012 
00013 #include "BaseData.h"      // superclass
00014 #include "Point.h"         // Point data member
00015 #include "SketchTypes.h"   // uchar
00016 #include "ShapeTypes.h"    // blobDataType
00017 #include "ShapeFuns.h"
00018 
00019 namespace CMVision {
00020   typedef unsigned char uchar;
00021   template<typename T> class run;
00022   struct region;
00023 }
00024 
00025 namespace DualCoding {
00026 
00027 class ShapeRoot;
00028 template<typename T> class Sketch;
00029 
00030 //! Blob shapes, described by bounding boxes and an optional list of runs.
00031 
00032 class BlobData : public BaseData {
00033  public:
00034 
00035   //! Assumed orientation of the blob in 3D space.
00036   enum BlobOrientation_t {
00037     groundplane,  //!< 2D shape lying flat on the ground
00038     pillar,       //!< 3D shape standing on the ground
00039     poster        //!< 3D shape hanging vertically in space
00040   };
00041 
00042   struct run {
00043   public:
00044     unsigned short int x, y, width;
00045     run() : x(0), y(0), width(0) {}
00046     run(unsigned short int _x, unsigned short int _y, unsigned short int _width) :
00047       x(_x), y(_y), width(_width) {}
00048   };
00049 
00050   // Data members
00051 
00052   bool topValid, bottomValid, leftValid, rightValid;
00053 
00054   BlobOrientation_t orientation; //!< Orientation of the blob
00055   coordinate_t assumedHeight; //!< Assumed height above ground of blob centroid (for poster) or top (for pillar)
00056   //! Bounding quadrilateral: may not be square when projected to ground space.
00057   Point topLeft, topRight, bottomLeft, bottomRight;
00058   float area; //!< Area of the blob; may not be integer when projected to ground space
00059   const std::vector<run> runvec; //!< Runs (for rendering in camera space)
00060 
00061  public:
00062   //! Constructor
00063   BlobData(ShapeSpace& _space,
00064      const Point &_topLeft, const Point &_topRight,
00065      const Point &_bottomLeft, const Point &_bottomRight,
00066      const float _area=0,
00067      const std::vector<run> &_runvec=std::vector<run>(), 
00068      const BlobOrientation_t _orientation=groundplane,
00069      const coordinate_t assumedHeight=0,
00070      const rgb rgbvalue=rgb(),
00071      bool _topValid=false, bool _bottomValid=false, bool _leftValid=false, bool _rightValid=false);
00072 
00073   static ShapeType_t getStaticType() { return blobDataType; }
00074 
00075   DATASTUFF_H(BlobData);
00076 
00077   friend class Shape<BlobData>;
00078 
00079   //! return the centroid of the shape in point format
00080   virtual Point getCentroid() const;
00081   
00082   //! Area of the blob
00083   float getArea() const { return area; }
00084 
00085   //! Print information about this shape.
00086   virtual void printParams() const;
00087 
00088   //! Transformations. (Virtual in BaseData.)
00089   virtual void applyTransform(const fmat::Transform& Tmat, const ReferenceFrameType_t newref=unspecified);
00090   
00091   //! Project to ground
00092 
00093   //  virtual void projectToGround(int xres, int yres, const NEWMAT::ColumnVector& groundplane);
00094   virtual void projectToGround(const fmat::Transform& camToBase,
00095              const PlaneEquation& gndplane);
00096 
00097   //! Update derived properties
00098   virtual void update_derived_properties();
00099 
00100   //! returns the bounding box of the blob
00101   BoundingBox2D getBoundingBox() const;
00102 
00103   //! Match blobs based on their parameters.  (Virtual in BaseData.)
00104   virtual bool isMatchFor(const ShapeRoot& other) const;
00105 
00106   virtual bool updateParams(const ShapeRoot& other, bool forceUpdate=false);
00107 
00108   virtual unsigned short getDimension() const { return (orientation==groundplane) ? 2 : 3; }
00109 
00110 
00111   //! Import blobs from Sketch<bool> as a vector of Shape<BlobData>
00112   static std::vector<Shape<BlobData> > 
00113   extractBlobs(const Sketch<bool> &sketch,
00114          int minarea=25,
00115          BlobOrientation_t orient=BlobData::groundplane, 
00116          coordinate_t height=0,
00117          int maxblobs=50); 
00118 
00119   //! Import blobs of all colors from Sketch<uchar> as a vector of Shape<BlobData>
00120   static std::vector<Shape<BlobData> >
00121   extractBlobs(const Sketch<uchar> &sketch,
00122          int minarea=25,
00123          BlobOrientation_t orient=BlobData::groundplane,
00124          const coordinate_t height=0,
00125          int maxblobs=50);
00126 
00127   //! Import blobs of specified colors from Sketch<uchar> as a vector of Shape<BlobData>
00128   static std::vector<Shape<BlobData> >
00129   extractBlobs(const Sketch<uchar> &sketch, 
00130          const std::set<color_index>& colors,
00131          const std::map<color_index,int>& minareas,
00132          const std::map<color_index,BlobOrientation_t>& orients,
00133          const std::map<color_index,coordinate_t>& heights,
00134          int maxblobs);
00135 
00136   //! Utility function for making a new blob instance from CMVision's region data structures
00137   static BlobData* new_blob(ShapeSpace& space,
00138      const CMVision::region &reg, 
00139      const CMVision::run<CMVision::uchar> *rle_buff,
00140      const BlobOrientation_t orient,
00141      const coordinate_t height,
00142      const rgb rgbvalue);
00143 
00144   //!@name Corner extraction for rectangular blobs
00145   //@{
00146   std::vector<Point> findCorners(unsigned int nExpected, std::vector<Point>& candidates, float &bestValue);
00147   std::vector<Point> findCornersDerivative();
00148   std::vector<Point> findCornersDiagonal();
00149   std::vector<Point> findCornersShapeFit(unsigned int ncorners, std::vector<Point>& candidates, float &bestValue);
00150   //@}
00151 
00152  // comparison predicates
00153 
00154   class AreaLessThan : public BinaryShapePred<BlobData> {
00155   public:
00156     bool operator() (const Shape<BlobData> &b1, const Shape<BlobData> &b2) const;
00157   };
00158 
00159 private:
00160   //! Render into a sketch space and return reference. (Private.)
00161   virtual Sketch<bool>* render() const;
00162 
00163   BlobData& operator=(const BlobData&); //!< don't call
00164 
00165 };
00166 
00167 } // namespace
00168 
00169 #endif // BLOBDATA_H_

DualCoding 5.1CVS
Generated Mon May 9 04:56:25 2016 by Doxygen 1.6.3