00001
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"
00014 #include "Point.h"
00015 #include "SketchTypes.h"
00016 #include "ShapeTypes.h"
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
00031
00032 class BlobData : public BaseData {
00033 public:
00034
00035
00036 enum BlobOrientation_t {
00037 groundplane,
00038 pillar,
00039 poster
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
00051
00052 bool topValid, bottomValid, leftValid, rightValid;
00053
00054 BlobOrientation_t orientation;
00055 coordinate_t assumedHeight;
00056
00057 Point topLeft, topRight, bottomLeft, bottomRight;
00058 float area;
00059 const std::vector<run> runvec;
00060
00061 public:
00062
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
00080 virtual Point getCentroid() const;
00081
00082
00083 float getArea() const { return area; }
00084
00085
00086 virtual void printParams() const;
00087
00088
00089 virtual void applyTransform(const fmat::Transform& Tmat, const ReferenceFrameType_t newref=unspecified);
00090
00091
00092
00093
00094 virtual void projectToGround(const fmat::Transform& camToBase,
00095 const PlaneEquation& gndplane);
00096
00097
00098 virtual void update_derived_properties();
00099
00100
00101 BoundingBox2D getBoundingBox() const;
00102
00103
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
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
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
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
00137 static BlobData* new_blob(ShapeSpace& space,
00138 const CMVision::region ®,
00139 const CMVision::run<CMVision::uchar> *rle_buff,
00140 const BlobOrientation_t orient,
00141 const coordinate_t height,
00142 const rgb rgbvalue);
00143
00144
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
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
00161 virtual Sketch<bool>* render() const;
00162
00163 BlobData& operator=(const BlobData&);
00164
00165 };
00166
00167 }
00168
00169 #endif // BLOBDATA_H_