4

I was just wondering how this function CvBGStatModel() works. I mean to say what is the algorithm used for this and how it gives better results compared to average and frame difference algorithms.

Thanks in advance.

Jav_Rock
  • 22,059
  • 20
  • 123
  • 164

1 Answers1

3

CvBGStatModel() is a class, not a function. For example, you can create this class like this:

IplImage* temp = NULL;
temp = cvLoadImage( "temp.jpg" );
CvBGStatModel* background_model = cvCreateGaussianBGModel(temp);

You have to call a function in order to update the background/foreground model (see sample):

cvUpdateBGStatModel( temp, background_model );

"how it gives better results compared to average and frame difference algorithms"

Because it stores pixel information as a mixture of the Gaussian Distributions that better represent that pixel. This means that a pixel that changes its value during a couple of frames won't be consider foreground as long as the Gaussians that better represent it are consider background. Gaussians are weighted. The longest a gaussian distribution was considered background, the more weight it has. The frame difference algorithm only considers difference between frames, but not how consistent/trustable these differences are.

Jav_Rock
  • 22,059
  • 20
  • 123
  • 164
  • And i had another doubt, i'm using opencv 2.0 and this class is not available in it, so kindly can you tell me which version i should be using for this? Thanks for your timely answer.It was really helpful.. Also i'm trying to count the number of cars in video..my algorithm is based on detection of rectangles but sadly it counts a single car to be made up of 3 rectangles hence the result is not the required one..Can anyone help me to improve this algorithm or any better algorithm is always welcome..Thanks in advance. – user1386438 Jun 01 '12 at 08:04
  • I suggest you that always use the latest version of OpenCV. I use 2.3.1 but 2.4 is available now. If you don't have this class available you will for sure have the equivalent, improved interface one: http://docs.opencv.org/modules/video/doc/motion_analysis_and_object_tracking.html?highlight=background#backgroundsubtractormog2 – Jav_Rock Jun 01 '12 at 08:34
  • and can you suggest something about algorithm?? – user1386438 Jun 01 '12 at 08:43
  • better make another question for the algortihm and linked it from here. They are different things and it clearer in different questions. I believe that the approach using rectangles is not apropiate, I will look for the common method for this case. – Jav_Rock Jun 01 '12 at 08:52