1

我有以下代码,旨在通过其 SIFT 特征描述符对一组图像进行聚类。

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..
}

我遇到的问题是,我已经在我调用的点计算了图像的描述符BowImgDescriptorExtractor::compute,因此如果我可以提供这些而不是BowImgDescriptorExtractor::compute重新计算它们,那将是理想的。如您所见,我能够提供关键点,但无法找到提供描述符的方法。

有什么方法可以让我重新使用我已经在这里创建的描述符?

4

1 回答 1

2

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.

于 2015-03-30T13:30:28.957 回答