Ask Your Question

Revision history [back]

Cluster crushes with unknown exception

Dear Community

I seek for your help. I found this project that builds Bag-of-Features Descriptor on SIFT Features on OpenCV 2.3. I will use OpenCV 3.4.0

I tried to rewrite first part of it to Java and there are two things that are not similar between his and my code. Firstly I chose only 3 images and he chose 20. Secondly I'm not sure that TermCriteria types in C++ and Java are similar.

He uses this

CV_TERMCRIT_ITER

type. But I have only these types to choose

TermCriteria.EPS TermCriteria.COUNT TermCriteria.MAX_ITER

Here is my code

public static void main(String[] args) throws Exception{
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    FeatureDetector detector = FeatureDetector.create(FeatureDetector.ORB);
    DescriptorExtractor descriptor = DescriptorExtractor.create(DescriptorExtractor.ORB);

    Mat img;
    MatOfKeyPoint keypoints = new MatOfKeyPoint();
    Mat desc = new Mat();
    Mat featuresUnclustered = new Mat();

    for(String file : filename){
        img = Imgcodecs.imread(file, Imgcodecs.CV_LOAD_IMAGE_GRAYSCALE);
        detector.detect(img, keypoints);
        descriptor.compute(img, keypoints, desc);
        featuresUnclustered.push_back(desc);
    }

    //Construct BOWKMeansTrainer
    //the number of bags
    int dictionarySize=200;
    //define Term Criteria
    TermCriteria tc = new TermCriteria(TermCriteria.EPS | TermCriteria.MAX_ITER,100,0.001);
    //retries number
    int retries=1;
    //necessary flags
    int flags=Core.KMEANS_PP_CENTERS;
    //Create the BoW (or BoF) trainer
    BOWKMeansTrainer bowTrainer = new BOWKMeansTrainer(dictionarySize,tc,retries,flags);
    //cluster the feature vectors
    Mat dictionary=bowTrainer.cluster(featuresUnclustered);
    //store the vocabulary
    System.out.println(dictionary.toString());
}

And this is exception that i got

image description

Any information will be helpful