centos 7,opencv 3.0

代码:

//  1)创建查询树 :
Point2f p1(2,3),   p2(5,4),p3(9, 6),  p4(4,7),  p5(8,1),p6(7, 2);
  vector<cv::Point2f> source;
  source.push_back(p1);
  source.push_back(p2);
  source.push_back(p3);
  source.push_back(p4);
  source.push_back(p5);
  source.push_back(p6);
   source.push_back(Point2f(1,1.5));
  flann::KDTreeIndexParams indexParams(2);
  flann::Index kdtree(cv::Mat(source).reshape(1), indexParams);

//  2) 查找 :
  vector<float> query;
  Point2f pt(0.1,1);
  query.push_back(pt.x);
  query.push_back(pt.y);
  int k = 1; //number of nearest neighbors
  vector<int> indices(k);//找到点的索引
  vector<float> dists(k);

  flann::SearchParams params(128);
  kdtree.knnSearch(query, indices, dists, k,params);
  cout<<indices[0]<<endl;
   cout<<indices[1]<<endl;
   cout<<indices[2]<<endl;
    cout<<indices[3]<<endl;

其它:
http://www.cs.ubc.ca/research/flann/
http://www.cnblogs.com/eyeszjwang/articles/2429382.html
http://www.bubuko.com/infodetail-1185412.html

C++ 源码:https://github.com/jtsiomb/kdtree

http://blog.csdn.net/daringpig/article/details/7652891

http://www.cnblogs.com/eyeszjwang/articles/2432465.html

https://github.com/tamarous/KD_Tree
http://www.tamarous.com/2015/12/10/k-d-tree-%E7%AE%97%E6%B3%95%E5%8F%8A%E5%85%B7%E4%BD%93%E5%AE%9E%E7%8E%B0%E4%BB%A3%E7%A0%81/

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐