ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

'CvSVM' has not been declared

2020-01-16 14:55:42  阅读:78  来源: 互联网

标签:declared SVM color been dong cpp home detector CvSVM


编译错误

In file included from /home/dong/color/color-detector/test.cpp:7:0:
/home/dong/color/color-detector/colorDetector.cpp:142:35: error: 'CvSVM' has not been declared
 void trainSVM(vector<string> dirs,CvSVM& SVM){
                                   ^
/home/dong/color/color-detector/colorDetector.cpp: In function 'void trainSVM(std::vector<std::__cxx11::basic_string<char> >, int&)':
/home/dong/color/color-detector/colorDetector.cpp:179:5: error: 'CvSVMParams' was not declared in this scope
     CvSVMParams params;
     ^
/home/dong/color/color-detector/colorDetector.cpp:180:5: error: 'params' was not declared in this scope
     params.svm_type    = CvSVM::C_SVC;
     ^
/home/dong/color/color-detector/colorDetector.cpp:180:26: error: 'CvSVM' has not been declared
     params.svm_type    = CvSVM::C_SVC;
                          ^
/home/dong/color/color-detector/colorDetector.cpp:181:26: error: 'CvSVM' has not been declared
     params.kernel_type = CvSVM::POLY;
                          ^
/home/dong/color/color-detector/colorDetector.cpp:187:9: error: request for member 'train' in 'SVM', which is of non-class type 'int'
     SVM.train(trainingData, labels, Mat(), Mat(), params);
         ^
/home/dong/color/color-detector/colorDetector.cpp: At global scope:
/home/dong/color/color-detector/colorDetector.cpp:191:25: error: 'CvSVM' has not been declared
 int testSVM(Mat testImg,CvSVM& SVM){
                         ^
/home/dong/color/color-detector/colorDetector.cpp: In function 'int testSVM(cv::Mat, int&)':
/home/dong/color/color-detector/colorDetector.cpp:194:20: error: request for member 'predict' in 'SVM', which is of non-class type 'int'
     response = SVM.predict(testImg);
                    ^
/home/dong/color/color-detector/test.cpp: In function 'int main()':
/home/dong/color/color-detector/test.cpp:18:5: error: 'CvSVM' was not declared in this scope
     CvSVM SVM;
     ^
/home/dong/color/color-detector/test.cpp:19:5: error: 'SVM' was not declared in this scope
     SVM.load("../modell.xml");


原因

3.4版本OpenCV的分类器代码有很多的改动,命名方式也有所不同

使用定义 cv::ml::SVM SVM;

    // Train the SVM
    Ptr<SVM> svm = SVM::create();
    svm->setType(SVM::C_SVC);
    svm->setKernel(SVM::LINEAR);
    svm->setTermCriteria(TermCriteria(TermCriteria::MAX_ITER, 100, 1e-6));
    svm->train(trainingDataMat, ROW_SAMPLE, labelsMat);



2.4.9版本的分类器定义如下:

// SVM model
class CV_EXPORTS_W CvSVM : public CvStatModel
{
public:
    // SVM type
    enum { C_SVC=100, NU_SVC=101, ONE_CLASS=102, EPS_SVR=103, NU_SVR=104 };

    // SVM kernel type
    enum { LINEAR=0, POLY=1, RBF=2, SIGMOID=3 };

    // SVM params type
    enum { C=0, GAMMA=1, P=2, NU=3, COEF=4, DEGREE=5 };

}

使用定义    CvSVM SVM;


标签:declared,SVM,color,been,dong,cpp,home,detector,CvSVM
来源: https://blog.51cto.com/fengyuzaitu/2467248

专注分享技术,共同学习,共同进步。侵权联系[admin#icode9.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有