I am using cvEm for Gaussian Mixture modeling on a 2D data. After calling the train function it returns True (signing a successful training) and also classification results (having different clusters in different colors) seem reasonable, but I get an access violation error while getting co-variance matrices of clusters!
Following is the related lines of code:
CvEMParams params;
params.covs = NULL;
params.means = NULL;
params.weights = NULL;
params.probs = NULL;
params.nclusters = NrGMMComponents;
params.cov_mat_type = CvEM::COV_MAT_GENERIC; // DIAGONAL, GENERIC, SPHERICAL
params.start_step = CvEM::START_AUTO_STEP;
params.term_crit.max_iter = 300;
params.term_crit.epsilon = 0.001;
params.term_crit.type = CV_TERMCRIT_ITER|CV_TERMCRIT_EPS;
//params.term_crit.type = CV_TERMCRIT_ITER;
// 2.2 Estimate GMM params for all <NrGMMComponents> Gaussian Mixture Components
CvEM em_model;
bool result = em_model.train( samples, Mat(), params, &labels);
vector<cv::Mat> covs;
em_model.getCovs(covs); ////////////Access Violation here! :(
I found another member function in CvEm called get_covs()
and it worked!
But I still do not know what's wrong with the getCov()
function.