我已经浏览了问题、源代码和其他示例,但我无法理解 Distance d = Distance()
的含义。函数中参数的含义
它在 this question 的评论中得到解决,但我在任何地方都找不到距离类型。我导入了以下文件:
#include "opencv2/contrib/contrib.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/video/tracking.hpp"
#include "opencv2/nonfree/features2d.hpp"
#include "opencv2/flann/flann.hpp"
我检查了cv
, cvflann
,和cv::flann
命名空间并且找不到任何东西。
这是我的代码:
int tmp = cv::flann::hierarchicalClustering<cv::L2<float>>(descriptors, centers, params, ______ );
显然 ___ 是最后一个参数所在的位置。我尝试过类似 cv::L2<float>()
但这也行不通。
在源代码中它看起来像一个模板。
我也尝试过:
int tmp = cv::flann::hierarchicalClustering<float, float>(descriptors, centers, params);
并且我收到错误“没有重载函数“cv::flann::hierachicalClustering”的实例与参数列表匹配。参数类型为:(cv::Mat、cv::Mat、cv::KMeansIndexParams)。
我使用的是 OpenCV 2.4.11。
有什么想法吗?
FLANN user manual 中还有更多文档。看起来它是被逐字复制到 OpenCV 中的。
最佳答案
参数Distance d = Distance()
是设置距离算法的默认方法参数。通常,这将是 FLANN_DIST_L2
。为什么你在任何地方都找不到“距离”“类型”,因为它实际上是一个"typename"。 OpenCV 选择使用 C++ 专门化(通过模板)而不是继承,以确保不同的距离函数具有相同的特征。
这是一个不平凡的主题,所以http://www.gotw.ca/publications/mxc++-item-4.htm应该提供一个相当轻松的介绍。如果我激起了您的兴趣,请查看 Andrei Alexandrescu 的开创性著作 Modern C++ Design .
关于c++ - OpenCV层次聚类函数中的参数 `Distance d = Distance()`是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29665763/