void Recoloring::TrainGMM(CvEM& source_model, Mat& source, Mat& source_mask) { int src_samples_size = countNonZero(source_mask); Mat source_samples(src_samples_size,3,CV_32FC1); Mat source_32f; //if(source.type() != CV_32F) // source.convertTo(source_32f,CV_32F,1.0/255.0); //else source_32f = source; int sample_count = 0; for(int y=0;y<source.rows;y++) { Vec3f* row = source_32f.ptr<Vec3f>(y); uchar* mask_row = source_mask.ptr<uchar>(y); for(int x=0;x<source.cols;x++) { if(mask_row[x] > 0) { source_samples.at<Vec3f>(sample_count++,0) = row[x]; } } } source_model.clear(); CvEMParams ps(1/* = number of gaussians*/); source_model.train(source_samples,Mat(),ps,NULL); }
void Model::Train_em( const SampleSet& samples ) { CvEM* model = (CvEM*)m_pModel; CvEMParams* para = (CvEMParams*)m_trainPara; para->nclusters = samples.Classes().size(); model->train(samples.Samples()); }