BoW在OpenCV中使用预先计算的功能 [英] BoW in OpenCV using precomputed features

查看:287
本文介绍了BoW在OpenCV中使用预先计算的功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要做BOW(一袋字),但我只有描述的图像的关键点。目前,我已经获得了词汇表:

I need to do BOW (bag of words) but I only have the described keypoints of the images. For the moment, I have obtained the vocabulary using:

cv::BOWKMeansTrainer bowtrainerCN(numCenters); //num clusters
bowtrainerCN.add(allDescriptors);
cv::Mat vocabularyCN = bowtrainerCN.cluster();

现在我需要做赋值,但是我不能使用compute函数,因为它计算描述符的图像和我已经有了。

So now I need to do the assignment but I can't use the compute function because it calculates the descriptors of the images and I already have that. Is there any function to do the assignment or have I to compute it manually?

推荐答案

一旦你构建了词汇表(codebook)使用 cv :: BOWKMeansTrainer :: cluster()方法,然后可以将描述符(具有适当的大小和类型)匹配到码本。你首先必须选择你需要的匹配器类型使用规范。 (请参阅 opencv doc

Once you have built the vocabulary (codebook) using cv::BOWKMeansTrainer::cluster() method, you can then match a descriptor (with suitable size and type) to the codebook. You first have to choose the type of matcher you need with a norm to use. (see opencv doc)

例如, cv :: BFMatcher L2 norm

// init the matcher with you pre-trained codebook
cv::Ptr<cv::DescriptorMatcher > matcher = new cv::BFMatcher(cv::NORM_L2);
matcher->add(std::vector<cv::Mat>(1, vocabulary));
// matches
std::vector<cv::DMatch> matches;
matcher->match(new_descriptors,matches);

然后,你的codebook中的new_descriptors [i]的最接近的代码字的索引将是

Then the index of the closest codeword in your codebook for the new_descriptors[i] will be

matches[i].trainIdx; 

这篇关于BoW在OpenCV中使用预先计算的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆