以下是我的代码的快照,
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()
我努力摆脱这种异常而没有希望:(
答案 0 :(得分:2)
我终于找到了这个问题的原因
它是modelKeyPoints或observedKeyPoints之一null:)
答案 1 :(得分:1)
与Zaher的答案非常相似 - 我的modelKeyPoints不为null,但它是空的(modelKeyPoints.Size == 0)。
使用不同的模型图像有帮助。