CvSVM has not been declared in this area. Error

I am using OpenCV 3.0.0

I have included all of these libraries and namespaces, but I still get the error "CvSVM is not declared in this scope"

#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include "opencv2/imgcodecs.hpp"
#include <opencv2/highgui.hpp>
#include <opencv2/ml.hpp>

using namespace cv;
using namespace cv::ml;
using namespace std;

When I run this code:

CvSVM svm;

I get an error message.

+4
source share
1 answer

In OpenCV 3.0 CvSVMit was renamed to SVMand moved to the namespace cv::ml(in fact, also in the previous version SVMthere was a typedef for CvSVM).

Since it SVMis an abstract class, you cannot create it. You need to call SVM::create().

So you need to do:

cv::Ptr<cv::ml::SVM> svm = cv::ml::SVM::create();

or simply:

using namespace cv;
using namespace cv::ml;
...
Ptr<SVM> svm = SVM::create();

CvSVMParams. SVM:

Ptr<SVM> svm = SVM::create();
svm->setType(SVM::C_SVC);
svm->setKernel(SVM::RBF);
// etc
+3

Source: https://habr.com/ru/post/1613535/


All Articles