bytedeco / javacv

Java interface to OpenCV, FFmpeg, and more
Other
7.57k stars 1.58k forks source link

BowExtractor use? #1571

Open nikkisingh111333 opened 3 years ago

nikkisingh111333 commented 3 years ago

hey i m struggling with Bag Of Visual Words in java bytedeco ..i cant find any good example of using bag of visual words in java .i know how it works theoritically but dont know how to implement it currently using this but confused:

org.bytedeco.opencv.opencv_core.TermCriteria criteria = new  org.bytedeco.opencv.opencv_core.TermCriteria(TermCriteria.EPS +  TermCriteria.MAX_ITER,100,0.1);
           FastFeatureDetector features = FastFeatureDetector.create();
           BriefDescriptorExtractor ext = BriefDescriptorExtractor.create();
           DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.FLANNBASED);
           BOWKMeansTrainer bowTrainer = new BOWKMeansTrainer(dictionarySize, criteria, 1, Core.KMEANS_PP_CENTERS);
           BOWImgDescriptorExtractor de = new BOWImgDescriptorExtractor(matcher);

how to implement it properly ..steps by step. some provide me some guidance ?

saudet commented 3 years ago

There's some sample code on the mailing list: https://groups.google.com/g/javacv/search?q=BOWImgDescriptorExtractor Let me know if you're having problems with any of that.

nikkisingh111333 commented 3 years ago

hey i m having problem in understanding it seems confusing .. first just check my code its simple one: var files= new File("C:\\Users\\Nikki singh\\Downloads\\2 img"); File[] imageFiles = files.listFiles(imgFilter); TermCriteria criteria = new TermCriteria(TermCriteria.EPS + TermCriteria.MAX_ITER,100,0.001); int dictionarySize = 60; BOWKMeansTrainer bow = new BOWKMeansTrainer(dictionarySize, criteria, 1, Core.KMEANS_PP_CENTERS); SIFT sift=SIFT.create(); FastFeatureDetector fd=FastFeatureDetector.create(); KeyPointVector keypoint=new KeyPointVector(); opencv_features2d.drawKeypoints(y, keypoint, y); for (int i=0;i<12;i++) { Mat im=imread(imageFiles[i].getAbsolutePath(),IMREAD_GRAYSCALE); ims.add(im); KeyPointVector mk=new KeyPointVector(); fd.detect(im , mk); sift.detectAndCompute(im,mask, mk, dis); dis.convertTo(dis, opencv_core.CV_32FC1); bow.add(dis); } System.out.println(bow.descriptorsCount()); DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.FLANNBASED); BOWImgDescriptorExtractor de = new BOWImgDescriptorExtractor(sift,matcher); var dictionary_vocabs=bow.cluster(); System.out.println(dictionary_vocabs.toString()); de.setVocabulary(dictionary_vocabs); // i m right TILL here System.out.println(de.getVocabulary().toString()); till here i m doing good but after vocabulary i dont know what to do..i ve read many sources about BOWV some says you have to train vocabs in svm or any other you want to use BUT some says you have to train each image descriptors(i m using SHIFT here) on svm .....than my question is whats the point of creating vocabulary ... i mean how can i train SVM or Anyother classifier with BOW and start predicting ..my folder has 26 sample image just for trying purpose i m using 14 for training...what the correct setup for bow ..please help me out.