Re-using descriptors with BOWImgDescriptorExtractor

て烟熏妆下的殇ゞ 提交于 2019-12-11 12:23:22

问题


I have the following code which is intended to cluster a set of images via their SIFT feature descriptors.

cv::BOWKMeansTrainer trainer = cv::BOWKMeansTrainer(n_clusters);

for (Image* image : get_images()) {
    trainer.add(image->get_descriptors());
}

cv::Mat vocabulary = trainer.cluster();
cv::BOWImgDescriptorExtractor extractor(Image::get_extractor(), Image::get_matcher());
extractor.setVocabulary(vocabulary);

for (Image* image : get_images()) {
    cv::Mat bow_descriptor;
    extractor.compute(image->get_data(), image->get_key_points(), bow_descriptor);

    // Determine which cluster the image matches best, via bow_descriptor..
}

The problem I have, is that I have already computed the descriptors for the images at the point I call BowImgDescriptorExtractor::compute, and so it would be ideal if I could provide these rather than BowImgDescriptorExtractor::compute re-calculating them. As you can see, I am able to provide the key-points, but not able to find a way to provide the descriptors.

Is there any way for me to re-use the descriptors I have already created here?


回答1:


I have resorted to writing my own version of BOWImgDescriptorExtractor, which allows me to directly pass in the descriptors rather than having to re-compute them.

I simply re-used the existing source code, but changed the method signature to allow me to pass in the descriptors, rather than the image data and key points, and also of course removed the unnecessary calculations in the method body.

Note: I'm currently running version 2.4.9 of OpenCV, but it appears that in version 3.0.0 (which is not yet released), they have overloaded compute to address this issue.



来源:https://stackoverflow.com/questions/29120374/re-using-descriptors-with-bowimgdescriptorextractor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!