DPM.H
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 DPM_H_DEFINED
00043 #define DPM_H_DEFINED
00044
00045 #include "Util/Types.H"
00046 #include "Image/Image.H"
00047 #include "Image/Pixels.H"
00048 #include "Image/ImageSet.H"
00049 #include "Features/HOG.H"
00050 #include "Util/JobServer.H"
00051 #include "Util/JobWithSemaphore.H"
00052 #include "Util/WorkThreadServer.H"
00053
00054 #include <vector>
00055 #include <string>
00056 #include <stdio.h>
00057
00058 class DPM
00059 {
00060 public:
00061
00062
00063 struct HOGFeatures
00064 {
00065 ImageSet<double> features;
00066 int bins;
00067 double scale;
00068 };
00069
00070 struct ModelScore
00071 {
00072 int level;
00073 Image<double> score;
00074 Image<int> component;
00075
00076 ModelScore(const Image<double> s, const Image<int> comp, int l) :
00077 level(l), score(s), component(comp)
00078 {
00079 }
00080 };
00081
00082 struct Detection
00083 {
00084 Rectangle bb;
00085 double score;
00086 int component;
00087
00088 Detection(const Rectangle rect, double s, int c) :
00089 bb(rect),
00090 score(s),
00091 component(c)
00092 {
00093 }
00094 };
00095
00096
00097 struct ModelPart
00098 {
00099 ImageSet<double> features;
00100 Point2D<float> anchor;
00101 float scale;
00102 std::vector<double> deformation;
00103 };
00104
00105 struct ModelComponent
00106 {
00107 ImageSet<double> rootFilter;
00108 double offset;
00109 std::vector<ModelPart> parts;
00110 };
00111
00112 struct Model
00113 {
00114 std::vector<ModelComponent> components;
00115 };
00116
00117
00118 DPM();
00119
00120
00121 virtual ~DPM();
00122
00123 void computeFeaturePyramid(const Image<PixRGB<byte> >& img);
00124
00125
00126 void readModel(const char* fileName);
00127
00128
00129 Image<PixRGB<byte> > getModelImage();
00130
00131
00132 void convolveModel();
00133
00134
00135 Image<double> convolveComponent(const int comp, const int level);
00136
00137
00138
00139 std::vector<Detection> getBoundingBoxes(const float thresh);
00140
00141
00142 std::vector<Detection> filterDetections(const std::vector<Detection>& detections, const float overlap);
00143
00144 Image<double> convolveFeatures(const ImageSet<double>& imgFeatures,
00145 const ImageSet<double>& filterFeatures);
00146
00147
00148 Image<double> distanceTrans(const Image<double>& score,
00149 const std::vector<double>& deformation);
00150
00151
00152 void dtHelper(const Image<double>::const_iterator src,
00153 Image<double>::iterator dst,
00154 Image<int>::iterator ptr,
00155 int step,
00156 int s1, int s2, int d1, int d2,
00157 double a, double b);
00158
00159
00160 protected:
00161
00162 class DPMJob : public JobWithSemaphore
00163 {
00164 public:
00165 DPMJob(DPM* dpm, const int comp, const int l) :
00166 itsDPM(dpm), itsComponent(comp), itsLevel(l)
00167 { }
00168
00169 virtual ~DPMJob() { }
00170
00171 virtual void run()
00172 {
00173 itsScore = itsDPM->convolveComponent(itsComponent, itsLevel);
00174 this->markFinished();
00175 }
00176
00177 Image<double> getScore() { return itsScore; }
00178 int getComponent() { return itsComponent; }
00179
00180 virtual const char* jobType() const { return "DPMJob"; }
00181
00182 private:
00183 DPM* itsDPM;
00184 int itsComponent;
00185 int itsLevel;
00186 Image<double> itsScore;
00187 };
00188
00189
00190 private:
00191 std::vector<HOGFeatures> itsFeaturesPyramid;
00192 Model itsModel;
00193
00194 int itsInterval;
00195
00196 std::vector<ModelScore> itsModelScores;
00197
00198 rutz::shared_ptr<WorkThreadServer> itsThreadServer;
00199
00200 };
00201
00202
00203
00204
00205
00206
00207
00208
00209 #endif //