#include<opencv2\opencv.hpp>
using namespace std;
using namespace cv;
using namespace cv::ml;
int main()
{
//训练需要用到的数据
int label[4] = { 1, 2, 3, 4 };
float train[4][2] = { { 31, 12 }, { 65, 220 }, { 440, 350 }, { 400, 400 } };
//转为Mat以调用
Mat TRAIN(4, 2, CV_32FC1, train);
Mat LABEL(4, 1, CV_32SC1, label);
//训练的初始化
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(TRAIN, ROW_SAMPLE, LABEL);
//-----------无关紧要的美工的部分-----------------------
//----其实对每个像素点的坐标也进行了分类----------------
//int W = 512, H = 512;
//Mat img = Mat::zeros(H, W, CV_8UC3);
//Vec3b green(0, 255, 0), blue(255, 0, 0), red(0, 0, 255), black(0, 0, 0);
//for (int i = 0; i < img.rows; ++i)
//for (int j = 0; j &