GSlocalizer.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
00039
00040
00041
00042 #ifndef BEOBOT_GSLOCALIZER_H_DEFINED
00043 #define BEOBOT_GSLOCALIZER_H_DEFINED
00044
00045 #define NUM_GSL_THREAD 16
00046 #define N_OBJECT_BLOCK 40
00047
00048 #include "Beowulf/Beowulf.H"
00049 #include "Beobot/beobot-GSnav-def.H"
00050
00051 #include "Component/ModelComponent.H"
00052 #include "Beobot/Landmark.H"
00053 #include "SIFT/Histogram.H"
00054 #include "Beobot/GSparticle.H"
00055 #include "Beobot/Environment.H"
00056 #include "Util/Timer.H"
00057
00058 #include <list>
00059 #include <pthread.h>
00060
00061
00062
00063
00064 struct GSlocJobData
00065 {
00066 GSlocJobData() { };
00067
00068 GSlocJobData(const int inObjNum,
00069 const int inSegNum,
00070 const int inLmkNum,
00071 const int inVOstartNum,
00072 const int inVOendNum) :
00073 objNum(inObjNum),
00074 segNum(inSegNum),
00075 lmkNum(inLmkNum),
00076 voStartNum(inVOstartNum),
00077 voEndNum(inVOendNum)
00078 {
00079 pVal = 0.0;
00080 segVal = 0.0;
00081 salVal = 0.0;
00082 locVal = 0.0;
00083 }
00084
00085 int objNum;
00086 int segNum;
00087 int lmkNum;
00088 int voStartNum;
00089 int voEndNum;
00090
00091
00092 float pVal;
00093 float segVal;
00094 float salVal;
00095 float locVal;
00096
00097 bool operator < (const GSlocJobData& rhs)
00098 {
00099 return pVal < rhs.pVal;
00100 }
00101
00102 };
00103
00104
00105
00106
00107
00108 class GSlocalizer : public ModelComponent
00109 {
00110 public:
00111
00112
00113
00114
00115
00116
00117 GSlocalizer(OptionManager& mgr,
00118 const std::string& descrName = "Gist and Saliency localizer",
00119 const std::string& tagName = "GSlocalizer");
00120
00121
00122 virtual ~GSlocalizer();
00123
00124
00125 void setSavePrefix(std::string prefix);
00126
00127
00128 void setEnvironment(rutz::shared_ptr<Environment> env);
00129
00130
00131
00132
00133
00134
00135
00136
00137 uint getNumObjectSearch(uint index);
00138
00139
00140 rutz::shared_ptr<Environment> getEnvironment();
00141
00142
00143 void setWindow(rutz::shared_ptr<XWinManaged> inputWin);
00144
00145
00146 void setBeoWulf(nub::soft_ref<Beowulf> beo);
00147
00148
00149 Image<PixRGB<byte> > getInputImage();
00150
00151
00152 uint getNumInputObject();
00153
00154
00155 rutz::shared_ptr<VisualObject> getInputVO(uint index);
00156
00157
00158 Image<double> getInputGist();
00159
00160
00161 rutz::shared_ptr<VisualObjectMatch> getVOmatch(uint index);
00162
00163
00164 uint getSegmentNumberMatch(uint index);
00165
00166
00167 float getLengthTraveledMatch(uint index);
00168
00169
00170
00171 Point2D<int> getInputObjOffset(uint index);
00172
00173
00174 int getInputFnum();
00175
00176
00177 int getSearchInputFnum();
00178
00179
00180 rutz::shared_ptr<Histogram> getSegmentHistogram();
00181
00182
00183 Point2D<int> getLocation();
00184
00185
00186 uint getSegmentLocation();
00187
00188
00189 float getSegmentLengthTraveled();
00190
00191
00192 void setGroundTruth(uint snum, float ltrav);
00193
00194
00195 void getGroundTruth(uint &snum, float <rav);
00196
00197
00198
00199
00200
00201
00202
00203
00204 void initParticles(std::string belFName = std::string(""));
00205
00206
00207 std::vector<GSparticle> getBeliefParticles();
00208
00209
00210 bool outputReady();
00211
00212
00213 bool isMatchFound(uint index);
00214
00215
00216
00217 void input(Image<PixRGB<byte> > ima,
00218 std::vector<rutz::shared_ptr<VisualObject> > inputVO,
00219 std::vector<Point2D<int> > inputObjOffset,
00220 int inputFnum, Image<double> cgist,
00221 float dx = -1.0F, float dy = -1.0F);
00222
00223
00224 rutz::shared_ptr<Histogram> getSegmentBeliefHistogram();
00225
00226
00227 void threadCompute();
00228
00229
00230
00231
00232 void stopSearch();
00233
00234
00235
00236 void stopSearch2();
00237
00238
00239
00240 void updateBelief();
00241
00242
00243 void actionUpdateBelief();
00244
00245
00246 void segmentUpdateBelief();
00247
00248
00249 void objectUpdateBelief();
00250
00251
00252 void objectUpdateBelief(uint index);
00253
00254
00255 void setLocation();
00256
00257
00258 Image<PixRGB<byte> > getBeliefImage(uint w, uint h, int &scale);
00259
00260
00261 Image<PixRGB<byte> > getMatchImage(uint index, Dims d);
00262
00263
00264
00265
00266
00267
00268 Point2D<int> getMotorSignal();
00269
00270
00271
00272 protected:
00273 void start1();
00274 void stop2();
00275
00276 private:
00277
00278
00279
00280
00281
00282
00283 void setSearchPriority();
00284
00285
00286 void addRandomPriority();
00287
00288
00289 void addSegmentPriority();
00290
00291
00292 void addSaliencyPriority();
00293
00294
00295 void addLocationPriority();
00296
00297
00298 GSlocJobData getMatch(uint index);
00299
00300
00301
00302
00303 std::string itsSavePrefix;
00304
00305
00306 std::vector<GSparticle> itsBeliefParticles;
00307 std::vector<Point2D<int> > itsBeliefLocations;
00308
00309
00310 rutz::shared_ptr<Environment> itsEnvironment;
00311
00312
00313 rutz::shared_ptr<TopologicalMap> itsTopologicalMap;
00314
00315
00316 rutz::shared_ptr<LandmarkDB> itsLandmarkDB;
00317
00318
00319 Image<PixRGB<byte> > itsInputImage;
00320 std::vector<rutz::shared_ptr<VisualObject> > itsInputVO;
00321 std::vector<bool> itsVOKeypointsComputed;
00322 std::vector<Point2D<int> > itsInputObjOffset;
00323 Image<double> itsInputGist;
00324 int itsInputFnum;
00325 int itsSearchInputFnum;
00326
00327
00328 uint itsSnumGT;
00329 float itsLtravGT;
00330
00331
00332 float itsRobotDx;
00333 float itsRobotDy;
00334
00335
00336 rutz::shared_ptr<Histogram> itsSegmentHistogram;
00337
00338
00339 std::vector<rutz::shared_ptr<VisualObjectMatch> > itsVOmatch;
00340 std::vector<GSlocJobData> itsLmkMatch;
00341 std::vector<uint> itsSegNumMatch;
00342 std::vector<float> itsLenTravMatch;
00343 std::vector<bool> itsMatchFound;
00344 std::vector<uint> itsNumObjectSearch;
00345
00346
00347 uint itsSegmentLocation;
00348 float itsSegmentLengthTraveled;
00349 Point2D<int> itsLocation;
00350
00351
00352
00353 std::list<GSlocJobData> itsJobQueue;
00354 bool itsIsQueueSorted;
00355 uint itsNumJobsProcessed;
00356 uint itsLastSuccessfulJob;
00357 uint itsNumObjectFound;
00358 uint itsNumJobs;
00359 bool itsStopSearch;
00360
00361 uint itsNumWorking;
00362
00363
00364 nub::soft_ref<Beowulf> itsBeowulf;
00365
00366
00367 rutz::shared_ptr<Histogram> itsSegmentBeliefHistogram;
00368
00369
00370 bool itsOutputReady2;
00371
00372
00373 pthread_t *worker;
00374 pthread_mutex_t jobLock;
00375 pthread_mutex_t fnumLock;
00376 pthread_mutex_t or2Lock;
00377 pthread_mutex_t stopSearchLock;
00378 pthread_mutex_t resLock;
00379 pthread_mutex_t workLock;
00380 pthread_mutex_t particleLock;
00381 pthread_cond_t jobCond;
00382 uint numWorkers;
00383
00384 rutz::shared_ptr<XWinManaged> itsWin;
00385
00386 rutz::shared_ptr<Timer> itsTimer;
00387 };
00388
00389 #endif
00390
00391
00392
00393
00394
00395