-
Notifications
You must be signed in to change notification settings - Fork 1
/
svm.hpp
28 lines (20 loc) · 853 Bytes
/
svm.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#pragma once
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
void trainSVM(const cv::Ptr<cv::ml::TrainData> &dataset)
{
auto svm = cv::ml::SVM::create();
svm->setKernel(cv::ml::SVM::LINEAR); //cv::ml::SVM::RBF, cv::ml::SVM::SIGMOID, cv::ml::SVM::POLY
svm->setType(cv::ml::SVM::C_SVC);
svm->trainAuto(dataset);
svm->save("SVM.xml");
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
float testSVM(const cv::Ptr<cv::ml::TrainData> &dataset)
{
auto svm = cv::ml::SVM::load("SVM.xml");
std::vector<int32_t> predictions;
auto error = svm->calcError(dataset, true, predictions);
return error;
}