Ask Your Question

Revision history [back]

ML::EM with multiple Features

Hello

I have a float[33] sized feature vector derived from pcl (Point Cloud Library). I would like to perform a Gaussian Mixture Model on this and found that OpenCV has this implemented in ML::EM.

I use OpenCV 3.0. Now unfortunately the EM model needs a one channel matrix. Does this mean I can only calculate a one dimensional Model? I have 33 features, not only one.

Here is my class where I convert my pcl feature PointCloud to OpenCV:

FPFHtoCV::FPFHtoCV(pcl::PointCloud<pcl::FPFHSignature33>::Ptr fpfhs)
{
   cv::Mat openCVPointCloud( fpfhs->points.size(), 1, CV_32FC(33));
    for(int i=0; i < fpfhs->points.size();i++)
   {
       pcl::FPFHSignature33 p = fpfhs->points.at(i);
       for(size_t j = 0; j < 33; j++)
       {
           openCVPointCloud.at<cv::Vec<float,33> >(1,0)[j] = p.histogram[j];
       }
    }
   _mat = openCVPointCloud;
}

And here how I try to run the GMM on the OpenCV matrix.

    FPFHtoCV ftc(fpfhs);
    cv::Mat mat = ftc.mat();
    cv::Ptr<cv::ml::EM> source_model = cv::ml::EM::create();
    source_model->setClustersNumber(6);
    cv::Mat logs;
    cv::Mat labels;
    cv::Mat probs;
    source_model->trainEM(mat,logs,labels,probs);

It does not work of course, as there is more than one channel.