使用emgucv绘制关键点

时间:2015-07-01 07:31:49

标签: c# debugging matching emgucv

我在MS VisualStudio 2013上使用EmguCV和C# 我创建了一个包含多个图像描述符的XML文件,然后我将这些描述符(作为观察图像)与观察到的图像描述符(作为模型图像)进行匹配,以便查看正在使用哪些KeyPoints。 (反向匹配的种类)。

我有以下代码用于某些图像作为输入,有些我得到异常: 类型' System.ArgumentException'的第一次机会异常发生在mscorlib.dll

当我在分配了XX的行上创建断点时,所有变量都是正确的但是在一些迭代之后抛出了异常。 这是我的主要问题:为什么会出现一些图片?(不依赖于图片格式) 还有一件事奇怪的是,结果图片上KeyPoints的颜色并不像我预期的那样是纯红色(0,0,255)。谁能告诉我为什么?

这是我的代码:

SURFDetector surfCPU = new SURFDetector(500, false);  
Emgu.CV.Util.VectorOfKeyPoint observedKeyPoints;
Matrix<int> indices;
int k = 1;
// extract features from the observed image
observedKeyPoints = surfCPU.DetectKeyPointsRaw(imgGray, null);
Matrix<float> observedDescriptors = surfCPU.ComputeDescriptorsRaw(imgGray, null, observedKeyPoints);
BruteForceMatcher<float> matcher55 = new BruteForceMatcher<float>(DistanceType.L2);

matcher55.Add(observedDescriptors);
indices = new Matrix<int>(AgrObjectDescriptors.Rows, k);

using (Matrix<float> dist = new Matrix<float>(AgrObjectDescriptors.Rows, k))
{
    matcher55.KnnMatch(AgrObjectDescriptors, indices, dist, k, null);
    Debug.Write(matcher55);
}

/*The following is the problem part  */
int XX,YY;
Emgu.CV.Structure.Bgr KeyPointColor =  new Bgr(0, 0, 255);
MKeyPoint[] usedKeyP = observedKeyPoints.ToArray();
for (int i = 0; i < indices.Rows; i++) {
    XX = Convert.ToInt32(usedKeyP[indices[i, 0]].Point.X);
    YY = Convert.ToInt32(usedKeyP[indices[i, 0]].Point.Y);
    img99[XX, YY] = KeyPointColor;
}
/*Draw the image on WPF component image1*/
 image1.Source = BitmapSourceConvert.ToBitmapSource(img99);

1 个答案:

答案 0 :(得分:0)

检查描述符为空时是否收到异常。发生这种情况时,我遇到了类似的错误,所以请检查一下是否是原因。这可以解释为什么有些图像可以正常工作而有些图像无法正常工作,因为有些图像可能有很好的匹配而其