Last active
August 26, 2015 06:01
-
-
Save berak/9907a116f514022d4fcd to your computer and use it in GitHub Desktop.
svm trainAuto test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include "opencv2/opencv.hpp" | |
using namespace cv; | |
using namespace std; | |
int main(int argc, char **argv) | |
{ | |
cv::Mat trainingData, trainingLabels; | |
vector<String> fn; | |
glob("build/trainingDir/0/*.jpg",fn); | |
for(size_t i=0; i<fn.size(); ++i) | |
{ | |
Mat im = imread(fn[i],0); | |
im.convertTo(im,CV_32F); | |
trainingData.push_back(im.reshape(1,1)); | |
trainingLabels.push_back(0); | |
} | |
glob("build/trainingDir/2/*.jpg",fn); | |
for(size_t i=0; i<fn.size(); ++i) | |
{ | |
Mat im = imread(fn[i],0); | |
im.convertTo(im,CV_32F); | |
trainingData.push_back(im.reshape(1,1)); | |
trainingLabels.push_back(1); | |
} | |
std::cout << trainingLabels.total() << std::endl; | |
Ptr<ml::SVM> m_classifier = cv::ml::SVM::create(); | |
// Training parameters: | |
m_classifier->setType(cv::ml::SVM::C_SVC); | |
m_classifier->setKernel(cv::ml::SVM::POLY); | |
m_classifier->setGamma(3); | |
m_classifier->setDegree(3); | |
std::cout << "PreTrain check " << std::endl; | |
m_classifier->trainAuto(ml::TrainData::create(trainingData, ml::ROW_SAMPLE, trainingLabels)); | |
std::cout << "PostTrain check " << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment