Android Opencv EM Fatal Error
I'm trying to use EM::predict2(sample, probs) to predict if a pixel is part of a leaf or not; however, I'm getting the error:
CvException [org.opencv.core.CvException: cv::Exception: /build/master_pack-android/opencv/modules/ml/src/em.cpp:569: error: (-215) sample.size() == Size(means.cols, 1) in function cv::Vec2d cv::ml::EMImpl::computeProbabilities(const cv::Mat&, cv::Mat*, int) const]
When I'm calling:
Mat probs = new Mat(imgHSV.rows(), em.getClustersNumber(), CvType.CV_32FC1);
Mat mPredict = new Mat(1, 2, CvType.CV_8UC1);
mPredict.put(0,0,imgHSV.get(i,j)[1]);
mPredict.put(0,1,imgHSV.get(i,j)[2]);
double[] probabilities = em.predict2(mPredict, probs);
To clarify some points, I'm showing below the pseudocode that I was trying to follow:
stackedPixels ← ∅
for all pixelRow in image do
for all pixel in pixelRow do
stackedPixels ← stackedPixels ∪ pixel
end for
end for
EM ← OpenCV.EM(nClusters = 2, covMatT ype = OpenCV.DIAGONAL)
EM.train(stackedPixels)
return EM
key ← hash(pixel[S], pixel[V])
if hash in pixelDictionary then
return pixelDictionary[key]
end if
probabilities ← EM.predict(pixel[S], pixel[V])
pixelDict[key] = probabilities[0] > probabilities[1]
return pixelDict[key]