Ask Your Question
1

NormalBayesClassifier classifier is an abstract class

asked 2014-09-03 16:37:05 -0600

kenilworth gravatar image

updated 2014-09-04 02:14:00 -0600

berak gravatar image

I'm trying to figure out how to use the Normal Bayes Classifier as explained here.

Mat trainingData;
Mat trainingLabels;
Mat evalData;
Mat results;

cv::ml::NormalBayesClassifier classifier;
//Train classifier...
classifier.train(trainingData, trainingLabels);

//Evaluate classifier...
classifier.predict(evalData,&results);

But I get the following build error: cv::ml::NormalBayesClassifier classifier is an abstract class

I tried making a subclass of NormalBayesClassifier and using that instead but I didn't manage.. What am I doing wrong?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
3

answered 2014-09-04 01:51:38 -0600

berak gravatar image

updated 2014-09-04 02:15:38 -0600

since you're obviously running opencv3.0, you can no more create it on the 'stack' (like it was in 2.4.9). it does not have a public constructor (that's your 'abstract class' error above)

instead, you will have to use a factory function, returning a cv::Ptr :


cv::Ptr<cv::ml::NormalBayesClassifier>  classifier = cv::ml::NormalBayesClassifier::create();

//Train classifier...
classifier->train(trainingData, cv::ml::ROW_SAMPLE, trainingLabels);
// note: it needs a flag now, if a feature is on a row or a column.

//Evaluate classifier...
classifier->predict(evalData,results); 
// note: i skipped the address-operator on results,
// which probably was wrong in the 1st place

also, better look at the 3.0 documentation, i.e. the ml module got some huge overhaul lately.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-09-03 16:37:05 -0600

Seen: 746 times

Last updated: Sep 04 '14