Android Opencv EM致命错误

时间:2017-08-08 18:29:44

标签: android opencv

我正在尝试使用 EM :: predict2(sample,probs)来预测像素是否是叶子的一部分;但是,我收到了错误:

  

CvException [org.opencv.core.CvException:cv :: Exception:/build/master_pack-android/opencv/modules/ml/src/em.cpp:569:error:( - 1515)sample.size() ==函数cv :: Vec2d中的大小(means.cols,1)cv :: ml :: EMImpl :: computeProbabilities(const cv :: Mat&,cv :: Mat *,int)const]

当我打电话时:

Mat mPredict = new Mat(1, 1, CvType.CV_8UC1);
Mat mLabel = new Mat(1, 1, CvType.CV_8UC1);
mPredict.put(0,0,imgHSV.get(i,j)[1]);
mLabel.put(0,0,imgHSV.get(i,j)[2]);

double[] probabilities = em.predict2(mPredict, mLabel);

为了澄清一些观点,我在下面展示了我试图遵循的伪代码:

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]

1 个答案:

答案 0 :(得分:0)

什么版本的opencv?他们最近改变了方法。 也许你可以先尝试一下?这基于v3.1.0 https://github.com/sonnyky/OpenCVEM

我正在玩OpenCV EM,并设法让它在n个集群中对像素进行分类。它仍然在进步中,所以请原谅凌乱的代码:)