Ask Your Question

Revision history [back]

error with BOWKMeansTrainer when training BOW

I'm trying to train Bag of Words to categorize images that is whether they are road sign or not. the program is running for some time. after adding approx. 200 images in the BOWKMeansTrainer an error is produced. below are the codes

     int dictionarySize = 1000;
     CvTermCriteria tc=new CvTermCriteria(CV_TERMCRIT_ITER, 10, 0.001);
     int retries = 1;
     int flags = 2;//CV_KMEANS_PP_CENTERS


    SURF  surf = new SURF(400);
    FeatureDetector featureDetector =FeatureDetector.create("SURF");//surf.getFeatureDetector();    
    DescriptorExtractor descriptorExtractor=surf.getDescriptorExtractor();
    BOWKMeansTrainer bMeansTrainer = new BOWKMeansTrainer(dictionarySize, tc , retries, flags); 
    BOWImgDescriptorExtractor bDescriptorExtractor = new BOWImgDescriptorExtractor( descriptorExtractor, descriptorMatcher);



    File folder = new File(path);
    File[] listOfFiles = folder.listFiles();

    for (File file : listOfFiles) {
        if (file.isFile()) {    
            String imageName=file.getName();
            String filePath=path+"/"+imageName;and the file name 
             CvMat image = cvLoadImageM(filePath,0); 
             if (!image.empty())
             {  
                KeyPoint keypoints = new KeyPoint(); // a verifier 
                featureDetector.detect(image, keypoints,null); 
                if (keypoints.isNull())
               {
                    System.out.println("Warning: Could not find key points in image: "+imageName);
                }

               else 
               {
                   CvMat f = new CvMat(null) ;
                   descriptorExtractor.compute(image, keypoints, f);   
                   keypoints.deallocate();              
                   bMeansTrainer.add(f);
                }
             }
             else 
             {
                 System.out.println("Warning: Could not read image: "+ imageName);
             }
        }
    }

And i'm getting this error

OpenCV Error: Assertion failed (!_descriptors.empty()) in unknown function, 
file..\..\..\src\opencv\modules\features2d\src\bagofwords.cpp, line 57 

Exception in thread "main" java.lang.RuntimeException: ..\..\..\src\opencv\
modules\features2d\src\bagofwords.cpp:57: error: (-215) !_descriptors.empty()

Someone can tell me what am possibly doing wrong??