V4d.H
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef V4d_H_DEFINED
00039 #define V4d_H_DEFINED
00040
00041
00042
00043 #include "Image/Image.H"
00044 #include "Image/ImageSet.H"
00045 #include "Image/Pixels.H"
00046 #include "Image/Layout.H"
00047 #include "Image/Point3D.H"
00048 #include "plugins/SceneUnderstanding/Camera.H"
00049
00050 #include "plugins/SceneUnderstanding/V4d.H"
00051 #include "plugins/SceneUnderstanding/V2.H"
00052 #include "Simulation/SimEvents.H"
00053 #include "Simulation/SimModule.H"
00054 #include "SIFT/Histogram.H"
00055 #include "Util/WorkThreadServer.H"
00056
00057 #include <vector>
00058 #include <string>
00059 #include <queue>
00060 #include <google/dense_hash_map>
00061 using google::dense_hash_map;
00062
00063 class SimEventV4BiasOutput;
00064
00065 class V4d : public SimModule
00066 {
00067 public:
00068
00069 enum NAF_TYPE {RIGHT_VERTIX,VERTIX, ARC};
00070
00071 struct NAFState
00072 {
00073 Point3D<float> pos;
00074 float rot;
00075 NAF_TYPE featureType;
00076 Point3D<float> posSigma;
00077 float rotSigma;
00078
00079 double prob;
00080 double weight;
00081
00082 NAFState () {}
00083
00084 NAFState (Point3D<float> p, float r, NAF_TYPE ft, Point3D<float> ps, float rs) :
00085 pos(p), rot(r), featureType(ft),
00086 posSigma(ps), rotSigma(rs),
00087 prob(0), weight(0)
00088 {}
00089
00090 double distance(const NAFState &nafState)
00091 {
00092 double dist = 1.0e100;
00093 if (nafState.featureType == featureType)
00094 {
00095 double dPoint = pos.squdist(nafState.pos);
00096 double dRot = nafState.rot - rot;
00097 dRot = acos(cos(nafState.rot - rot));
00098
00099 dist = sqrt(dPoint + (dRot*dRot));
00100 } else {
00101 dist = 1.0e100;
00102 }
00103
00104 return dist;
00105 }
00106 };
00107
00108 struct RTableEntry
00109 {
00110 Point2D<int> loc;
00111 float rot;
00112 };
00113
00114 struct FeatureTemplate
00115 {
00116 std::vector<V1::EdgeState> edges;
00117 std::vector<Point3D<float> > outline;
00118 std::vector<Point3D<float> > var;
00119 std::vector<RTableEntry> rTable;
00120 NAF_TYPE featureType;
00121 };
00122
00123 struct GHTAcc
00124 {
00125 Point2D<int> pos;
00126 int ang;
00127 int scale;
00128 NAF_TYPE featureType;
00129 float sum;
00130
00131 bool operator<(const GHTAcc& acc) const
00132 {
00133 return sum < acc.sum;
00134 }
00135 };
00136
00137 V4d(OptionManager& mgr, const std::string& descrName = "V4",
00138 const std::string& tagName = "V4");
00139
00140
00141 ~V4d();
00142
00143
00144 void alignToCenterOfMass(FeatureTemplate& featureTemplate);
00145
00146 void buildRTables();
00147
00148
00149
00150 void evolve();
00151 void evolveSift();
00152
00153 float calculateOrientationVector(Point2D<int>& loc, Histogram& OV);
00154 float createDescriptor(Point2D<int>& loc, Histogram& OV, float mainOri);
00155
00156 void harrisDetector(std::vector<V4d::GHTAcc>& accRet, const FeatureTemplate& featureTemplate);
00157 void proposeParticlesHarris(std::vector<NAFState>& particles, const double Neff);
00158
00159
00160 Layout<PixRGB<byte> > getDebugImage();
00161
00162 void getParticleLikelihood(NAFState& particle);
00163 double getLineProbability(const Point2D<int>& p1, const Point2D<int>& p2);
00164
00165 void resampleParticles(std::vector<NAFState>& particles);
00166 void resampleParticles2(std::vector<NAFState>& particles);
00167 void proposeParticles(std::vector<NAFState>& particles, const double Neff);
00168 float evaluateParticles(std::vector<NAFState>& particles);
00169
00170
00171 std::vector<Point2D<int> > getImageOutline(NAFState& nafState);
00172
00173 void findAngMerge(std::vector<GHTAcc>& acc, const NAFState& nafState, std::vector<GHTAcc> tmpAcc);
00174 void mergeBias(std::vector<GHTAcc>& acc);
00175
00176
00177
00178 void GHT(std::vector<GHTAcc>& accRet, const FeatureTemplate& featureTemplate);
00179 float voteForFeature(Image<float>& acc, int angIdx, std::vector<V1::EdgeState>& rTable);
00180
00181 void normalizeAcc(std::vector<GHTAcc>& acc);
00182
00183 Image<PixRGB<byte> > showParticles(const std::vector<NAFState>& particles);
00184
00185 protected:
00186
00187 SIMCALLBACK_DECLARE(V4d, SimEventV2Output);
00188
00189
00190 SIMCALLBACK_DECLARE(V4d, SimEventSaveOutput);
00191
00192
00193 SIMCALLBACK_DECLARE(V4d, SimEventUserInput);
00194
00195
00196 SIMCALLBACK_DECLARE(V4d, SimEventV4BiasOutput);
00197
00198
00199 OModelParam<bool> itsShowDebug;
00200
00201 private:
00202
00203 std::vector<V1::EdgeState> itsEdgesState;
00204 std::priority_queue<V2::CornerState> itsCornersState;
00205 dense_hash_map<int, V1::EdgeState> itsHashedEdgesState;
00206
00207 float itsMaxVal;
00208 int itsGHTAngStep;
00209 double itsBestProb;
00210 float itsObjectsDist;
00211
00212 Camera itsCamera;
00213 std::vector<FeatureTemplate> itsNAFeatures;
00214
00215 std::vector<NAFState> itsFeaturesParticles;
00216 std::vector<NAFState> itsBias;
00217
00218 rutz::shared_ptr<WorkThreadServer> itsThreadServer;
00219
00220
00221
00222 Image<PixRGB<byte> > itsDebugImg;
00223
00224 };
00225
00226
00227 class SimEventV4dOutput : public SimEvent
00228 {
00229 public:
00230 SimEventV4dOutput(SimModule* src, std::vector<V4d::NAFState>& cellsOutput) :
00231 SimEvent(src), itsCells(cellsOutput)
00232 {}
00233
00234 virtual ~SimEventV4dOutput(){}
00235 std::vector<V4d::NAFState> getCells() { return itsCells; }
00236
00237 private:
00238 const std::vector<V4d::NAFState>& itsCells;
00239 };
00240
00241 class SimEventV4BiasOutput : public SimEvent
00242 {
00243 public:
00244 SimEventV4BiasOutput(SimModule* src, std::vector<V4d::NAFState>& cellsOutput) :
00245 SimEvent(src), itsCells(cellsOutput)
00246 {}
00247
00248 virtual ~SimEventV4BiasOutput(){}
00249 std::vector<V4d::NAFState> getCells() { return itsCells; }
00250
00251 private:
00252 const std::vector<V4d::NAFState>& itsCells;
00253 };
00254
00255
00256
00257
00258
00259
00260
00261
00262 #endif //