0

我正在使用 opencv EM 算法借助 opencv 文档中的示例代码获取 GMM 模型,如下所示:

cv::Mat capturedFrame
const int N = 5; 
int nsamples = 100;
cv::Mat samples ( nsamples, 2, CV_32FC1 );
samples = samples.reshape ( 2, 0 );
cv::Mat sample ( 1, 2, CV_32FC1 );
CvEM em_model;
CvEMParams params;

for ( i = 0; i < N; i++ )
{           
//from the training samples
cv::Mat samples_part = samples.rowRange ( i*nsamples/N, (i+1)*nsamples/N);
cv::Scalar mean (((i%N)+1)*img.rows/(N1+1),((i/N1)+1)*img.rows/(N1+1));
cv::Scalar sigma (30,30);
cv::randn(samples_part,mean,sigma);                     

}
samples = samples.reshape ( 1, 0 );
//initialize model parameters
params.covs         = NULL;
params.means        = NULL;
params.weights      = NULL;
params.probs        = NULL;
params.nclusters    = N;
params.cov_mat_type = CvEM::COV_MAT_SPHERICAL;
params.start_step   = CvEM::START_AUTO_STEP;
params.term_crit.max_iter = 300;
params.term_crit.epsilon  = 0.1;
params.term_crit.type   = CV_TERMCRIT_ITER|CV_TERMCRIT_EPS;     
//cluster the data
em_model.train ( samples, Mat(), params, &labels );

作为 GMM 和 openCV 的新手,现在我有一些问题:

首先,在执行上述代码后,我可以得到如下问题:

cv::Mat probs = em_model.getProbs();

那么如何才能得到元素最多和最少的模型,即最大和最小的模型呢?

其次,我的样本数据在这里只有100,就像opencv的示例代码一样,但是我正在读取一个大小为600x800的帧,我想对其中的所有像素进行采样,即480000。但是大约需要10毫秒这 100 个样本,这意味着如果我设置它会太慢:

int nsamples = 480000;

我在这里走对了吗?

4

1 回答 1

1

如果我的问题是正确的,那么您所说的“最大”和“最小”模型是指混合物中每个高斯的权重。您可以使用 获取与高斯相关的权重EM::getWeights

Concerning second question, if you train your model using 480000 samples instead of 100, yes, it will be definitely longer. Being "too slow" depends on your requirements. But EM is a classification model, so what is usually done is that you must train the model, using a sufficient amount of sample. This is a long process, but usually done "offline". Then, you can use the model to "predict" new samples, i.e. get the probabilities associated with new input samples. When you call getProbs() function, you get the probabilities associated with your training samples. If you want to get probabilities for unknown samples, typically pixels in your video frame, call the function predict.

于 2012-10-16T07:56:39.723 回答