From 7cf03929913aaa26ff829059f2351db2271ab596 Mon Sep 17 00:00:00 2001 From: Micooz Date: Sat, 15 Aug 2015 11:47:25 +0800 Subject: [PATCH] Simplify SVM training. --- include/easypr/train/svm_train.h | 55 ++--- src/train/svm_train.cpp | 383 +++++++++++++------------------ test/main.cpp | 98 ++------ 3 files changed, 201 insertions(+), 335 deletions(-) diff --git a/include/easypr/train/svm_train.h b/include/easypr/train/svm_train.h index 5ce0236..83c9cda 100644 --- a/include/easypr/train/svm_train.h +++ b/include/easypr/train/svm_train.h @@ -1,48 +1,37 @@ -#ifndef EASYPR_SVM_TRAIN_H -#define EASYPR_SVM_TRAIN_H +#ifndef EASYPR_TRAIN_SVMTRAIN_H_ +#define EASYPR_TRAIN_SVMTRAIN_H_ +#include "easypr/train/train.h" #include -#include #include "easypr/config.h" namespace easypr { - class SvmTrain { - public: - typedef enum { - kForward = 1, // correspond to "has plate" - kInverse = 0 // correspond to "no plate" - } Label; +class SvmTrain : public ITrain { + public: + typedef struct { + std::string file; + SvmLabel label; + } TrainItem; - SvmTrain(const char* forward_data_folder, const char* inverse_data_folder); + SvmTrain(const char* plates_folder, const char* xml); - void train(bool divide = true, float divide_percentage = 0.7, - const char* out_svm_folder = kDefaultSvmPath); + virtual void train(); - void runTest(const char* svm_path = kDefaultSvmPath); + virtual void test(); - private: - /* - * divide images into train part and test part by percentage - */ - void divide(const char* images_folder, float percentage = 0.7); + private: + void prepare(); - void getTrain(); + virtual cv::Ptr tdata(); - void getTest(); - - const char* forward_; - const char* inverse_; - - // these two variables are used for cv::CvSVM::train_auto() - cv::Mat classes_; - cv::Ptr trainingData_; - - // these two variables are used for cv::CvSVM::predict() - std::vector test_imgaes_; - std::vector