00001
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"
00014 #include "Point.h"
00015 #include "ShapeTypes.h"
00016 #include "ShapeFuns.h"
00017
00018 namespace DualCoding {
00019
00020 class ShapeRoot;
00021 template<typename T> class Sketch;
00022
00023
00024
00025 class BlobData : public BaseData {
00026 public:
00027
00028
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
00044 enum BlobOrientation_t {
00045 groundplane,
00046 pillar,
00047 pinata
00048 } orientation;
00049
00050 public:
00051
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
00067 virtual Point getCentroid() const;
00068
00069
00070 float getArea() { return area; }
00071
00072
00073 virtual void printParams() const;
00074
00075
00076 virtual void applyTransform(const NEWMAT::Matrix& Tmat);
00077
00078
00079
00080 virtual void projectToGround(const NEWMAT::Matrix& camToBase,
00081 const NEWMAT::ColumnVector& groundplane);
00082
00083
00084 virtual void update_derived_properties();
00085
00086
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
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
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 ®,
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
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
00141 virtual Sketch<bool>* render() const;
00142
00143 BlobData& operator=(const BlobData&);
00144
00145 };
00146
00147 }
00148
00149 #endif // BLOBDATA_H_