且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

OpenCV:Flann匹配器崩溃

更新时间:2023-01-11 08:40:34

可能您已尝试使用KD-Tree或KMeans?它们仅适用于CV_32F描述符,例如SIFT或SURF. 对于像BRIEF \ ORB \ FREAK这样的二进制描述符,您必须使用LSH或Hierarchical clustering index.或简单的蛮力搜索. 您可以自动管理它,例如这样.

Probably you have tried to use KD-Tree or KMeans? They works only for CV_32F descriptors like SIFT or SURF. For binary descriptors like BRIEF\ORB\FREAK you have to use either LSH or Hierarchical clustering index. Or simple bruteforce search. You can manage it automatically, for example like this.

cv::flann::Index GenFLANNIndex(cv::Mat keys)
{
  switch (keys.type())
    {
    case CV_32F:
      {
        return  cv::flann::Index(keys,cv::flann::KDTreeIndexParams(4));
        break;
       }
    case CV_8U:
      {
        return cv::flann::Index(keys,cv::flann::HierarchicalClusteringIndexParams(),dist_type);
        break;
      }
    default:
      {
        return cv::flann::Index(keys,cv::flann::KDTreeIndexParams(4));
        break;
      }
    }

}
...
cv::flann::Index tree = GenFLANNIndex(descriptors);