EMGU 2.4.0 BruteForceMatcher KNNMATCH无法正常工作?

时间:2012-11-14 14:44:46

标签: c# image-processing opencv emgucv

以下是我的代码的快照,

Matrix<byte> mask;
int k = 2;
VectorOfKeyPoint modelKeyPoints;
VectorOfKeyPoint observedKeyPoints;
SURFDetector surfCPU = new SURFDetector(500, false);
modelKeyPoints = surfCPU.DetectKeyPointsRaw(modelImage, null);
Matrix<float> modelDescriptors = surfCPU.ComputeDescriptorsRaw(modelImage, null, modelKeyPoints);
observedKeyPoints = surfCPU.DetectKeyPointsRaw(observedImage, null);
Matrix<float> observedDescriptors = surfCPU.ComputeDescriptorsRaw(observedImage, null, observedKeyPoints);
BruteForceMatcher<float> matcher = new BruteForceMatcher<float>(DistanceType.L2);
matcher.Add(modelDescriptors);
indices = new Matrix<int>(observedDescriptors.Rows, k);
using (Matrix<float> dist = new Matrix<float>(observedDescriptors.Rows, k))
{
      matcher.KnnMatch(observedDescriptors, indices, dist, k, null);
}

我总是在KnnMatch()

中得到以下异常

发生了Emgu.CV.Util.CvException 消息:OpenCV:queryDescriptors.type()== trainDescCollection [0] .type()

我努力摆脱这种异常而没有希望:(

2 个答案:

答案 0 :(得分:2)

我终于找到了这个问题的原因

它是modelKeyPoints或observedKeyPoints之一null:)

答案 1 :(得分:1)

与Zaher的答案非常相似 - 我的modelKeyPoints不为null,但它是空的(modelKeyPoints.Size == 0)。

使用不同的模型图像有帮助。