Lines Matching refs:bg_model
112 static void icvBackgroundTest( const int nChannels, int n, int i, int j, int *match, CvGaussBGModel* bg_model );
114 static void CV_CDECL icvReleaseGaussianBGModel( CvGaussBGModel** bg_model );
115 static int CV_CDECL icvUpdateGaussianBGModel( IplImage* curr_frame, CvGaussBGModel* bg_model );
138 CvGaussBGModel* bg_model = 0;
169 CV_CALL( bg_model = (CvGaussBGModel*)cvAlloc( sizeof(*bg_model) ));
170 memset( bg_model, 0, sizeof(*bg_model) );
171 bg_model->type = CV_BG_MODEL_MOG;
172 bg_model->release = (CvReleaseBGStatModel)icvReleaseGaussianBGModel;
173 bg_model->update = (CvUpdateBGStatModel)icvUpdateGaussianBGModel;
175 bg_model->params = params;
178 CV_CALL( bg_model->g_point = (CvGaussBGPoint*)cvAlloc(sizeof(CvGaussBGPoint)*
181 CV_CALL( bg_model->background = cvCreateImage(cvSize(first_frame->width,
183 CV_CALL( bg_model->foreground = cvCreateImage(cvSize(first_frame->width,
186 CV_CALL( bg_model->storage = cvCreateMemStorage());
190 CV_CALL( bg_model->g_point[0].g_values =
200 bg_model->g_point[n].g_values =
201 bg_model->g_point[0].g_values + n*params.n_gauss;
202 bg_model->g_point[n].g_values[0].weight = 1; //the first value seen has weight one
203 bg_model->g_point[n].g_values[0].match_sum = 1;
206 bg_model->g_point[n].g_values[0].variance[m] = var_init;
207 bg_model->g_point[n].g_values[0].mean[m] = (unsigned char)first_frame->imageData[p + m];
211 bg_model->g_point[n].g_values[k].weight = 0;
212 bg_model->g_point[n].g_values[k].match_sum = 0;
214 bg_model->g_point[n].g_values[k].variance[m] = var_init;
215 bg_model->g_point[n].g_values[k].mean[m] = 0;
221 bg_model->countFrames = 0;
227 CvBGStatModel* base_ptr = (CvBGStatModel*)bg_model;
229 if( bg_model && bg_model->release )
230 bg_model->release( &base_ptr );
232 cvFree( &bg_model );
233 bg_model = 0;
236 return (CvBGStatModel*)bg_model;
252 CvGaussBGModel* bg_model = *_bg_model;
253 if( bg_model->g_point )
255 cvFree( &bg_model->g_point[0].g_values );
256 cvFree( &bg_model->g_point );
259 cvReleaseImage( &bg_model->background );
260 cvReleaseImage( &bg_model->foreground );
261 cvReleaseMemStorage(&bg_model->storage);
262 memset( bg_model, 0, sizeof(*bg_model) );
271 icvUpdateGaussianBGModel( IplImage* curr_frame, CvGaussBGModel* bg_model )
277 bg_model->countFrames++;
289 CvGaussBGPoint* g_point = &bg_model->g_point[n];
290 const CvGaussBGStatModelParams bg_model_params = bg_model->params;
298 if( bg_model->countFrames >= bg_model->params.win_size )
300 icvUpdateFullWindow( pixel, nChannels, match, g_point, &bg_model->params );
312 icvBackgroundTest( nChannels, n, i, j, match, bg_model );
319 cvClearMemStorage(bg_model->storage);
321 //cvMorphologyEx( bg_model->foreground, bg_model->foreground, 0, 0, CV_MOP_OPEN, 1 );
322 //cvMorphologyEx( bg_model->foreground, bg_model->foreground, 0, 0, CV_MOP_CLOSE, 1 );
324 cvFindContours( bg_model->foreground, bg_model->storage, &first_seq, sizeof(CvContour), CV_RETR_LIST );
328 if( cnt->rect.width * cnt->rect.height < bg_model->params.minArea )
348 bg_model->foreground_regions = first_seq;
349 cvZero(bg_model->foreground);
350 cvDrawContours(bg_model->foreground, first_seq, CV_RGB(0, 0, 255), CV_RGB(0, 0, 255), 10, -1);
575 static void icvBackgroundTest( const int nChannels, int n, int i, int j, int *match, CvGaussBGModel* bg_model )
580 CvGaussBGPoint* g_point = bg_model->g_point;
583 bg_model->background->imageData[ bg_model->background->widthStep*i + j*nChannels + m] = (unsigned char)(g_point[n].g_values[0].mean[m]+0.5);
585 for( b = 0; b < bg_model->params.n_gauss; b++)
590 if( weight_sum > bg_model->params.bg_threshold )
594 bg_model->foreground->imageData[ bg_model->foreground->widthStep*i + j] = pixelValue;