Computer vision 冲浪比较代码给出问题

Computer vision 冲浪比较代码给出问题,computer-vision,Computer Vision,我正在进行SURF比较,通过计算描述器之间的欧几里德距离来识别图像中的对象。但是下面的代码不起作用。IPoint是一个冲浪功能点,任何帮助都值得一提 List<IPoint> ipts = new List<IPoint>(); Dictionary<string, List<IPoint>> objs = new Dictionary<string, List<IPoint>>(); double distance(IP

我正在进行SURF比较,通过计算描述器之间的欧几里德距离来识别图像中的对象。但是下面的代码不起作用。IPoint是一个冲浪功能点,任何帮助都值得一提

 List<IPoint> ipts = new List<IPoint>();
Dictionary<string, List<IPoint>> objs = new Dictionary<string, List<IPoint>>();
double distance(IPoint a, IPoint b)
{
    double dis = 0;
    for (int i = 0; i < 64; i++)
    {

        dis += Math.Sqrt(Math.Pow((a.descriptor[i] - b.descriptor[i]), 2));
    }
    return (dis);
}
bool matchpoint(IPoint a, List<IPoint> l, out string e)
{
    e = "";
    double smallest = double.MaxValue;
    string s = string.Empty;
    for (int i = 0; i < l.Count; i++)
    {
        var d = distance(a, l[i]);
        if (d < smallest)
        {
            smallest = d;
            s = i.ToString();
        }
    }
    if (smallest < 0.5)
    {
        e = s;
        return true;
    }
    else
    {
        return false;// null;
    }
    return false;
}
string match(out double per)
{
    string h;
    Dictionary<string, double> torn = new Dictionary<string, double>();
    foreach (string s in objs.Keys.ToList())
    {
        int count = 0;
        for (int i = 0; i < objs[s].Count; i++)
        {
            if (matchpoint(objs[s][i], ipts,out h))
            {
                count++;
            }
        }
        torn[s] = count / objs[s].Count;
        count = 0;
    }
    string smalln = "";
    double smallest = double.MaxValue;
    foreach (string s in torn.Keys.ToList())
    {
        if (torn[s] < smallest)
        {
            smallest = torn[s];
            smalln = s;
        }
    }
    per = smallest;
    return smalln;
}
private void button1_Click(object sender, EventArgs e)
{
    double d;
    match(out d);
    MessageBox.Show(match(out d) + " " + d.ToString());
}
List ipts=new List();
Dictionary objs=新字典();
双倍距离(I点a、I点b)
{
双dis=0;
对于(int i=0;i<64;i++)
{
dis+=Math.Sqrt(Math.Pow((a.descriptor[i]-b.descriptor[i]),2));
}
返回(dis);
}
布尔匹配点(I点a、列表l、输出字符串e)
{
e=“”;
最小值加倍=最大值加倍;
string s=string.Empty;
对于(int i=0;i
应该是:

double distance(IPoint a, IPoint b)
{
    double dis = 0;
    for (int i = 0; i < 64; i++)
    {

        dis += Math.Pow((a.descriptor[i] - b.descriptor[i]), 2);
    }
    return Math.Sqrt(dis);
}
双倍距离(i点a、i点b)
{
双dis=0;
对于(int i=0;i<64;i++)
{
dis+=Math.Pow((a.描述符[i]-b.描述符[i]),2);
}
返回Math.Sqrt(dis);
}

你要平方,然后求每个差的根,基本上就是做一个绝对值。试着记住毕达哥拉斯的一个简单的例子:
C=SQRT(A*A+B*B)
而不是
C=SQRT(A*A)+SQRT(B*B)

谢谢你的帮助,同时考虑两个距离的比率也非常有效。我在这里发布工作代码,因为你在其他地方找不到这个问题的答案

void getMatches(List<IPoint> ipts1, List<IPoint> ipts2,out List<IPoint> mats)
{
    List<IPoint> matches = new List<IPoint>();
    float dist, d1, d2;
    IPoint match;
    matches.Clear();

    for(int i = 0; i < ipts1.Count; i++)
    {
        d1 = d2 = float.MaxValue;
        for(int j = 0; j < ipts2.Count; j++) 
        {
            dist = (float)distance(ipts1[i], ipts2[j]);//ipts1[i] - ipts2[j];  
            if(dist<d1)  // if this feature matches better than current best
            {
                d2 = d1;
                d1 = dist;
                match = ipts2[j];
            }
            else if(dist<d2) // this feature matches better than second best
            {
                d2 = dist;
            }
        }

        // If match has a d1:d2 ratio < 0.65 ipoints are a match
        if(d1/d2 < Convert.ToSingle(textBox2.Text)) 
        {
            matches.Add(ipts1[i]);
        }
    }

    mats = matches;  
}
void getMatches(列出ipts1、列出ipts2、列出mats)
{
列表匹配项=新列表();
浮动区,d1,d2;
i点匹配;
匹配。清除();
对于(int i=0;i