How to use the CV::EM class in OpenCV 2.4.2? -


got question on how use em algorithm in latest opencv 2.4.2. used use c version , worked fine, since system upgrade seems c api has been removed in opencv 2.4.2.

this simple case em: suppose have list of radius considered 2 kinds of balls , want estimate mean/variance of these 2 types. in other words, 1-d problem.

i tried write c++ version of em using new apis, haven't got working yet.

int nsamples = radius_list.size(); int ncluster = 2; //we assume bimodal model mat samples = mat::zeros(nsamples, 1, cv_32fc1); // init data (int = 0; < radius_list.size(); ++i) { int value = radius_list[i]; samples.at<float>(i, 0) = value; } em em_model = em(ncluster, em::cov_mat_spherical); if (!em_model.train(samples)) { cerr << "error training em model" << endl; exit(-1); } const mat& means = em_model.get<mat>("means"); int mean1 = means.at<float>(0, 0); int mean2 = means.at<float>(1, 0); cout << "mean1 = " << mean1 << ", mean2 = " << mean2 << endl; const vector<mat>& covs = em_model.get<vector<mat> >("covs"); int scale1 = covs[0].at<float>(0, 0); int scale2 = covs[1].at<float>(0, 0); cout << "scale1 = " << scale1 << ", scale2 = " << scale2 << endl; 

the problem is: although if() didn't complain, retrieved mean , scale values junk values, -2147483648 on machine.

please advise on how modify code make work. i'm still learning sorts of c++ apis in opencv.

thank all!

your doing implicit type conversions distracts compiler. mean, weights , covariance matrices not ints doubles (you can check printing mat.depth() result screen) change lines from:

int mean1 = means.at<float>(0, 0); 

like code to:

double mean1 = means.at<double>(0, 0); 

regards, rafal


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -