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
00043 #ifndef __OPENCV_BACKGROUND_SEGM_HPP__
00044 #define __OPENCV_BACKGROUND_SEGM_HPP__
00045
00046 #include "opencv2/core/core.hpp"
00047
00048 #ifdef __cplusplus
00049 extern "C" {
00050 #endif
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 #define CV_BG_MODEL_FGD 0
00087 #define CV_BG_MODEL_MOG 1
00088 #define CV_BG_MODEL_FGD_SIMPLE 2
00089
00090 struct CvBGStatModel;
00091
00092 typedef void (CV_CDECL * CvReleaseBGStatModel)( struct CvBGStatModel** bg_model );
00093 typedef int (CV_CDECL * CvUpdateBGStatModel)( IplImage* curr_frame, struct CvBGStatModel* bg_model,
00094 double learningRate );
00095
00096 #define CV_BG_STAT_MODEL_FIELDS() \
00097 int type; \
00098 CvReleaseBGStatModel release; \
00099 CvUpdateBGStatModel update; \
00100 IplImage* background; \
00101 IplImage* foreground; \
00102 IplImage** layers; \
00103 int layer_count; \
00104 CvMemStorage* storage; \
00105 CvSeq* foreground_regions
00106
00107 typedef struct CvBGStatModel
00108 {
00109 CV_BG_STAT_MODEL_FIELDS();
00110 } CvBGStatModel;
00111
00112
00113
00114
00115 CVAPI(void) cvReleaseBGStatModel( CvBGStatModel** bg_model );
00116
00117
00118 CVAPI(int) cvUpdateBGStatModel( IplImage* current_frame, CvBGStatModel* bg_model,
00119 double learningRate CV_DEFAULT(-1));
00120
00121
00122
00123
00124
00125
00126 CVAPI(void) cvRefineForegroundMaskBySegm( CvSeq* segments, CvBGStatModel* bg_model );
00127
00128
00129 CVAPI(int) cvChangeDetection( IplImage* prev_frame,
00130 IplImage* curr_frame,
00131 IplImage* change_mask );
00132
00133
00134
00135
00136
00137
00138 #define CV_BGFG_FGD_LC 128
00139 #define CV_BGFG_FGD_N1C 15
00140 #define CV_BGFG_FGD_N2C 25
00141
00142 #define CV_BGFG_FGD_LCC 64
00143 #define CV_BGFG_FGD_N1CC 25
00144 #define CV_BGFG_FGD_N2CC 40
00145
00146
00147 #define CV_BGFG_FGD_ALPHA_1 0.1f
00148
00149
00150
00151
00152 #define CV_BGFG_FGD_ALPHA_2 0.005f
00153
00154
00155 #define CV_BGFG_FGD_ALPHA_3 0.1f
00156
00157 #define CV_BGFG_FGD_DELTA 2
00158
00159 #define CV_BGFG_FGD_T 0.9f
00160
00161 #define CV_BGFG_FGD_MINAREA 15.f
00162
00163 #define CV_BGFG_FGD_BG_UPDATE_TRESH 0.5f
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178 typedef struct CvFGDStatModelParams
00179 {
00180 int Lc;
00181 int N1c;
00182 int N2c;
00183
00184
00185 int Lcc;
00186 int N1cc;
00187 int N2cc;
00188
00189
00190 int is_obj_without_holes;
00191 int perform_morphing;
00192
00193
00194 float alpha1;
00195 float alpha2;
00196 float alpha3;
00197
00198 float delta;
00199 float T;
00200 float minArea;
00201 } CvFGDStatModelParams;
00202
00203 typedef struct CvBGPixelCStatTable
00204 {
00205 float Pv, Pvb;
00206 uchar v[3];
00207 } CvBGPixelCStatTable;
00208
00209 typedef struct CvBGPixelCCStatTable
00210 {
00211 float Pv, Pvb;
00212 uchar v[6];
00213 } CvBGPixelCCStatTable;
00214
00215 typedef struct CvBGPixelStat
00216 {
00217 float Pbc;
00218 float Pbcc;
00219 CvBGPixelCStatTable* ctable;
00220 CvBGPixelCCStatTable* cctable;
00221 uchar is_trained_st_model;
00222 uchar is_trained_dyn_model;
00223 } CvBGPixelStat;
00224
00225
00226 typedef struct CvFGDStatModel
00227 {
00228 CV_BG_STAT_MODEL_FIELDS();
00229 CvBGPixelStat* pixel_stat;
00230 IplImage* Ftd;
00231 IplImage* Fbd;
00232 IplImage* prev_frame;
00233 CvFGDStatModelParams params;
00234 } CvFGDStatModel;
00235
00236
00237 CVAPI(CvBGStatModel*) cvCreateFGDStatModel( IplImage* first_frame,
00238 CvFGDStatModelParams* parameters CV_DEFAULT(NULL));
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251 #define CV_BGFG_MOG_MAX_NGAUSSIANS 500
00252
00253
00254 #define CV_BGFG_MOG_BACKGROUND_THRESHOLD 0.7
00255 #define CV_BGFG_MOG_STD_THRESHOLD 2.5
00256 #define CV_BGFG_MOG_WINDOW_SIZE 200
00257 #define CV_BGFG_MOG_NGAUSSIANS 5
00258 #define CV_BGFG_MOG_WEIGHT_INIT 0.05
00259 #define CV_BGFG_MOG_SIGMA_INIT 30
00260 #define CV_BGFG_MOG_MINAREA 15.f
00261
00262
00263 #define CV_BGFG_MOG_NCOLORS 3
00264
00265 typedef struct CvGaussBGStatModelParams
00266 {
00267 int win_size;
00268 int n_gauss;
00269 double bg_threshold, std_threshold, minArea;
00270 double weight_init, variance_init;
00271 }CvGaussBGStatModelParams;
00272
00273 typedef struct CvGaussBGValues
00274 {
00275 int match_sum;
00276 double weight;
00277 double variance[CV_BGFG_MOG_NCOLORS];
00278 double mean[CV_BGFG_MOG_NCOLORS];
00279 } CvGaussBGValues;
00280
00281 typedef struct CvGaussBGPoint
00282 {
00283 CvGaussBGValues* g_values;
00284 } CvGaussBGPoint;
00285
00286
00287 typedef struct CvGaussBGModel
00288 {
00289 CV_BG_STAT_MODEL_FIELDS();
00290 CvGaussBGStatModelParams params;
00291 CvGaussBGPoint* g_point;
00292 int countFrames;
00293 } CvGaussBGModel;
00294
00295
00296
00297 CVAPI(CvBGStatModel*) cvCreateGaussianBGModel( IplImage* first_frame,
00298 CvGaussBGStatModelParams* parameters CV_DEFAULT(NULL));
00299
00300
00301 typedef struct CvBGCodeBookElem
00302 {
00303 struct CvBGCodeBookElem* next;
00304 int tLastUpdate;
00305 int stale;
00306 uchar boxMin[3];
00307 uchar boxMax[3];
00308 uchar learnMin[3];
00309 uchar learnMax[3];
00310 } CvBGCodeBookElem;
00311
00312 typedef struct CvBGCodeBookModel
00313 {
00314 CvSize size;
00315 int t;
00316 uchar cbBounds[3];
00317 uchar modMin[3];
00318 uchar modMax[3];
00319 CvBGCodeBookElem** cbmap;
00320 CvMemStorage* storage;
00321 CvBGCodeBookElem* freeList;
00322 } CvBGCodeBookModel;
00323
00324 CVAPI(CvBGCodeBookModel*) cvCreateBGCodeBookModel();
00325 CVAPI(void) cvReleaseBGCodeBookModel( CvBGCodeBookModel** model );
00326
00327 CVAPI(void) cvBGCodeBookUpdate( CvBGCodeBookModel* model, const CvArr* image,
00328 CvRect roi CV_DEFAULT(cvRect(0,0,0,0)),
00329 const CvArr* mask CV_DEFAULT(0) );
00330
00331 CVAPI(int) cvBGCodeBookDiff( const CvBGCodeBookModel* model, const CvArr* image,
00332 CvArr* fgmask, CvRect roi CV_DEFAULT(cvRect(0,0,0,0)) );
00333
00334 CVAPI(void) cvBGCodeBookClearStale( CvBGCodeBookModel* model, int staleThresh,
00335 CvRect roi CV_DEFAULT(cvRect(0,0,0,0)),
00336 const CvArr* mask CV_DEFAULT(0) );
00337
00338 CVAPI(CvSeq*) cvSegmentFGMask( CvArr *fgmask, int poly1Hull0 CV_DEFAULT(1),
00339 float perimScale CV_DEFAULT(4.f),
00340 CvMemStorage* storage CV_DEFAULT(0),
00341 CvPoint offset CV_DEFAULT(cvPoint(0,0)));
00342
00343 #ifdef __cplusplus
00344 }
00345
00346 namespace cv
00347 {
00348
00355 class CV_EXPORTS_W BackgroundSubtractor
00356 {
00357 public:
00359 virtual ~BackgroundSubtractor();
00361 CV_WRAP_AS(apply) virtual void operator()(const Mat& image, CV_OUT Mat& fgmask,
00362 double learningRate=0);
00363 };
00364
00365
00376 class CV_EXPORTS_W BackgroundSubtractorMOG : public BackgroundSubtractor
00377 {
00378 public:
00380 CV_WRAP BackgroundSubtractorMOG();
00382 CV_WRAP BackgroundSubtractorMOG(int history, int nmixtures, double backgroundRatio, double noiseSigma=0);
00384 virtual ~BackgroundSubtractorMOG();
00386 virtual void operator()(const Mat& image, Mat& fgmask, double learningRate=0);
00387
00389 virtual void initialize(Size frameSize, int frameType);
00390
00391 Size frameSize;
00392 int frameType;
00393 Mat bgmodel;
00394 int nframes;
00395 int history;
00396 int nmixtures;
00397 double varThreshold;
00398 double backgroundRatio;
00399 double noiseSigma;
00400 };
00401
00402 }
00403 #endif
00404
00405 #endif