V4.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 V4_H_DEFINED
00039 #define V4_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 #include "plugins/SceneUnderstanding/V4d.H"
00050 #include "plugins/SceneUnderstanding/V2.H"
00051 #include "Simulation/SimEvents.H"
00052 #include "Simulation/SimModule.H"
00053 #include "Util/WorkThreadServer.H"
00054
00055 #include <vector>
00056 #include <string>
00057 #include <google/dense_hash_map>
00058 using google::dense_hash_map;
00059
00060 class V4 : public SimModule
00061 {
00062 public:
00063
00064 enum GEON_TYPE {TRIANGLE,SQUARE, CIRCLE};
00065
00066 struct GeonState
00067 {
00068 Point3D<float> pos;
00069 float rot;
00070 double prob;
00071 double weight;
00072 GEON_TYPE geonType;
00073
00074 Point3D<float> posSigma;
00075 float rotSigma;
00076
00077 double distance(const GeonState &geonState)
00078 {
00079 double dist = 1.0e100;
00080 if (geonState.geonType == geonType)
00081 {
00082 double dPoint = pos.squdist(geonState.pos);
00083 double dRot = geonState.rot - rot;
00084 dRot = acos(cos(geonState.rot - rot));
00085
00086 dist = sqrt(dPoint + (dRot*dRot));
00087 } else {
00088 dist = 1.0e100;
00089 }
00090
00091 return dist;
00092 }
00093 };
00094
00095 struct RTableEntry
00096 {
00097 Point2D<int> loc;
00098 float rot;
00099 V4d::NAF_TYPE featureType;
00100 };
00101
00102 struct GHTAcc
00103 {
00104 Point2D<int> pos;
00105 int ang;
00106 int scale;
00107 GEON_TYPE geonType;
00108 float sum;
00109
00110 bool operator<(const GHTAcc& acc) const
00111 {
00112 return sum < acc.sum;
00113 }
00114
00115 };
00116
00117 struct GeonOutline
00118 {
00119 std::vector<Point3D<float> > outline;
00120 std::vector<V4d::NAFState> NAFTemplate;
00121 std::vector<RTableEntry> rTable;
00122 GEON_TYPE geonType;
00123 };
00124
00125 V4(OptionManager& mgr, const std::string& descrName = "V4",
00126 const std::string& tagName = "V4");
00127
00128
00129 ~V4();
00130
00131 void buildRTables();
00132 void init(Dims dims);
00133
00134 void setInput(const std::vector<V1::EdgeState> &edgesState);
00135 void setInput(const std::vector<V4d::NAFState> &nafStates);
00136
00137 std::vector<V4::GeonState> getOutput();
00138 std::vector<V4d::NAFState> getBias();
00139
00140 void showGeon(GeonOutline& object);
00141
00142 void evolve();
00143
00144
00145 void alignToCenterOfMass(GeonOutline& featureTemplate);
00146
00147 Layout<PixRGB<byte> > getDebugImage();
00148
00149 void getOutlineLikelihood(GeonState& geon);
00150 void getGeonLikelihood(GeonState& geon);
00151
00152 double getLineProbability(const Point2D<int>& p1, const Point2D<int>& p2);
00153
00154 void resampleParticles(std::vector<GeonState>& geonParticles);
00155 void resampleParticles2(std::vector<GeonState>& geonParticles);
00156 void proposeParticles(std::vector<GeonState>& geonParticles, const double Neff);
00157
00158 std::vector<Point2D<int> > getImageGeonOutline(GeonState& geon);
00159
00160 float evaluateGeonParticles(std::vector<GeonState>& geonParticles);
00161
00162
00163 void GHT(std::vector<GHTAcc>& accRet, GeonOutline& geonOutline);
00164 void normalizeAcc(std::vector<GHTAcc>& acc);
00165 void voteForFeature(Image<float>& acc, int angIdx, std::vector<RTableEntry>& rTable);
00166
00167
00168 Image<PixRGB<byte> > showParticles(const std::vector<GeonState>& geonParticles);
00169
00170 protected:
00171
00172 SIMCALLBACK_DECLARE(V4, SimEventV2Output);
00173
00174
00175 SIMCALLBACK_DECLARE(V4, SimEventV4dOutput);
00176
00177
00178
00179 SIMCALLBACK_DECLARE(V4, SimEventUserInput);
00180
00181
00182 SIMCALLBACK_DECLARE(V4, SimEventSaveOutput);
00183
00184
00185 OModelParam<bool> itsShowDebug;
00186
00187 private:
00188
00189 std::vector<V1::EdgeState> itsEdgesState;
00190 dense_hash_map<int, V1::EdgeState> itsHashedEdgesState;
00191
00192 std::vector<V4d::NAFState> itsNAFParticles;
00193
00194 float itsMaxVal;
00195 int itsGHTAngStep;
00196 double itsBestProb;
00197 float itsObjectsDist;
00198
00199
00200 Camera itsCamera;
00201 std::vector<GeonState> itsGeonsParticles;
00202
00203 std::vector<GeonOutline> itsGeons;
00204
00205
00206 Image<float> itsHoughSpaceImg;
00207
00208 rutz::shared_ptr<WorkThreadServer> itsThreadServer;
00209
00210 Image<PixRGB<byte> > itsDebugImg;
00211
00212 };
00213
00214
00215 class SimEventV4Output : public SimEvent
00216 {
00217 public:
00218 SimEventV4Output(SimModule* src, std::vector<V4::GeonState>& cellsOutput) :
00219 SimEvent(src), itsCells(cellsOutput)
00220 {}
00221
00222 virtual ~SimEventV4Output(){}
00223 std::vector<V4::GeonState> getCells() { return itsCells; }
00224
00225 private:
00226 const std::vector<V4::GeonState>& itsCells;
00227 };
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251 #endif //