规范化图像描述符OpenCV Java

时间:2015-11-10 17:45:53

标签: java c++ opencv image-processing sift

您好我将在OpenCV Java中实现Opencv BOW算法。我试图将大部分代码转换为java。但是我被困在这里,因为我不明白这里到底发生了什么。

void BOWImgDescriptorExtractor::compute( InputArray keypointDescriptors, OutputArray _imgDescriptor, std::vector<std::vector<int> >* pointIdxsOfClusters )
{
int clusterCount = descriptorSize(); // = vocabulary.rows

// Match keypoint descriptors to cluster center (to vocabulary)
std::vector<DMatch> matches;
dmatcher->match( keypointDescriptors, matches );

// Compute image descriptor
if( pointIdxsOfClusters )
{
    pointIdxsOfClusters->clear();
    pointIdxsOfClusters->resize(clusterCount);
}

_imgDescriptor.create(1, clusterCount, descriptorType());
_imgDescriptor.setTo(Scalar::all(0));

Mat imgDescriptor = _imgDescriptor.getMat();

float *dptr = imgDescriptor.ptr<float>();
for( size_t i = 0; i < matches.size(); i++ )
{
    int queryIdx = matches[i].queryIdx;
    int trainIdx = matches[i].trainIdx; // cluster index
    CV_Assert( queryIdx == (int)i );

    dptr[trainIdx] = dptr[trainIdx] + 1.f;
    if( pointIdxsOfClusters )
        (*pointIdxsOfClusters)[trainIdx].push_back( queryIdx );
}

// Normalize image descriptor.
imgDescriptor /= keypointDescriptors.size().height;
}     

在最后一行中,它描述了规范化描述符。我想知道如何在java中实现该部分。任何帮助,将不胜感激。

1 个答案:

答案 0 :(得分:0)

我试图像你这样做,但它对我不起作用,所以我用弓训练器fonctionnality构建了opencv2.9,它运行良好,我已经完成了96℅