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/newmat/newmat.h"
00012 #include "Vision/cmv_types.h"
00013
00014 #include "BaseData.h"
00015 #include "Point.h"
00016 #include "SketchTypes.h"
00017 #include "ShapeTypes.h"
00018 #include "ShapeFuns.h"
00019
00020 namespace DualCoding {
00021
00022 class ShapeRoot;
00023 template<typename T> class Sketch;
00024
00025
00026
00027 class BlobData : public BaseData {
00028 public:
00029
00030
00031 enum BlobOrientation_t {
00032 groundplane,
00033 pillar,
00034 poster
00035 };
00036
00037 struct run {
00038 public:
00039 unsigned short int x, y, width;
00040 run() : x(0), y(0), width(0) {}
00041 run(unsigned short int _x, unsigned short int _y, unsigned short int _width) :
00042 x(_x), y(_y), width(_width) {}
00043 };
00044
00045
00046 BlobOrientation_t orientation;
00047 coordinate_t assumedHeight;
00048
00049 Point topLeft, topRight, bottomLeft, bottomRight;
00050 float area;
00051 const std::vector<run> runvec;
00052
00053 public:
00054
00055 BlobData(ShapeSpace& _space,
00056 const Point &_topLeft, const Point &_topRight,
00057 const Point &_bottomLeft, const Point &_bottomRight,
00058 const float _area=0,
00059 const std::vector<run> &_runvec=std::vector<run>(),
00060 const BlobOrientation_t _orientation=groundplane,
00061 const coordinate_t assumedHeight=0,
00062 const rgb rgbvalue=rgb());
00063
00064 static ShapeType_t getStaticType() { return blobDataType; }
00065
00066 DATASTUFF_H(BlobData);
00067
00068 friend class Shape<BlobData>;
00069
00070
00071 virtual Point getCentroid() const;
00072
00073
00074 float getArea() { return area; }
00075
00076
00077 virtual void printParams() const;
00078
00079
00080 virtual void applyTransform(const NEWMAT::Matrix& Tmat, const ReferenceFrameType_t newref=unspecified);
00081
00082
00083
00084 virtual void projectToGround(const NEWMAT::Matrix& camToBase,
00085 const NEWMAT::ColumnVector& groundplane);
00086
00087
00088 virtual void update_derived_properties();
00089
00090
00091 virtual bool isMatchFor(const ShapeRoot& other) const;
00092
00093 virtual bool updateParams(const ShapeRoot& other, bool forceUpdate=false);
00094
00095 virtual unsigned short getDimension() const { return (orientation==groundplane) ? 2 : 3; }
00096
00097
00098
00099 static std::vector<Shape<BlobData> >
00100 extractBlobs(const Sketch<bool> &sketch,
00101 int minarea=25,
00102 BlobOrientation_t orient=BlobData::groundplane,
00103 coordinate_t height=0,
00104 int maxblobs=50);
00105
00106
00107 static std::vector<Shape<BlobData> >
00108 extractBlobs(const Sketch<uchar> &sketch,
00109 int minarea=25,
00110 BlobOrientation_t orient=BlobData::groundplane,
00111 const coordinate_t height=0,
00112 int maxblobs=50);
00113
00114
00115 static std::vector<Shape<BlobData> >
00116 extractBlobs(const Sketch<uchar> &sketch,
00117 const std::set<color_index>& colors,
00118 const std::map<color_index,int>& minareas,
00119 const std::map<color_index,BlobOrientation_t>& orients,
00120 const std::map<color_index,coordinate_t>& heights,
00121 int maxblobs);
00122
00123
00124 static BlobData* new_blob(ShapeSpace& space,
00125 const CMVision::region ®,
00126 const CMVision::run<CMVision::uchar> *rle_buff,
00127 const BlobOrientation_t orient,
00128 const coordinate_t height,
00129 const rgb rgbvalue);
00130
00131
00132
00133 std::vector<Point> findCorners(unsigned int nExpected, std::vector<Point>& candidates, float &bestValue);
00134 std::vector<Point> findCornersDerivative();
00135 std::vector<Point> findCornersDiagonal();
00136 std::vector<Point> findCornersShapeFit(unsigned int ncorners, std::vector<Point>& candidates, float &bestValue);
00137
00138
00139
00140
00141 class AreaLessThan : public BinaryShapePred<BlobData> {
00142 public:
00143 bool operator() (const Shape<BlobData> &b1, const Shape<BlobData> &b2) const;
00144 };
00145
00146 private:
00147
00148 virtual Sketch<bool>* render() const;
00149
00150 BlobData& operator=(const BlobData&);
00151
00152 };
00153
00154 }
00155
00156 #endif // BLOBDATA_H_