OpenCV 2.4.5: FLANN and hierarchicalClustering

一曲冷凌霜 提交于 2019-12-12 20:54:34

问题


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.



来源:https://stackoverflow.com/questions/17460431/opencv-2-4-5-flann-and-hierarchicalclustering

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