hierarchical clustering
I am trying to cluster features using the flann hierarchicalClustering function. The features' dimension is 48 and I have around 100 features. I don't understand why the clustering crashes ? (seg fault). Below is a sample code of what I am doing :
//samples
cv::Mat1f descriptorsSamples = cv::Mat1f::zeros(nSamples, 48);
//here I fill descriptorsSamples with float values (48 dim descriptors)
unsigned int branching = 32; // 32
unsigned int niterations = 10; // 100
int nClusters = 0;
cvflann::KMeansIndexParams kmean_params;
unsigned int initiNCenters = 10;
cv::Mat1f centers(initiNCenters, 3);
nClusters = cv::flann::hierarchicalClustering< cv::flann::L2<float> >((const cv::Mat &) descriptorsSamples,
(cv::Mat &) centers,
(const::cvflann::KMeansIndexParams &) kmean_params);
IMPORTANT : I am using OpenCV 2.4.8 (this version is imposed)
don't. it's stone age, and no more maintained.
your code does not segfault with recent 4.1.0, so:
thanks for your answer. I will try to update my OpenCV version. Meanwhile below is how I fill my samples :
I think it could be the types (my descriptor vector is of type double and the sample required for the hierarchical clustering are floats). Can I use doubles with the hierarchical clustering ?
are your
descriptorsSamples
valid throughout all of the program ? the flann code tries to run away with an internal float * pointer, breaking any Mat refcounting.however, the way you copy it to a float Mat looks correct, and iirc, no, you have to stick with float using flann.
I think I know where the issue is: the sample dimension is too big. I have reduced the dimension from 48 to 5 and it runs. Now, since my descriptors are dimension 48, I wonder if there is indeed a limitation in the dimensions of the samples ? I couldn't find this information anywhere.
no, there are no internal size restrictions. look at your own code again.
what if you do not use
Mat1f
butMat(w,h,CV_32F)
?I just tried using Mat(w,h, CV_32F) and this did not fix the issue... I keep on searching. Thanks again.