computer vision - SURF comparison code giving issues -
i doing surf comparison identify objects in images calculating euclidean distances between desriptors. following code isnt working. ipoint surf feature point, apreciated.
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; (int = 0; < 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; (int = 0; < 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; (int = 0; < 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()); }
should be:
double distance(ipoint a, ipoint b) { double dis = 0; (int = 0; < 64; i++) { dis += math.pow((a.descriptor[i] - b.descriptor[i]), 2); } return math.sqrt(dis); } you squaring , taking root of each difference, doing absolute value. try remember simple example of pythagoras: c=sqrt(a*a+b*b) , not c=sqrt(a*a)+sqrt(b*b)
Comments
Post a Comment