CvNormalBayesClassifier训练错误
CvNormalBayesClassifier train error
我使用OpenCv来制作CvNormalBayesClassifier
,但是当我尝试训练它时,我得到了一个错误。这是我的代码:
CvMat train=cvMat(1, 32, CV_32FC1, val);
CvMat res=cvMat(1, 1, CV_32FC1, type);
M1.train(&train, &res);
,其中val
是双精度数组,type
是只有一个int元素的数组。M1
是我的CvNormalBayesClassifier
我得到的错误是:
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
流产
谢谢你的建议
该错误意味着您的响应数组res是完全统一的(它必须是,因为它只有元素)。要么添加一个不同的值来允许训练师进行训练,要么告诉它你正在进行单课训练:
CvSVMParams params;
params.svm_type = CvSVM::ONE_CLASS;
M1.train(train, res, Mat(), Mat(), params);
我没有使用"ONE_CLASS",所以你可能需要先给"nu"参数一个值(见这个OpenCV SVM文档页)。此外,我认为没有必要使用&号
首先,最后一个参数cvMat
函数具有void*
类型,因此它不知道数组的实际类型。因此,不可能进行数据转换。但是你正在使用CV_32FC1
常量,它假设float
类型和train
和res
矩阵只是重新解释你的int和双精度浮点数。你的CvNormalBayesClassifier
只看到一个垃圾,而不是真正的数据。
- 警告处理为错误这里有什么问题
- "error: no matching function for call to"构造函数错误
- boost::进程间消息队列引发错误
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- QT在错误的班级中寻找空位
- vector.resize()中的分配错误
- 代码在main()中运行,但在函数中出现错误
- 释放错误后堆使用
- (C++)分析树以计算返回错误值的简单算术表达式
- Project Euler问题4的错误解决方案
- 我的字符计数代码计算错误.为什么
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- 尝试导入pybind-opencv模块时出现libgtk错误
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- 在某些循环内使用vector.push_back时出现分段错误
- MSVC多行宏编译器错误
- 静态数据成员的问题-修复链接错误会导致编译器错误
- 为什么在运行时没有向我们提供有关分段错误的更多信息?
- 错误:未在此范围内声明'reverse'