Homepage Demos Overview Downloads Tutorials 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 <iostream>
00008 #include <string>
00009 
00010 #include "Shared/newmat/newmat.h"
00011 #include "Vision/cmv_types.h"
00012 
00013 #include "BaseData.h"      // superclass
00014 #include "Point.h"          // Point data member
00015 #include "ShapeTypes.h"   // blobDataType
00016 #include "ShapeFuns.h"
00017 
00018 namespace DualCoding {
00019 
00020 class ShapeRoot;
00021 template<typename T> class Sketch;
00022 
00023 //! Blob shapes, described by bounding boxes and an optional list of runs.
00024 
00025 class BlobData : public BaseData {
00026  public:
00027 
00028   // Bounding quadrilateral; may not be square when projected to world space.
00029   Point topLeft, topRight, bottomLeft, bottomRight;
00030 
00031   float area;
00032 
00033   struct run {
00034   public:
00035     unsigned short int x, y, width;
00036     run() : x(0), y(0), width(0) {}
00037     run(unsigned short int _x, unsigned short int _y, unsigned short int _width) :
00038       x(_x), y(_y), width(_width) {}
00039   };
00040 
00041   const std::vector<run> runvec;
00042 
00043   //! Assumed orientation of the blob in 3D space.
00044   enum BlobOrientation_t {
00045     groundplane,  //!< 2D shape lying flat on the ground
00046     pillar,       //!< 3D shape standing on the ground
00047     pinata       //!< 3D shape hanging vertically in space
00048   } orientation;
00049 
00050  public:
00051   //! Constructor
00052   BlobData(ShapeSpace& _space,
00053      const Point &_topLeft, const Point &_topRight,
00054      const Point &_bottomLeft, const Point &_bottomRight,
00055      const float _area, 
00056      const std::vector<run> &_runvec, 
00057      const BlobOrientation_t _orientation,
00058      const rgb rgbvalue);
00059 
00060   static ShapeType_t getStaticType() { return blobDataType; }
00061 
00062   DATASTUFF_H(BlobData);
00063 
00064   friend class Shape<BlobData>;
00065 
00066   //! return the centroid of the shape in point format
00067   virtual Point getCentroid() const;
00068   
00069   //! Area of the blob
00070   float getArea() { return area; }
00071 
00072   //! Print information about this shape.
00073   virtual void printParams() const;
00074 
00075   //! Transformations. (Virtual in BaseData.)
00076   virtual void applyTransform(const NEWMAT::Matrix& Tmat);
00077   
00078   //! Project to ground
00079   //  virtual void projectToGround(int xres, int yres, const NEWMAT::ColumnVector& groundplane);
00080   virtual void projectToGround(const NEWMAT::Matrix& camToBase,
00081              const NEWMAT::ColumnVector& groundplane);
00082 
00083   //! Update derived properties
00084   virtual void update_derived_properties();
00085 
00086   //! Match blobs based on their parameters.  (Virtual in BaseData.)
00087   virtual bool isMatchFor(const ShapeRoot& other) const;
00088 
00089   virtual bool updateParams(const ShapeRoot& other, bool forceUpdate=false);
00090 
00091   virtual unsigned short getDimension() const { return (orientation==groundplane) ? 2 : 3; }
00092 
00093 
00094   //! Import blobs from Sketch<bool> as a vector of Shape<BlobData>
00095   static std::vector<Shape<BlobData> > 
00096   extractBlobs(const Sketch<bool> &sketch, 
00097          const set<int>& colors, int minarea=0,
00098          BlobData::BlobOrientation_t orient=BlobData::groundplane, 
00099          int maxblobs=50);
00100   static std::vector<Shape<BlobData> > 
00101   extractBlobs(const Sketch<bool> &sketch, int minarea=0,
00102          BlobData::BlobOrientation_t orient=BlobData::groundplane, 
00103          int maxblobs=50); 
00104 
00105   //! Import blobs from Sketch<uchar> as a vector of Shape<BlobData>
00106   static std::vector<Shape<BlobData> >
00107   extractBlobs(const Sketch<CMVision::uchar> &sketch, 
00108          const set<int>& colors, int minarea=0,
00109          BlobData::BlobOrientation_t orient=BlobData::groundplane,
00110          int maxblobs=50);
00111   static std::vector<Shape<BlobData> >
00112   extractBlobs(const Sketch<CMVision::uchar> &sketch, int minarea=0,
00113          BlobData::BlobOrientation_t orient=BlobData::groundplane,
00114          int maxblobs=50);
00115 
00116   static BlobData* 
00117   new_blob(ShapeSpace& space,
00118      const CMVision::region &reg, 
00119      const CMVision::run<CMVision::uchar> *rle_buff,
00120      const BlobData::BlobOrientation_t orient,
00121      const rgb rgbvalue);
00122 
00123   std::vector<Point> findCorners(unsigned int nExpected, std::vector<Point>& candidates, float &bestValue);
00124 
00125   std::vector<Point> findCornersDerivative();
00126 
00127   std::vector<Point> findCornersDiagonal();
00128 
00129   std::vector<Point> findCornersShapeFit(unsigned int ncorners, std::vector<Point>& candidates, float &bestValue);
00130 
00131 
00132  // comparison predicates
00133 
00134   class areaLessThan : public BinaryShapePred<BlobData> {
00135   public:
00136     bool operator() (const Shape<BlobData> &b1, const Shape<BlobData> &b2) const;
00137   };
00138 
00139 private:
00140   //! Render into a sketch space and return reference. (Private.)
00141   virtual Sketch<bool>* render() const;
00142 
00143   BlobData& operator=(const BlobData&); //!< don't call
00144 
00145 };
00146 
00147 } // namespace
00148 
00149 #endif // BLOBDATA_H_

DualCoding 3.0beta
Generated Wed Oct 4 00:01:53 2006 by Doxygen 1.4.7