OpenCV 的 hierachicalClustering 函数中的参数 'Distance d = Distance()' 是什么?
What is the parameter `Distance d = Distance()` in OpenCV's hierachicalClustering function?
我已经看过问题、源代码和其他示例,但我一辈子都无法理解Distance d = Distance()
参数在函数中的含义
template<typename Distance> int flann::hierarchicalClustering(const Mat& features, Mat& centers, const cvflann::KMeansIndexParams& params, Distance d=Distance())
这个问题的评论中已经提到了,但我在任何地方都找不到"距离"类型。我导入了以下文件:
#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用户手册中还有更多文档。看起来它是逐字复制到OpenCV中的。
参数Distance d = Distance()
是设置距离算法的默认方法参数。通常,这将是FLANN_DIST_L2
。为什么在任何地方都找不到Distance
"类型",是因为它实际上是一个typename
。OpenCV选择使用C++专门化(通过模板)而不是继承,以确保不同的距离函数具有相同的特性。
这是一个不平凡的话题,所以http://www.gotw.ca/publications/mxc++-item-4.htm应该提供一个相当轻松的介绍。如果我能激起你的兴趣,可以看看安德烈·亚历山德雷斯库开创性的现代C++设计。
添加这个以供将来参考,因为我自己只是在为OpenCV FLANN类而挣扎
这对我有效:
// define parameters
cvflann::KMeansIndexParams kmeansParams(10, 100, cvflann::FLANN_CENTERS_KMEANSPP);
// note cvflann - not cv::flann - namespace there
int nClusters = flann::hierarchicalClustering<flann::L2<float>>(samples, centers, kmeansParams );
// note regular flann namespace here
问题是marcman使用的是<cv::L2<float>>
而不是<flann::L2<float>>
flann名称空间非常混乱,并且文档中缺少
而且由于模板化,在IDE中很难弄清楚。
- 为不同配置设置MSVC_RUNTIME_LIBRARY的正确方法是什么
- C++避免重复声明的语法是什么
- 在C++中,将大的无符号浮点数四舍五入为整数的最佳方法是什么
- 实现无开销push_back的最佳方法是什么
- C++从另一个类访问公共静态向量的正确方法是什么
- "throw expression code" 1e7 >返回 d 是什么?投掷标准::overflow_error( "too big" ) : d;意味 着?
- C++中名称篡改的目的是什么
- 在 c++ 中拥有一组结构的正确方法是什么?
- 这个指针和内存代码打印是什么?我不知道是打印垃圾还是如何打印我需要的值
- 是什么阻止DOMTimerCoordinator::NextID进入无休止的循环
- 派生类销毁的最佳实践是什么
- 这个语法std::class<>{}(arg1, arg2) 在C++中是什么意思?
- 通过JNI传递数据数组的最快方法是什么
- "using namespace std;"在C++的作用是什么?
- 在两台机器之间进行时间戳的最佳c++chrono函数是什么
- 文件系统:复制功能的速度秘诀是什么
- 用常见虚拟函数实现的任意组合来实现派生类的正确方法是什么
- 使用QQuickFramebufferObject时同步数据的最佳方式是什么
- 这句话是什么意思 - " vector<long long> distance(n, std::numeric_limits<long long>::max()); "?
- OpenCV 的 hierachicalClustering 函数中的参数 'Distance d = Distance()' 是什么?