hierarchical clustering

asked 2019-07-12 03:29:33 -0600

lounice gravatar image

updated 2019-07-12 03:37:27 -0600

berak gravatar image

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)

edit retag flag offensive close merge delete

Comments

1

I am using OpenCV 2.4.8

don't. it's stone age, and no more maintained.

berak gravatar imageberak ( 2019-07-12 03:38:11 -0600 )edit
1

your code does not segfault with recent 4.1.0, so:

  • show us, how you actually fill the descriptors (problem might be there, illegal access, etc)
  • try to update to 3.4.x or master. really, if it's a library problem, noone will be able to help you with unmaintained legacy code.
berak gravatar imageberak ( 2019-07-12 03:45:14 -0600 )edit
1

thanks for your answer. I will try to update my OpenCV version. Meanwhile below is how I fill my samples :

for(unsigned int ii = 0; ii< nSamples; ii++)
{
vector <double> descriptorVector;
interestPoint[ii]->getDescriptor(descriptorVector);
for(unsigned int j=0; j<48; j++) //48 is the descriptor's dimension
descriptorsSamples.at<float>(ii, j) = descriptorVector[j];
}
lounice gravatar imagelounice ( 2019-07-12 04:07:05 -0600 )edit
1

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 ?

lounice gravatar imagelounice ( 2019-07-12 04:13:13 -0600 )edit
1

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.

berak gravatar imageberak ( 2019-07-12 04:13:18 -0600 )edit
1

I think it could be the types

however, the way you copy it to a float Mat looks correct, and iirc, no, you have to stick with float using flann.

berak gravatar imageberak ( 2019-07-12 04:16:51 -0600 )edit

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.

lounice gravatar imagelounice ( 2019-07-12 05:02:56 -0600 )edit
1

no, there are no internal size restrictions. look at your own code again.

berak gravatar imageberak ( 2019-07-12 05:22:15 -0600 )edit

what if you do not use Mat1f but Mat(w,h,CV_32F) ?

berak gravatar imageberak ( 2019-07-12 05:33:52 -0600 )edit

I just tried using Mat(w,h, CV_32F) and this did not fix the issue... I keep on searching. Thanks again.

lounice gravatar imagelounice ( 2019-07-12 08:12:50 -0600 )edit