asmlib-opencv
an ASM(Active Shape Model) implementation by C++ & OpenCV
|
00001 #ifndef ASMMODEL_H 00002 #define ASMMODEL_H 00003 #include "shapemodel.h" 00004 #include "cv.h" 00005 00032 00033 namespace StatModel { 00034 00035 using cv::Point_; 00036 using cv::Mat_; 00037 00038 #define ASM_FIT_VERBOSE_NOVERBOSE 0 00039 #define ASM_FIT_VERBOSE_AT_LEVEL 1 00040 #define ASM_FIT_VERBOSE_AT_ITERATION 2 00041 #define ASM_FIT_VERBOSE_AT_POINT 3 00042 00043 class ASMModel; 00044 00049 00050 00053 class ASMFitResult : public FitResult { 00054 private: 00055 ASMModel *asmModel; 00056 public: 00057 ASMFitResult(ASMModel *model): asmModel(model) {} 00058 00060 void toPointList(vector< Point_<int> > &pV) const; 00061 }; 00062 00064 00067 class ASMModel : public ShapeModel 00068 { 00069 private: 00071 vector< vector< Mat_< double > > > iCovarG; 00072 00074 vector< vector< Mat_< double > > > meanG; 00075 00077 int localFeatureRad; 00078 00080 int ns; 00081 00084 void buildLocalDiffStructure(); 00085 00086 PCA pcaPyr[3]; 00087 double sigma2Pyr[3]; 00088 00089 public: 00091 ASMModel():localFeatureRad(4), ns(6){} 00092 00094 ASMModel(const string& filename) { loadFromFile(filename); } 00095 00097 00107 vector< ASMFitResult > fitAll( 00108 const Mat & img, 00109 const vector< cv::Rect > & detectedObjs, 00110 int verbose=0); 00111 00113 00119 ASMFitResult fit(const Mat & img, int verbose=0); 00120 00122 void buildModel(const string& shapeDefFile, const string& ptsListFile); 00123 00125 void saveToFile(const string& filename); 00126 00128 void loadFromFile(const string& filename); 00129 00131 void showResult(Mat &img, const vector< ASMFitResult > &res); 00132 00133 private: 00135 00139 void findParamForShape(const ShapeVec &Y, ASMFitResult & fitResult); 00140 00142 00145 void findParamForShapeBTSM(const ShapeVec &Y, const ShapeVec &Y_old, 00146 ASMFitResult & fitResult, ASMFitResult &b_old, int l); 00147 00149 void saveToFile(ModelFile &file); 00150 00152 void loadFromFile(ModelFile &file); 00153 }; 00154 00155 } // Namespace 00156 #endif // ASMMODEL_H