本文基于http://docs.opencv.org/3.0-beta/doc/tutorials/ml/introduction_to_svm/introduction_to_svm.html,这里面存在着opencv2版本的使用方法。尤其是3.0中不存在params了。而且opencv3.0的参考文章比较少,特地上传自己的代码,在链接中代码的基础上修改了,可以直接跑通,并且增加了测试的环节,希望对各位有所帮助。
下面就附上代码:
#include <iostream>
#include <opencv2/highgui.hpp>
#include <opencv2/ml.hpp>
#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include "opencv2/imgcodecs.hpp"
#include <opencv2/highgui.hpp>
#include <opencv2/ml.hpp>
using namespace std;
using namespace cv;
using namespace cv::ml;
int main(int, char**)
{
// Data for visual representation
int width = 512, height = 512;
Mat image = Mat::zeros(height, width, CV_8UC3);
// Set up training data
int labels[4] = { 1, -1, -1, -1 };
Mat label