#include <stdio.h>
#include <time.h>
#include <opencv2/opencv.hpp>
#include <opencv/cv.h>
#include <iostream>
#include <opencv2/core/core.hpp>
#include <io.h>
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/ml.hpp"
using namespace std;
using namespace cv;
using namespace cv::ml;
int main(int argc, char** argv)
{
double time0 = static_cast<double>(getTickCount());
Mat train = Mat::zeros(50, 19, CV_32FC1);//创建Mat类矩阵,定义初始化值全部是0,矩阵大小和xml一致,double
Mat label = Mat::zeros(50, 1, CV_32SC1);//同理,int
//读入mat
FileStorage fs("C:\\Users\\Administrator\\Desktop\\xun\\data.xml", FileStorage::READ);
fs["data"] >> train;
FileStorage fs1("C:\\Users\\Administrator\\Desktop\\xun\\label.xml", FileStorage::READ);
fs1["label"] >> label;
/*for (int i = 0; i < train.rows;i++)
for (int j = 0; j < train.cols; j++)
{
cout <<train.at<float>(i,j) << endl;
}
cout << " 训练数据行数:" << train.rows << "训练数据列数:" << train.cols << endl;
cout << " 训练标签行数:" << label.rows << "训练数据列数: " << label.cols << endl;*/
//
Ptr<SVM> svm = SVM::create();
//svm->setType(SVM::C_SVC);
//svm->setC(100);
//svm->setKernel(SVM::RBF);
//svm->setTermCriteria(TermCriteria(TermCriteria::MAX_ITER, (int)1e7, 1e-6));
//svm->train(train, ROW_SAMPLE, label);
svm->trainAuto(train, ROW_SAMPLE, label);
cout << "训练好了!!!" << endl;
svm->save("C:\\Users\\Administrator\\Desktop\\xun\\svm.xml");
cout << "baocun" << endl;
time0 = ((double)getTickCount() - time0) / getTickFrequency();
cout << "shijian wei" << time0 << "秒" << endl;
while (char(waitKey(1) != 'q')) {}
return 0;
}
支持向量机
最新推荐文章于 2024-02-27 16:14:54 发布
1573

被折叠的 条评论
为什么被折叠?



