Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

please use float Mat's here (it seems it can't handle anything else), also do not pre-allocate your indices & dists for the radiusSearch():

  cv::Mat_<float> features(0,2);

  for(auto && point : points) {

    //Fill matrix
    cv::Mat row = (cv::Mat_<float>(1, 2) << point.x, point.y);
    features.push_back(row);
  }
  std::cout << features << std::endl;

  cv::flann::Index flann_index(features, cv::flann::KDTreeIndexParams(1));


  unsigned int max_neighbours = 10;
  cv::Mat query = (cv::Mat_<float>(1, 2) << 313.0, 245.6);
  cv::Mat indices, dists; //neither assume type nor size here !
  double radius= 2.0;

  flann_index.radiusSearch(query, indices, dists, radius, max_neighbours,
      cv::flann::SearchParams(32));

  cerr << indices.type() << endl << indices << endl;
  cerr << dists.type() << endl << dists << endl;

4
[6, 4, 5, 12, 7, 0, 0, 0, 0, 0]
5
[0.020002441, 0.099993892, 0.1699933, 0.2, 0.29000488, 0, 0, 0, 0, 0]