From 2512b438cc4ce62d59a0a6c7c1c7d0cafc050984 Mon Sep 17 00:00:00 2001 From: FuGangqiang Date: Mon, 23 Mar 2015 20:33:42 +0800 Subject: [PATCH] rename `features.h` => `feature.h`, `features.cpp` => `feature.cpp` --- CMakeLists.txt | 2 +- EasyPR.vcxproj | 8 +-- EasyPR.vcxproj.filters | 8 +-- src/core/{features.cpp => feature.cpp} | 4 +- src/include/{features.h => feature.h} | 6 +-- src/include/plate_judge.h | 8 +-- src/main.cpp | 74 +++++++++++++------------- src/test/accuracy_test.cpp | 4 +- src/train/ann_train.cpp | 62 ++++++++++----------- src/train/svm_train.cpp | 24 ++++----- src/util/deface.cpp | 10 ++-- src/util/general_test_prepare.cpp | 30 +++++------ src/util/generate_gdts.cpp | 6 +-- 13 files changed, 123 insertions(+), 123 deletions(-) rename src/core/{features.cpp => feature.cpp} (96%) rename src/include/{features.h => feature.h} (92%) diff --git a/CMakeLists.txt b/CMakeLists.txt index b0f5627..3a4253f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,7 @@ set(SOURCE_FILES src/core/chars_identify.cpp src/core/chars_recognise.cpp src/core/chars_segment.cpp - src/core/features.cpp + src/core/feature.cpp src/core/plate.cpp src/core/plate_detect.cpp src/core/plate_judge.cpp diff --git a/EasyPR.vcxproj b/EasyPR.vcxproj index 40ff59e..e0e4521 100644 --- a/EasyPR.vcxproj +++ b/EasyPR.vcxproj @@ -1,4 +1,4 @@ - + @@ -91,7 +91,7 @@ - + @@ -116,7 +116,7 @@ - + @@ -129,4 +129,4 @@ - \ No newline at end of file + diff --git a/EasyPR.vcxproj.filters b/EasyPR.vcxproj.filters index 8e0c225..6f3a374 100644 --- a/EasyPR.vcxproj.filters +++ b/EasyPR.vcxproj.filters @@ -1,4 +1,4 @@ - + @@ -60,7 +60,7 @@ 源文件 - + 源文件 @@ -125,7 +125,7 @@ 头文件 - + 头文件 @@ -138,4 +138,4 @@ 头文件 - \ No newline at end of file + diff --git a/src/core/features.cpp b/src/core/feature.cpp similarity index 96% rename from src/core/features.cpp rename to src/core/feature.cpp index 14328e3..958473a 100644 --- a/src/core/features.cpp +++ b/src/core/feature.cpp @@ -3,7 +3,7 @@ // еeasyprĿ޸ #include "../include/prep.h" -#include "../include/features.h" +#include "../include/feature.h" #include "../include/core_func.h" /*! \namespace easypr @@ -87,4 +87,4 @@ namespace easypr { //TODO } -} /* \namespace easypr */ \ No newline at end of file +} /* \namespace easypr */ diff --git a/src/include/features.h b/src/include/feature.h similarity index 92% rename from src/include/features.h rename to src/include/feature.h index 69d354a..4a682d4 100644 --- a/src/include/features.h +++ b/src/include/feature.h @@ -1,5 +1,5 @@ -#ifndef __FEATURES_H__ -#define __FEATURES_H__ +#ifndef __FEATURE_H__ +#define __FEATURE_H__ /*! \namespace easypr Namespace where all the C++ EasyPR functionality resides @@ -33,4 +33,4 @@ namespace easypr { } /*! \namespace easypr*/ #endif -/* endif __FEATURES_H__ */ \ No newline at end of file +/* endif __FEATURE_H__ */ diff --git a/src/include/plate_judge.h b/src/include/plate_judge.h index 911cdd5..424c4d1 100644 --- a/src/include/plate_judge.h +++ b/src/include/plate_judge.h @@ -7,7 +7,7 @@ // Copyright: liuruoze // Reference: Mastering OpenCV with Practical Computer Vision Projects // Reference: CSDN Bloger taotao1233 -// Desciption: +// Desciption: // Defines CPlateLocate ////////////////////////////////////////////////////////////////////////// #ifndef __PLATE_JUDGE_H__ @@ -15,7 +15,7 @@ #include "prep.h" #include "plate.h" -#include "features.h" +#include "feature.h" #include "core_func.h" /*! \namespace easypr @@ -23,7 +23,7 @@ */ namespace easypr { -class CPlateJudge +class CPlateJudge { public: CPlateJudge(); @@ -64,4 +64,4 @@ private: } /*! \namespace easypr*/ -#endif /* endif __PLATE_JUDGE_H__ */ \ No newline at end of file +#endif /* endif __PLATE_JUDGE_H__ */ diff --git a/src/main.cpp b/src/main.cpp index 62c0d43..b60ef97 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,6 @@ #include "include/plate_recognize.h" #include "include/util.h" -#include "include/features.h" +#include "include/feature.h" #include "include/CParser.h" using namespace easypr; @@ -10,10 +10,10 @@ int acurayTestMain(); void cmdMain(int argc, char *argv[]); namespace easypr { - + int svmTrain(bool dividePrepared = true, bool trainPrepared = true, svmCallback getFeatures = getHistogramFeatures); - + } extern const string GENERAL_TEST_PATH = "image/general_test"; @@ -43,7 +43,7 @@ int main(int argc, char *argv[]) cmdMain(argc, argv); return 0; } - + bool isExit = false; while (isExit != true) { @@ -53,12 +53,12 @@ int main(int argc, char *argv[]) { selectOption << option[i] << endl; } - + cout << "////////////////////////////////////"<< endl; cout << selectOption.str(); cout << "////////////////////////////////////"<< endl; cout << "ѡһ:"; - + int select = -1; bool isRepeat = true; while (isRepeat) @@ -140,12 +140,12 @@ int acurayTestMain() { selectOption << acuray_option[i] << endl; } - + cout << "////////////////////////////////////"<< endl; cout << selectOption.str(); cout << "////////////////////////////////////"<< endl; cout << "ѡһ:"; - + int select = -1; bool isRepeat = true; while (isRepeat) @@ -204,12 +204,12 @@ int svmMain() { selectOption << svm_option[i] << endl; } - + cout << "////////////////////////////////////"<< endl; cout << selectOption.str(); cout << "////////////////////////////////////"<< endl; cout << "ѡһ:"; - + int select = -1; bool isRepeat = true; while (isRepeat) @@ -302,11 +302,11 @@ void cmdMain(int argc, char *argv[]) " $ ./EasyPR -p -l -t ", NULL }; - + CParser parser(argc, argv); - + try { - + do { if (parser.has_or(2, "help", "h") /* || argc < 2 */) { int i = 0; @@ -315,44 +315,44 @@ void cmdMain(int argc, char *argv[]) } break; } - + // tests - + if (parser.has_or(2, "test_plate_locate", "-tpl")) { cout << (test_plate_locate() == 0 ? "passed" : "failed"); break; } - + if (parser.has_or(2, "test_plate_judge", "-tpj")) { cout << (test_plate_judge() == 0 ? "passed" : "failed"); break; } - + if (parser.has_or(2, "test_plate_detect", "-tpd")) { cout << (test_plate_detect() == 0 ? "passed" : "failed"); break; } - + if (parser.has_or(2, "test_chars_segment", "-tcs")) { cout << (test_chars_segment() == 0 ? "passed" : "failed"); break; } - + if (parser.has_or(2, "test_chars_identify", "-tci")) { cout << (test_chars_identify() == 0 ? "passed" : "failed"); break; } - + if (parser.has_or(2, "test_chars_recognize", "-tcr")) { cout << (test_chars_recognise() == 0 ? "passed" : "failed"); break; } - + if (parser.has_or(2, "test_plate_recognize", "-tpr")) { cout << (test_plate_recognize() == 0 ? "passed" : "failed"); break; } - + if (parser.has_or(2, "test_all", "-ta")) { cout << "test_plate_locate " << (test_plate_locate() == 0 ? "passed" : "failed") << endl; cout << "test_plate_judge " << (test_plate_judge() == 0 ? "passed" : "failed") << endl; @@ -364,45 +364,45 @@ void cmdMain(int argc, char *argv[]) cout << "test_plate_locate " << (test_plate_locate() == 0 ? "passed" : "failed") << endl; break; } - + // batch testing - + if (parser.has_or(2, "general_test", "-gt")) { acurayTest(GENERAL_TEST_PATH); break; } - + if (parser.has_or(2, "native_test", "-nt")) { acurayTest(NATIVE_TEST_PATH); break; } - + // svm trains - + if (parser.has_or(2, "svm_gen_learndata", "-sgl")) { getLearnData(); break; } - + if (parser.has_or(2, "svm_tag_learndata", "-stl")) { label_data(); break; } - + if (parser.has_or(2, "svm_detect", "-sd")) { svmTrain(parser.has_or(2, "v", "svm_divide"), parser.has_or(2, "t", "svm_train")); break; } - + // GDTS - + if (parser.has_or(2, "gdts", "gts")) { general_test(); break; } - - // - + + // + if (parser.has("group")) { // Ŷ; cout << endl; @@ -413,7 +413,7 @@ void cmdMain(int argc, char *argv[]) cout << endl; break; } - + if (parser.has("thanks")) { // л cout << endl; @@ -424,9 +424,9 @@ void cmdMain(int argc, char *argv[]) cout << endl; break; } - + } while(false); - + } catch (const std::exception &err) { cout << err.what() << endl; } diff --git a/src/test/accuracy_test.cpp b/src/test/accuracy_test.cpp index f8509ad..ec0f7fa 100644 --- a/src/test/accuracy_test.cpp +++ b/src/test/accuracy_test.cpp @@ -3,7 +3,7 @@ #include "../include/plate_recognize.h" #include "../include/util.h" -#include "../include/features.h" +#include "../include/feature.h" using namespace easypr; @@ -183,4 +183,4 @@ int acurayTest(const string& test_path) { cout << "Unable to open file"; } return 0; -} \ No newline at end of file +} diff --git a/src/train/ann_train.cpp b/src/train/ann_train.cpp index 30b0d44..5933d77 100644 --- a/src/train/ann_train.cpp +++ b/src/train/ann_train.cpp @@ -23,7 +23,7 @@ #include #include "../include/plate_recognize.h" -#include "../include/features.h" +#include "../include/feature.h" #include "../include/util.h" using namespace easypr; @@ -59,14 +59,14 @@ Mat features(Mat in, int sizeData){ //Histogram features Mat vhist=ProjectedHistogram(in,VERTICAL); Mat hhist=ProjectedHistogram(in,HORIZONTAL); - + //Low data feature Mat lowData; resize(in, lowData, Size(sizeData, sizeData) ); - + //Last 10 is the number of moments components int numCols=vhist.cols+hhist.cols+lowData.cols*lowData.cols; - + Mat out=Mat::zeros(1,numCols,CV_32F); //Asign values to feature,ANNΪˮƽֱֱͼ͵ͷֱͼɵʸ int j=0; @@ -100,7 +100,7 @@ void annTrain(Mat TrainData, Mat classes, int nNeruns) layers.at(1) = nNeruns; layers.at(2) = numAll; ann.create(layers, CvANN_MLP::SIGMOID_SYM, 1, 1); - + //Prepare trainClases //Create a mat with n trained data by m classes Mat trainClasses; @@ -117,7 +117,7 @@ void annTrain(Mat TrainData, Mat classes, int nNeruns) } } Mat weights( 1, TrainData.rows, CV_32FC1, Scalar::all(1) ); - + //Learn classifier ann.train( TrainData, trainClasses, weights ); } @@ -130,18 +130,18 @@ int saveTrainData() Mat trainingDataf10; Mat trainingDataf15; Mat trainingDataf20; - + vector trainingLabels; string path = "train/data/chars_recognise_ann/chars2/chars2"; - + for(int i = 0; i < numCharacter; i++) { cout << "Character: "<< strCharacters[i] << "\n"; stringstream ss(stringstream::in | stringstream::out); ss << path << "/" << strCharacters[i]; - + auto files = Utils::getFiles(ss.str()); - + int size = files.size(); for (int j = 0; j < size; j++) { @@ -151,7 +151,7 @@ int saveTrainData() Mat f10=features(img, 10); Mat f15=features(img, 15); Mat f20=features(img, 20); - + trainingDataf5.push_back(f5); trainingDataf10.push_back(f10); trainingDataf15.push_back(f15); @@ -159,9 +159,9 @@ int saveTrainData() trainingLabels.push_back(i); //ÿһַͼƬӦַ± } } - + path = "train/data/chars_recognise_ann/charsChinese/charsChinese"; - + for (int i = 0; i < numChinese; i++) { cout << "Character: "<< strChinese[i] << "\n"; @@ -169,7 +169,7 @@ int saveTrainData() ss << path << "/" << strChinese[i]; auto files = Utils::getFiles(ss.str()); - + int size = files.size(); for (int j = 0; j < size; j++) { @@ -179,7 +179,7 @@ int saveTrainData() Mat f10=features(img, 10); Mat f15=features(img, 15); Mat f20=features(img, 20); - + trainingDataf5.push_back(f5); trainingDataf10.push_back(f10); trainingDataf15.push_back(f15); @@ -187,13 +187,13 @@ int saveTrainData() trainingLabels.push_back(i + numCharacter); } } - + trainingDataf5.convertTo(trainingDataf5, CV_32FC1); trainingDataf10.convertTo(trainingDataf10, CV_32FC1); trainingDataf15.convertTo(trainingDataf15, CV_32FC1); trainingDataf20.convertTo(trainingDataf20, CV_32FC1); Mat(trainingLabels).copyTo(classes); - + FileStorage fs("train/ann_data.xml", FileStorage::WRITE); fs << "TrainingDataF5" << trainingDataf5; fs << "TrainingDataF10" << trainingDataf10; @@ -201,9 +201,9 @@ int saveTrainData() fs << "TrainingDataF20" << trainingDataf20; fs << "classes" << classes; fs.release(); - + cout << "End saveTrainData" << endl; - + return 0; } @@ -211,10 +211,10 @@ void saveModel(int _predictsize, int _neurons) { FileStorage fs; fs.open("train/ann_data.xml", FileStorage::READ); - + Mat TrainingData; Mat Classes; - + string training; if(1) { @@ -222,21 +222,21 @@ void saveModel(int _predictsize, int _neurons) ss << "TrainingDataF" << _predictsize; training = ss.str(); } - + fs[training] >> TrainingData; fs["classes"] >> Classes; - + //train the Ann cout << "Begin to saveModelChar predictSize:" << _predictsize << " neurons:" << _neurons << endl; - + long start = Utils::getTimestamp(); annTrain(TrainingData, Classes, _neurons); long end = Utils::getTimestamp(); cout << "Elapse:" << (end-start)/1000 << endl; - + cout << "End the saveModelChar" << endl; - + string model_name = "train/ann.xml"; //if(1) //{ @@ -244,7 +244,7 @@ void saveModel(int _predictsize, int _neurons) // ss << "ann_prd" << _predictsize << "_neu"<< _neurons << ".xml"; // model_name = ss.str(); //} - + FileStorage fsTo(model_name, cv::FileStorage::WRITE); ann.write(*fsTo, "ann"); } @@ -252,9 +252,9 @@ void saveModel(int _predictsize, int _neurons) int annMain() { cout << "To be begin." << endl; - + saveTrainData(); - + //ɸҪѵͬpredictSizeneuronsANNģ //for (int i = 2; i <= 2; i ++) //{ @@ -265,11 +265,11 @@ int annMain() // saveModel(size, neurons); // } //} - + //ʾֻѵmodelļµann.xmlģһpredictSize=10,neurons=40ANNģ͡ //ݻIJͬѵʱ䲻һһҪ10ңһɡ saveModel(10, 40); - + cout << "To be end." << endl; int end; cin >> end; diff --git a/src/train/svm_train.cpp b/src/train/svm_train.cpp index 2c6c8d3..69d6dc6 100644 --- a/src/train/svm_train.cpp +++ b/src/train/svm_train.cpp @@ -1,7 +1,7 @@ // svm_train.cpp : svmģ͵ѵļҪplate_detect #include "../include/plate_recognize.h" -#include "../include/features.h" +#include "../include/feature.h" #include "../include/util.h" /*! \namespace easypr @@ -34,7 +34,7 @@ void learn2HasPlate(float bound = 0.7) cout << files[i].c_str() << endl; Mat img = imread(files[i].c_str()); if(1) - { + { stringstream ss(stringstream::in | stringstream::out); ss << "train/data/plate_detect_svm/train/HasPlate/hasplate_" << i << ".jpg"; imwrite(ss.str(), img); @@ -47,7 +47,7 @@ void learn2HasPlate(float bound = 0.7) cout << files[i].c_str() << endl; Mat img = imread(files[i].c_str()); if(1) - { + { stringstream ss(stringstream::in | stringstream::out); ss << "train/data/plate_detect_svm/test/HasPlate/hasplate_" << i << ".jpg"; imwrite(ss.str(), img); @@ -79,7 +79,7 @@ void learn2NoPlate(float bound = 0.7) cout << files[i].c_str() << endl; Mat img = imread(files[i].c_str()); if(1) - { + { stringstream ss(stringstream::in | stringstream::out); ss << "train/data/plate_detect_svm/train/NoPlate/noplate_" << i << ".jpg"; imwrite(ss.str(), img); @@ -92,7 +92,7 @@ void learn2NoPlate(float bound = 0.7) cout << files[i].c_str() << endl; Mat img = imread(files[i].c_str()); if(1) - { + { stringstream ss(stringstream::in | stringstream::out); ss << "train/data/plate_detect_svm/test/NoPlate/noplate_" << i << ".jpg"; imwrite(ss.str(), img); @@ -100,7 +100,7 @@ void learn2NoPlate(float bound = 0.7) } } -void getHasPlateTrain(Mat& trainingImages, vector& trainingLabels, +void getHasPlateTrain(Mat& trainingImages, vector& trainingLabels, svmCallback getFeatures = getHisteqFeatures) { int label = 1; @@ -131,7 +131,7 @@ void getHasPlateTrain(Mat& trainingImages, vector& trainingLabels, } -void getNoPlateTrain(Mat& trainingImages, vector& trainingLabels, +void getNoPlateTrain(Mat& trainingImages, vector& trainingLabels, svmCallback getFeatures = getHisteqFeatures) { int label = 0; @@ -356,14 +356,14 @@ int svmTrain(bool dividePrepared = true, bool trainPrepared = true, //Train SVM cout << "Begin to generate svm" << endl; - + try { //CvSVM svm(trainingData, classes, Mat(), Mat(), SVM_params); - svm.train_auto(trainingData, classes, Mat(), Mat(), SVM_params, 10, + svm.train_auto(trainingData, classes, Mat(), Mat(), SVM_params, 10, CvSVM::get_default_grid(CvSVM::C), - CvSVM::get_default_grid(CvSVM::GAMMA), - CvSVM::get_default_grid(CvSVM::P), - CvSVM::get_default_grid(CvSVM::NU), + CvSVM::get_default_grid(CvSVM::GAMMA), + CvSVM::get_default_grid(CvSVM::P), + CvSVM::get_default_grid(CvSVM::NU), CvSVM::get_default_grid(CvSVM::COEF), CvSVM::get_default_grid(CvSVM::DEGREE), true); diff --git a/src/util/deface.cpp b/src/util/deface.cpp index 6c62c6f..670a983 100644 --- a/src/util/deface.cpp +++ b/src/util/deface.cpp @@ -21,7 +21,7 @@ #include "../include/plate_recognize.h" #include "../include/util.h" -#include "../include/features.h" +#include "../include/feature.h" using namespace std; using namespace cv; @@ -32,8 +32,8 @@ Mat detectAndMaskFace(Mat& img, CascadeClassifier& cascade, // ʶ // ڷݵgeneral_testݼķͼд // EasyPRԴĿdzעرͼƬмʻ˵˽ -int deface() -{ +int deface() +{ CascadeClassifier cascade; //string cascadeName="/Users/zhoushiwei/Dropbox/Avatar/SDMLIB/haarcascade_frontalface_alt2.xml"; string cascadeName="model/haarcascade_frontalface_default.xml"; @@ -104,10 +104,10 @@ Mat detectAndMaskFace(Mat& img, CascadeClassifier& cascade, double scale) roi.at(jj,ii*3+2)=s2; } } - + } } } - + return img; } diff --git a/src/util/general_test_prepare.cpp b/src/util/general_test_prepare.cpp index 43ff83e..4b4601d 100644 --- a/src/util/general_test_prepare.cpp +++ b/src/util/general_test_prepare.cpp @@ -4,7 +4,7 @@ #include "../include/plate_recognize.h" #include "../include/util.h" -#include "../include/features.h" +#include "../include/feature.h" using namespace easypr; @@ -20,40 +20,40 @@ int general_test() { ////ȡ·µļ auto files = Utils::getFiles(src_path); - + CPlateLocate lo; CPlateJudge ju; CPlateRecognize pr; - + pr.LoadANN("model/ann.xml"); pr.LoadSVM("model/svm.xml"); pr.setLifemode(true); - + int size = files.size(); //int size = 200; - + if (0 == size) { cout << "No File Found!" << endl; return 0; } - + cout << "Begin to prepare general_test!" << endl; - + for (int i = 0; i < size; i++) { string filepath = files[i].c_str(); cout << "------------------" << endl; - + // EasyPRʼжϳ Mat src = imread(filepath); vector plateVec; - + int result = pr.plateRecognize(src, plateVec); if (result == 0) { int num = plateVec.size(); - + if (num == 0) { cout << ""<< "޳" < spilt_plate = Utils::splitString(colorplate, ':'); - + int size = spilt_plate.size(); if (size == 2) { @@ -74,12 +74,12 @@ int general_test() imwrite(ss.str(), src); } } - } + } else { cout << ":" << result << endl; } } - + return 0; -} \ No newline at end of file +} diff --git a/src/util/generate_gdts.cpp b/src/util/generate_gdts.cpp index 938ea6b..f4dd469 100644 --- a/src/util/generate_gdts.cpp +++ b/src/util/generate_gdts.cpp @@ -5,7 +5,7 @@ #include "../include/plate_recognize.h" #include "../include/util.h" -#include "../include/features.h" +#include "../include/feature.h" using namespace easypr; @@ -65,7 +65,7 @@ int generate_gdts() if (spiltsize != 0) filename = spilt_path[spiltsize-1]; - + stringstream ss(stringstream::in | stringstream::out); ss << dst_path << "/" << filename; imwrite(ss.str(), dst); @@ -119,4 +119,4 @@ Mat imageProcess(Mat img) Mat dst = img(rect); //GaussianBlur( dst, dst, Size(1, 1), 0, 0, BORDER_DEFAULT ); return dst; -} \ No newline at end of file +}