在 OpenCV 中实现词汇树

发布于 2024-11-04 04:51:40 字数 254 浏览 1 评论 0原文

我正在尝试基于论文“Scalable Recognition with a Vocabulary Tree”来实现图像搜索。我正在使用 SURF 来提取特征和关键点。例如,对于一张图像,我得到 300 个关键点,每个关键点有 128 个描述符值。我的问题是如何在数据上应用 K 均值聚类算法。我的意思是我是否需要对所有点(即 300*128 值)应用聚类算法,或者我是否需要找到连续描述符值之间的距离并存储这些值并对其应用聚类算法。我很困惑,任何帮助将不胜感激。

谢谢, 洛基。

I am trying to implement image search based on paper "Scalable Recognition with a Vocabulary Tree". I am using SURF for extracting the features and key points. For example, for an image i'm getting say 300 key points and each key point has 128 descriptor values. My Question is how can I apply the K-Means Clustering algorithm on the data. I mean Do I need to apply clustering algorithm on all the points i.e., 300*128 values or Do I need to find the distance between the consecutive descriptor values and store the values and apply the clustering algorithm on that. I am confused and any help will be appreciated.

Thanks,
Rocky.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

残疾 2024-11-11 04:51:40

从你的问题来看,我想说你很困惑。词汇树技术基于使用 k-means 分层聚类和叶节点的 TF-IDF 加权方案。

简而言之,用于构建词汇树的聚类算法对所有 d 维 数据(对于 SIFT 的情况,d=128)运行一次 k 均值,然后对每个获得的簇再次运行 k 均值,直到某个深度级别。因此,词汇树构建的两个主要参数是分支因子k和树深度L。一些改进仅考虑分支因子,而深度是通过切割树来自动确定的,以满足最小方差度量。

至于实现,OpenCV 的 cv::BOWTrainer 是一个很好的起点,但对于分层 BoW 方案的情况并没有很好的概括,因为它强制将中心存储在一个简单的 中。 >cv::Mat 虽然词汇树通常是不平衡的,并且当节点数量远低于理论数量时,从内存使用的角度来看,以逐级方式将其映射到矩阵可能效率不高深度L和分支因子k的平衡树中的节点数,即:

n << (1-k^L)/(1-k)

From your question I would say you are quite confused. The vocabulary tree technique is grounded on the us of k-means hierarchical clustering and a TF-IDF weighting scheme for the leaf nodes.

In a nutshell the clustering algorithm employed for the vocabulary tree construction runs k-means once over all the d-dimensional data (d=128 for the case of SIFT) and then runs k-means again over each of the obtained clusters until some depth level. Hence the two main parameters for the vocabulary tree construction are the branching factor k and the tree depth L. Some improvements consider only the branching factor while the depth is automatically determined by cutting the tree to fulfill a minimum variance measure.

As for the implementation, cv::BOWTrainer from OpenCV is a good starting point though is not very well generalized for the case of a hierarchical BoW scheme since it imposes the centers to be stored in a simple cv::Mat while vocabulary tree is typically unbalanced and mapping it to a matrix in a level-wise fashion might not be efficient from the memory use point of view when the number of nodes is much lower than the theoretical number of nodes in a balanced tree with depth L and branching factor k, that is:

n << (1-k^L)/(1-k)

扶醉桌前 2024-11-11 04:51:40

据我所知,我认为您必须将所有描述符存储在 cv::Mat 上,然后将其添加到“Kmeans Trainer”中,这样​​您最终就可以应用聚类算法。这里有一个片段可以让您了解我在说什么:

BOWKMeansTrainer bowtrainer(1000); //num clusters
bowtrainer.add(training_descriptors); // we add the descriptors
Mat vocabulary = bowtrainer.cluster(); // apply the clustering algorithm

这可能会让您感兴趣:http://www.morethantechnical.com/2011/08/25/a-simple- object-classifier-with-bag-of-words-using-opencv-2-3-w-code/

祝你好运!

For what I know I think that you have to store all the descriptors on a cv::Mat and then add this to a "Kmeans Trainer", thus you can finally apply the clustering algorithm. Here a snippet that can give you an idea about what I am talking:

BOWKMeansTrainer bowtrainer(1000); //num clusters
bowtrainer.add(training_descriptors); // we add the descriptors
Mat vocabulary = bowtrainer.cluster(); // apply the clustering algorithm

And this maybe can be interesting to you: http://www.morethantechnical.com/2011/08/25/a-simple-object-classifier-with-bag-of-words-using-opencv-2-3-w-code/

Good luck!!

爱格式化 2024-11-11 04:51:40

查看 libvot 中的代码,在 src/vocab_tree/clustering.* 中,可以找到详细的实现聚类算法。

Checkout out the code in libvot, in src/vocab_tree/clustering.*, you can find a detailed implementation of the clustering algorithm.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文