Ask Your Question
0

NormalBayesCLassifier::predict error

asked 2014-07-02 03:57:35 -0600

thdrksdfthmn gravatar image

I have trained a NormalBayesClassifier and saved it as yaml. The FeatureDetector used was PyramidGFTT, the DescriptorExtractor used was BRISK and the matcher was BruteForce. I have used a BOWImgDescriptorExtractor based on the mentioned types of DescriptorsExtractor and matcher. I have also used a BOWKMeansTrainer(750, cv::TermCriteria(CV_TERMCRIT_ITER, 10, 0.001), 3, KMEANS_PP_CENTERS) for training. I save the classifier trained.

Then I load it and use the same detector, extractor and matcher, it works fine, but when I do classifier->predict(descriptors, &result); It crashes saying:

OpenCV Error: Bad argument (The input samples must be 32f matrix with the number of columns = var_all) in predict, file /home/me/opencv/modules/ml/src/nbayes.cpp, line 384
terminate called after throwing an instance of 'cv::Exception'
  what():  /home/me/opencv/modules/ml/src/nbayes.cpp:384: error: (-5) The input samples must be 32f matrix with the number of columns = var_all in function predict

In fact I use Ptr< NormalBayesCLassifier >, that is why I use -> instead of .. If I do not use Ptr, it gives me the same error. I have tried to convert the descriptors to CV_32FC1, but the same error is thrown.

How to predict what class an image is using NormalBayesClassifier loaded from a file (yaml)?

edit retag flag offensive close merge delete

Comments

hmm, if you're using BOW, you will have to use the result from the bow.compute() function for the descriptor

berak gravatar imageberak ( 2014-07-02 04:30:12 -0600 )edit

no... I think I need a vocabulary, that I have not saved...

thdrksdfthmn gravatar imagethdrksdfthmn ( 2014-07-02 04:34:09 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-07-07 09:59:16 -0600

thdrksdfthmn gravatar image

The problem that I was having here, was that I have not saved the vocabulary. So I have not load any vocabulary, so the matcher was not letting any feature/descriptor to pass it. I was getting an empty set of descriptors ant that was the reason of the error. After I have added the vocabulary, everything worked well.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-07-02 03:57:35 -0600

Seen: 533 times

Last updated: Jul 07 '14