Ask Your Question

Implementing BagOfWords in java?

asked 2018-06-15 09:30:06 -0500

Macho gravatar image

I am new to Java and Opencv, i have spent 2 days trying to implement BOW in Java, i am using OpenCV 3.2.0 since it is the only version that i found contains BOW classes in Feature2d

int dictionarySize = 1500;
 TermCriteria criteria = new TermCriteria(TermCriteria.EPS + TermCriteria.MAX_ITER,100,0.1);

 FeatureDetector features = FeatureDetector.create(FeatureDetector.SIFT);
 DescriptorExtractor extractor = DescriptorExtractor.create(DescriptorExtractor.SIFT);
 DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.FLANNBASED);

 BOWKMeansTrainer bowTrainer = new BOWKMeansTrainer(dictionarySize, criteria, 1, Core.KMEANS_PP_CENTERS);

BOWImgDescriptorExtractor de = new BOWImgDescriptorExtractor(extractor, matcher);

In the last line of code i found out in Java BOWImgDescriptorExtractor class don't take theses input arguments like the C++ class.

I need to train SVM with BoW so please any help would be appreciated.

edit retag flag offensive close merge delete


did you build the opencv libs locally before, with the classes from opencv_contrib ? (you won't be able to use SIFT features else)

berak gravatar imageberak ( 2018-06-15 10:10:28 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2018-06-15 09:39:26 -0500

berak gravatar image

updated 2018-06-15 09:52:14 -0500

sad as it is, you can't use those BoW classes from java, their bindings are broken. (e.g. there is no BOWImgDescriptorExtractor constructor, it is skipped during the wrapper generation)

i am using OpenCV 3.2.0 since it is the only version that i found contains BOW classes in Feature2d

that is not true. more recent versions have them, too (and you should a more recent version, than 3.2), but the problem remains the same.

you'll either have to fallback to jni for this, or rewrite it in java.

please see here for a java example

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2018-06-15 09:30:06 -0500

Seen: 158 times

Last updated: Jun 15 '18