00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00020 #ifndef CMotion2DEstimator_h
00021 #define CMotion2DEstimator_h
00022
00023 #include <stdio.h>
00024
00025 #include <CMotion2DPyramid.h>
00026 #include <CMotion2DModel.h>
00027
00028
00029 #if defined (WIN32)
00030 # if defined MOTION2D_DLL_EXPORTS
00031 # define MOTION2D_API __declspec( dllexport )
00032 # elif defined MOTION2D_DLL_IMPORTS
00033 # define MOTION2D_API __declspec( dllimport )
00034 # else
00035 # define MOTION2D_API
00036 # endif
00037 #else
00038 # define MOTION2D_API
00039 #endif
00040
00041
00042
00043 class MOTION2D_API CMotion2DEstimator
00044 {
00045 public:
00046
00055 enum ERobustFunction {
00056 Tukey,
00059 Talwar,
00062 Cauchy,
00064 Welsh
00066 };
00067
00083 enum ECConstType {
00084 CConst_Fixed,
00087 CConst_Classic,
00090 CConst_Robust
00092 };
00093
00094 public:
00095 CMotion2DEstimator();
00096 ~CMotion2DEstimator();
00097
00098 bool estimate(const CMotion2DPyramid & pyramid1,
00099 const CMotion2DPyramid & pyramid2,
00100 const short *support, short label,
00101 CMotion2DModel &model, bool useModelAsInitialization=false);
00102 bool estimate(const CMotion2DPyramid & pyramid1,
00103 const CMotion2DPyramid & pyramid2,
00104 const unsigned char *support, unsigned char label,
00105 CMotion2DModel &model, bool useModelAsInitialization=false);
00106 float *getWeights(int &n_rows, int &n_cols);
00107
00108
00117 void setRobustEstimator(bool robust=true) {
00118 if (robust == true)
00119 least_mean_square = false;
00120 else {
00121 least_mean_square = true;
00122
00123 }
00124 };
00125
00135 void setRobustFunction(ERobustFunction function=Tukey) {
00136 switch (function) {
00137 case Tukey : ty_pond = 0; break;
00138 case Talwar: ty_pond = 1; break;
00139 case Cauchy: ty_pond = 2; break;
00140 case Welsh : ty_pond = 3; break;
00141 }
00142 };
00151 void setCConstant(ECConstType C_type=CConst_Fixed, double C=8.0) {
00152 switch (C_type) {
00153 case CConst_Fixed:
00154 type_variance = 0;
00155 variance = C;
00156 break;
00157 case CConst_Classic:
00158 type_variance = 1;
00159 break;
00160 case CConst_Robust:
00161 type_variance = 2;
00162 break;
00163 }
00164 };
00165
00179 void setNIterationMaxIRLS(int niter=8) {
00180 max_it_irls = niter;
00181 };
00182
00191 void setNIterationMaxLevel(int niter=7) {
00192 max_it_stab = niter;
00193 };
00194
00204 void setLevelParameterIntroduction(int level_const=-1,
00205 int level_affine=-1,
00206 int level_quadratic=-1) {
00207
00208 level_ct = level_const;
00209 level_lin = level_affine;
00210 level_quad = level_quadratic;
00211 };
00212
00236 bool setFirstEstimationLevel(unsigned level=3) {
00237 if (level >= (unsigned) CMotion2DPyramid::NLEVELS_MAX) {
00238 __panic("Cmotion2DEstimator::setFirstEstimationLevel() : Bad level...");
00239 return false;
00240 }
00241 first_est_level = level;
00242 return true;
00243 };
00244
00256 unsigned getFirstEstimationLevel() {
00257 return pyr_level_max;
00258 };
00259
00271 bool setLastEstimationLevel(unsigned level=0) {
00272 if (level >= (unsigned) CMotion2DPyramid::NLEVELS_MAX) {
00273 __panic("Cmotion2DEstimator::setFirstEstimationLevel() : Bad level...");
00274 return false;
00275 }
00276
00277 final_est_level = level;
00278 return true;
00279 };
00280
00290 unsigned getLastEstimationLevel() {
00291 return final_est_level;
00292 };
00293
00300 void setReliableSupportRate(float rate=0.4) {
00301 if ((rate < 0.f) || (rate > 1.f)) {
00302 __panic("CMotion2DEstimator::setReliableSupportRate(): Bad rate...");
00303 }
00304 tx_pts_min = rate;
00305 };
00306
00321 void computeSupportSize(bool compute=true, float threshold = 0.2f) {
00322 if (compute == true) {
00323 compute_support_size = 1;
00324
00325 if ((threshold < 0.f) || (threshold > 1.f)) {
00326 __panic("CMotion2DEstimator::computeSupportSize(): Bad threshold.");
00327 }
00328 seuil_poids = threshold;
00329
00330 }
00331 else
00332 compute_support_size = 0;
00333 };
00334
00342 bool isSupportSizeComputed() {
00343 if (compute_support_size == 1)
00344 return true;
00345 else
00346 return false;
00347 };
00348
00357 bool getSupportSize(double &size) {
00358 if (compute_support_size == 1) {
00359 size = rapport_poids;
00360 return true;
00361 }
00362 else {
00363
00364 size = 0.0;
00365 return false;
00366 }
00367 };
00368
00377 void computeResidualVariance(bool compute=false) {
00378 compute_sigma2res = compute;
00379 };
00380
00390 bool isResidualVarianceComputed() {
00391 if (compute_sigma2res == true)
00392 return true;
00393 else
00394 return false;
00395 };
00396
00404 double getResidualVariance() {return sigma2res; };
00405
00414 void computeCovarianceMatrix(bool compute=false) {
00415 compute_covariance = compute;
00416 };
00417
00426 bool isCovarianceMatrixComputed() {
00427 if (compute_covariance == true)
00428 return true;
00429 else
00430 return false;
00431 };
00444 double *getCovarianceMatrix(int &n_rows, int &n_cols){
00445 if (compute_covariance == true) {
00446 n_rows = MAXCOEFSMODEL;
00447 n_cols = MAXCOEFSMODEL;
00448 return covariance;
00449 }
00450 else {
00451
00452 n_rows = -1;
00453 n_cols = -1;
00454 return NULL;
00455 }
00456 };
00457
00458 float *getDisplacedRowsSpatialGradientDataAddress(int level, int &n_rows, int &n_cols);
00459 float *getDisplacedColsSpatialGradientDataAddress(int level, int &n_rows, int &n_cols);
00460 float *getDFDDataAddress(int level, int &n_rows, int &n_cols);
00461
00462
00463 private:
00464 void __panic(char *message);
00465
00467
00469
00470 int type_variance;
00471 int ty_pond;
00472
00473 int max_it_stab;
00474 int max_it_irls;
00475 double variance;
00476 int level_ct;
00477 int level_lin;
00478 int level_quad;
00479 unsigned first_est_level;
00480 unsigned final_est_level;
00481 int pyr_level_max;
00482 bool compute_sigma2res;
00483 bool compute_covariance;
00484 bool verbose;
00485
00486 double seuil_poids;
00487 bool least_mean_square;
00488 double tx_pts_min;
00489
00490 bool init_mem_estIsDone;
00491 bool init_mem_weightsIsDone;
00492 TImageFloat pyr_fl1[CMotion2DPyramid::NLEVELS_MAX];
00493 TImageFloat pyr_fl2[CMotion2DPyramid::NLEVELS_MAX];
00494 TImageFloat pyr_fl3[CMotion2DPyramid::NLEVELS_MAX];
00495 TImageFloat pyr_weights[CMotion2DPyramid::NLEVELS_MAX];
00496 TImageShort pyr_support[CMotion2DPyramid::NLEVELS_MAX];
00497 int ct_level_intro;
00498 int lin_level_intro;
00499 int quad_level_intro;
00500 int compute_support_size;
00501
00502
00503
00504 double rapport_poids;
00505 double sigma2res;
00506 double covariance[MAXCOEFSMODEL * MAXCOEFSMODEL];
00507
00508 };
00509
00510
00511 #endif