I’m using OpenCv to make a CvNormalBayesClassifier, but when I try to train it I get an error.
this is my code:
CvMat train=cvMat(1, 32, CV_32FC1, val);
CvMat res=cvMat(1, 1, CV_32FC1, type);
M1.train(&train, &res);
where val is an array of double and type is an array of just one int element. M1 is my CvNormalBayesClassifier
the error I get is this one:
OpenCV Error: Bad argument (There is only a single class) in cvPreprocessCategoricalResponses, file /build/buildd/opencv-2.1.0/src/ml/ml_inner_functions.cpp, line 731
terminate called after throwing an instance of 'cv::Exception'
what(): /build/buildd/opencv-2.1.0/src/ml/ml_inner_functions.cpp:731: error: (-5) There is only a single class in function cvPreprocessCategoricalResponses
Aborted
thank you for any suggestion
First of all, the last argument
cvMatfunction has avoid*type so it does not know the real type of your arrays. As result no data conversion is possible. But you are usingCV_32FC1constant which assumesfloattype andtrainandresmatrices just reinterpret bits of your int and doubles as floats. And yourCvNormalBayesClassifiersees just a trash instead of real data.