Ask Your Question
0

NormalBayesCLassifier::predict error

asked Jul 2 '14

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)?

Preview: (hide)

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 (Jul 2 '14)edit

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

thdrksdfthmn gravatar imagethdrksdfthmn (Jul 2 '14)edit

1 answer

Sort by » oldest newest most voted
1

answered Jul 7 '14

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.

Preview: (hide)

Question Tools

Stats

Asked: Jul 2 '14

Seen: 547 times

Last updated: Jul 07 '14