混合高斯背景建模原理:
代码:
#include<opencv2/highgui.hpp>
#include<opencv2/core.hpp>
#include<opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main()
{
CvCapture*capture = cvCreateFileCapture("C:\\Users\\aoe\\Desktop\\avi\\walk.avi");//读取视频
IplImage*mframe = cvQueryFrame(capture);//读取视频中的一帧
int height = mframe->height;
int width = mframe->width;
int C = 4;//number of gaussian components
int M = 4;//number of background components
int std_init = 6;//initial standard deviation
double D = 2.5;
double T = 0.7;
double alpha = 0.01;
double p = alpha / (1 / C);
double thresh = 0.25;
int min_index = 0;
int*rank_ind=0;
int i, j,k,m;
int rand_temp=0;
int rank_ind_temp = 0;
CvRNG state;
IplImage*current = cvCreateImage(cvSize(mframe->width, mframe->height), IPL_DEPTH_8U, 1);
IplImage*test = cvCreateImage(cvSize(mframe->width, mframe->height), IPL_DEPTH_8U, 1);
IplImage*frg = cvCreateImage(cvSize(mframe->width, mframe->height), IPL_DEPTH_8U, 1);
double*mean = (double*)malloc(sizeof(double)*width*height*C);//pixelmeans
double*std = (double*)malloc(sizeof(double)*width*height*C);//pixel standard deviations
double*w = (double*)malloc(sizeof(double)*width*height*C);//权值
double*u_diff =