OpenCV的:如何分类GMM计算probs [英] OpenCV: how to categorize GMM calculated probs

查看:482
本文介绍了OpenCV的:如何分类GMM计算probs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用OpenCV的EM算法获得与例如code的OpenCV的文档中的帮助GMM模型如下:

I am using opencv EM algorithm to obtain GMM models with the help of example code in opencv documentation as follows:

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,现在我有一些问题:

As being a fresh to GMM and openCV, now I have some questions:

首先后,执行上述code后,我可以得到probs,如:

Firstly, after performing above code, I can get the probs like:

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

那么如何才能得到这些具有最多和最少的元素模型,就是最大的和最小的车型?

Then how can I get the models which are having the most and least elements, that is, the biggest and smallest models?

其次,我的样本数据只有100在这里,因为在OpenCV中的例子code,但我读一帧大小600X800,我想品尝所有的像素它,这是480000.但是,它需要大约10毫秒这100个样品,这意味着如果我设置这将是太缓慢:

Secondly, my sample data is only 100 here, as in the example code of opencv, but I am reading a frame with size 600x800, and I want to sample all those pixels in it, which is 480000. But it takes about 10 ms for these 100 samples, that means it would be too much slow if I set:

int nsamples = 480000;

我是放在这里的正确方法?

Am I on the right way here?

推荐答案

如果我得到你的问题的权利,你所说的最大和最小模式是指在混合物中各高斯的权重。你可以得到相关的高斯权使用 EM :: getWeights

If I get your question right, what you call your "biggest" and "smallest" models refers to the weights of each gaussian in the mixture. You can get the weights associated to the gaussians using EM::getWeights.

关于第二个问题,如果你使用480000的样品,而不是100训练模型,是的,这肯定会有更长。作为太慢取决于您的要求。但是EM是一个分类模型,还等什么,通常做的是,你必须训练模型,采用样本足够量。这是一个漫长的过程,但通常做的脱机。然后,您可以使用该模型为predict新样本,即得到了新的输入样本有关的概率。当你调用 getProbs()的功能,你就会得到你的训练样本相关联的概率。如果你想获得未知样品的概率,一般像素的视频帧,调用函数的 predict

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.

这篇关于OpenCV的:如何分类GMM计算probs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆