-->

OpenCV 2.4.5: FLANN and hierarchicalClustering

2019-07-17 22:05发布

问题:

I have recently started porting an application to a new platform which runs OpenCV 2.4.5.

Part of my code which uses OpenCV's implementation of FLANN to do hierarchical clustering no longer compiles.

The code is as follows:

cv::Mat mergedFeatures = cvCreateMat(descriptorTotal, descriptorDims, CV_32F);

int counter = 0;
for (uint j = 0; j < ImageFeatures.size(); j++) {
    cv::Mat features = ImageFeatures[j];
    for (int k = 0; k < features.rows; k++) {
        cv::Mat roi = mergedFeatures.row(counter);
        features.row(k).copyTo(roi);
        counter++;
    }
}

cv::Mat centers = cvCreateMat(1000, descriptorDims, CV_32FC1);
cv::flann::KMeansIndexParams k_params = cv::flann::KMeansIndexParams();
cv::flann::AutotunedIndexParams atp = cv::flann::AutotunedIndexParams();
int numClusters = cv::flann::hierarchicalClustering<float, float>(mergedFeatures, centers, k_params);

The error that I am getting (in Eclipse) is that cv::flann::hierarchicalClustering has invalid arguments and that neither of the candidates for this function are met.

Can someone explain how I suddenly seem to be calling this method incorrectly?

Many thanks for any help.

回答1:

I fixed the problem myself.

Instead of accepting:

cv::flann::KMeansIndexParams k_params

the hierarchicalClustering function actually needs:

cvflann::KMeansIndexParams k_params

It is rather a confusing namespace convention with the FLANN library in OpenCV and I had just overlooked the namespace difference in what the compiler error was telling me.

It is all working now. The KMeansIndexParams type is present in both namespaces and I guess that the hierarchicalClustering method has changed very slightly from OpenCV 2.3 to 2.4.5.