OpenCV—cv::ml::SVMImpl::train报错
报错:
OpenCV(4.1.0) Error: Bad argument (in the case of classification problem the responses must be categorical; either specify varType when creating TrainData, or pass integer responses) in cv::ml::SVMImpl::train, file c:\build\master_winpack-build-win64-vc15\opencv\modules\ml\src\svm.cpp, line 1629
原因:输入到cv::ml::SVMImpl::train的Mat的数据类型不对。
原函数
virtual bool train( InputArray samples, int layout, InputArray responses );
其中:
samples分类的输入类型为cv_32F
responses分类的输入类型为32_32S
调整方法:
使用函数:
void convertTo(OutputArray dst, int rtype) const;
例子:
trainFeature.convertTo(trainFeature,CV_32FC1);