rename `features.h` => `feature.h`, `features.cpp` => `feature.cpp`

1.3
FuGangqiang 10 years ago
parent 4b94d82933
commit 2512b438cc

@ -14,7 +14,7 @@ set(SOURCE_FILES
src/core/chars_identify.cpp src/core/chars_identify.cpp
src/core/chars_recognise.cpp src/core/chars_recognise.cpp
src/core/chars_segment.cpp src/core/chars_segment.cpp
src/core/features.cpp src/core/feature.cpp
src/core/plate.cpp src/core/plate.cpp
src/core/plate_detect.cpp src/core/plate_detect.cpp
src/core/plate_judge.cpp src/core/plate_judge.cpp

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations"> <ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32"> <ProjectConfiguration Include="Debug|Win32">
@ -91,7 +91,7 @@
<ClCompile Include="src\core\chars_identify.cpp" /> <ClCompile Include="src\core\chars_identify.cpp" />
<ClCompile Include="src\core\chars_recognise.cpp" /> <ClCompile Include="src\core\chars_recognise.cpp" />
<ClCompile Include="src\core\chars_segment.cpp" /> <ClCompile Include="src\core\chars_segment.cpp" />
<ClCompile Include="src\core\features.cpp" /> <ClCompile Include="src\core\feature.cpp" />
<ClCompile Include="src\core\plate.cpp" /> <ClCompile Include="src\core\plate.cpp" />
<ClCompile Include="src\core\core_func.cpp" /> <ClCompile Include="src\core\core_func.cpp" />
<ClCompile Include="src\test\accuracy_test.cpp" /> <ClCompile Include="src\test\accuracy_test.cpp" />
@ -116,7 +116,7 @@
<ClInclude Include="src\include\chars_recognise.h" /> <ClInclude Include="src\include\chars_recognise.h" />
<ClInclude Include="src\include\chars_segment.h" /> <ClInclude Include="src\include\chars_segment.h" />
<ClInclude Include="src\include\CParser.h" /> <ClInclude Include="src\include\CParser.h" />
<ClInclude Include="src\include\features.h" /> <ClInclude Include="src\include\feature.h" />
<ClInclude Include="src\include\plate.h" /> <ClInclude Include="src\include\plate.h" />
<ClInclude Include="src\include\plate_detect.h" /> <ClInclude Include="src\include\plate_detect.h" />
<ClInclude Include="src\include\plate_judge.h" /> <ClInclude Include="src\include\plate_judge.h" />
@ -129,4 +129,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
</ImportGroup> </ImportGroup>
</Project> </Project>

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup> <ItemGroup>
<Filter Include="源文件"> <Filter Include="源文件">
@ -60,7 +60,7 @@
<ClCompile Include="src\core\plate_recognize.cpp"> <ClCompile Include="src\core\plate_recognize.cpp">
<Filter>源文件</Filter> <Filter>源文件</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="src\core\features.cpp"> <ClCompile Include="src\core\feature.cpp">
<Filter>源文件</Filter> <Filter>源文件</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="src\test\test.cpp"> <ClCompile Include="src\test\test.cpp">
@ -125,7 +125,7 @@
<ClInclude Include="src\include\util.h"> <ClInclude Include="src\include\util.h">
<Filter>头文件</Filter> <Filter>头文件</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="src\include\features.h"> <ClInclude Include="src\include\feature.h">
<Filter>头文件</Filter> <Filter>头文件</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="src\include\CParser.h"> <ClInclude Include="src\include\CParser.h">
@ -138,4 +138,4 @@
<Filter>头文件</Filter> <Filter>头文件</Filter>
</ClInclude> </ClInclude>
</ItemGroup> </ItemGroup>
</Project> </Project>

@ -3,7 +3,7 @@
// 这个部分中的特征由easypr的开发者修改 // 这个部分中的特征由easypr的开发者修改
#include "../include/prep.h" #include "../include/prep.h"
#include "../include/features.h" #include "../include/feature.h"
#include "../include/core_func.h" #include "../include/core_func.h"
/*! \namespace easypr /*! \namespace easypr
@ -87,4 +87,4 @@ namespace easypr {
//TODO //TODO
} }
} /* \namespace easypr */ } /* \namespace easypr */

@ -1,5 +1,5 @@
#ifndef __FEATURES_H__ #ifndef __FEATURE_H__
#define __FEATURES_H__ #define __FEATURE_H__
/*! \namespace easypr /*! \namespace easypr
Namespace where all the C++ EasyPR functionality resides Namespace where all the C++ EasyPR functionality resides
@ -33,4 +33,4 @@ namespace easypr {
} /*! \namespace easypr*/ } /*! \namespace easypr*/
#endif #endif
/* endif __FEATURES_H__ */ /* endif __FEATURE_H__ */

@ -7,7 +7,7 @@
// Copyright: liuruoze // Copyright: liuruoze
// Reference: Mastering OpenCV with Practical Computer Vision Projects // Reference: Mastering OpenCV with Practical Computer Vision Projects
// Reference: CSDN Bloger taotao1233 // Reference: CSDN Bloger taotao1233
// Desciption: // Desciption:
// Defines CPlateLocate // Defines CPlateLocate
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
#ifndef __PLATE_JUDGE_H__ #ifndef __PLATE_JUDGE_H__
@ -15,7 +15,7 @@
#include "prep.h" #include "prep.h"
#include "plate.h" #include "plate.h"
#include "features.h" #include "feature.h"
#include "core_func.h" #include "core_func.h"
/*! \namespace easypr /*! \namespace easypr
@ -23,7 +23,7 @@
*/ */
namespace easypr { namespace easypr {
class CPlateJudge class CPlateJudge
{ {
public: public:
CPlateJudge(); CPlateJudge();
@ -64,4 +64,4 @@ private:
} /*! \namespace easypr*/ } /*! \namespace easypr*/
#endif /* endif __PLATE_JUDGE_H__ */ #endif /* endif __PLATE_JUDGE_H__ */

@ -1,6 +1,6 @@
#include "include/plate_recognize.h" #include "include/plate_recognize.h"
#include "include/util.h" #include "include/util.h"
#include "include/features.h" #include "include/feature.h"
#include "include/CParser.h" #include "include/CParser.h"
using namespace easypr; using namespace easypr;
@ -10,10 +10,10 @@ int acurayTestMain();
void cmdMain(int argc, char *argv[]); void cmdMain(int argc, char *argv[]);
namespace easypr { namespace easypr {
int svmTrain(bool dividePrepared = true, bool trainPrepared = true, int svmTrain(bool dividePrepared = true, bool trainPrepared = true,
svmCallback getFeatures = getHistogramFeatures); svmCallback getFeatures = getHistogramFeatures);
} }
extern const string GENERAL_TEST_PATH = "image/general_test"; extern const string GENERAL_TEST_PATH = "image/general_test";
@ -43,7 +43,7 @@ int main(int argc, char *argv[])
cmdMain(argc, argv); cmdMain(argc, argv);
return 0; return 0;
} }
bool isExit = false; bool isExit = false;
while (isExit != true) while (isExit != true)
{ {
@ -53,12 +53,12 @@ int main(int argc, char *argv[])
{ {
selectOption << option[i] << endl; selectOption << option[i] << endl;
} }
cout << "////////////////////////////////////"<< endl; cout << "////////////////////////////////////"<< endl;
cout << selectOption.str(); cout << selectOption.str();
cout << "////////////////////////////////////"<< endl; cout << "////////////////////////////////////"<< endl;
cout << "请选择一项操作:"; cout << "请选择一项操作:";
int select = -1; int select = -1;
bool isRepeat = true; bool isRepeat = true;
while (isRepeat) while (isRepeat)
@ -140,12 +140,12 @@ int acurayTestMain()
{ {
selectOption << acuray_option[i] << endl; selectOption << acuray_option[i] << endl;
} }
cout << "////////////////////////////////////"<< endl; cout << "////////////////////////////////////"<< endl;
cout << selectOption.str(); cout << selectOption.str();
cout << "////////////////////////////////////"<< endl; cout << "////////////////////////////////////"<< endl;
cout << "请选择一项操作:"; cout << "请选择一项操作:";
int select = -1; int select = -1;
bool isRepeat = true; bool isRepeat = true;
while (isRepeat) while (isRepeat)
@ -204,12 +204,12 @@ int svmMain()
{ {
selectOption << svm_option[i] << endl; selectOption << svm_option[i] << endl;
} }
cout << "////////////////////////////////////"<< endl; cout << "////////////////////////////////////"<< endl;
cout << selectOption.str(); cout << selectOption.str();
cout << "////////////////////////////////////"<< endl; cout << "////////////////////////////////////"<< endl;
cout << "请选择一项操作:"; cout << "请选择一项操作:";
int select = -1; int select = -1;
bool isRepeat = true; bool isRepeat = true;
while (isRepeat) while (isRepeat)
@ -302,11 +302,11 @@ void cmdMain(int argc, char *argv[])
" $ ./EasyPR -p -l -t ", " $ ./EasyPR -p -l -t ",
NULL NULL
}; };
CParser parser(argc, argv); CParser parser(argc, argv);
try { try {
do { do {
if (parser.has_or(2, "help", "h") /* || argc < 2 */) { if (parser.has_or(2, "help", "h") /* || argc < 2 */) {
int i = 0; int i = 0;
@ -315,44 +315,44 @@ void cmdMain(int argc, char *argv[])
} }
break; break;
} }
// tests // tests
if (parser.has_or(2, "test_plate_locate", "-tpl")) { if (parser.has_or(2, "test_plate_locate", "-tpl")) {
cout << (test_plate_locate() == 0 ? "passed" : "failed"); cout << (test_plate_locate() == 0 ? "passed" : "failed");
break; break;
} }
if (parser.has_or(2, "test_plate_judge", "-tpj")) { if (parser.has_or(2, "test_plate_judge", "-tpj")) {
cout << (test_plate_judge() == 0 ? "passed" : "failed"); cout << (test_plate_judge() == 0 ? "passed" : "failed");
break; break;
} }
if (parser.has_or(2, "test_plate_detect", "-tpd")) { if (parser.has_or(2, "test_plate_detect", "-tpd")) {
cout << (test_plate_detect() == 0 ? "passed" : "failed"); cout << (test_plate_detect() == 0 ? "passed" : "failed");
break; break;
} }
if (parser.has_or(2, "test_chars_segment", "-tcs")) { if (parser.has_or(2, "test_chars_segment", "-tcs")) {
cout << (test_chars_segment() == 0 ? "passed" : "failed"); cout << (test_chars_segment() == 0 ? "passed" : "failed");
break; break;
} }
if (parser.has_or(2, "test_chars_identify", "-tci")) { if (parser.has_or(2, "test_chars_identify", "-tci")) {
cout << (test_chars_identify() == 0 ? "passed" : "failed"); cout << (test_chars_identify() == 0 ? "passed" : "failed");
break; break;
} }
if (parser.has_or(2, "test_chars_recognize", "-tcr")) { if (parser.has_or(2, "test_chars_recognize", "-tcr")) {
cout << (test_chars_recognise() == 0 ? "passed" : "failed"); cout << (test_chars_recognise() == 0 ? "passed" : "failed");
break; break;
} }
if (parser.has_or(2, "test_plate_recognize", "-tpr")) { if (parser.has_or(2, "test_plate_recognize", "-tpr")) {
cout << (test_plate_recognize() == 0 ? "passed" : "failed"); cout << (test_plate_recognize() == 0 ? "passed" : "failed");
break; break;
} }
if (parser.has_or(2, "test_all", "-ta")) { if (parser.has_or(2, "test_all", "-ta")) {
cout << "test_plate_locate " << (test_plate_locate() == 0 ? "passed" : "failed") << endl; cout << "test_plate_locate " << (test_plate_locate() == 0 ? "passed" : "failed") << endl;
cout << "test_plate_judge " << (test_plate_judge() == 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; cout << "test_plate_locate " << (test_plate_locate() == 0 ? "passed" : "failed") << endl;
break; break;
} }
// batch testing // batch testing
if (parser.has_or(2, "general_test", "-gt")) { if (parser.has_or(2, "general_test", "-gt")) {
acurayTest(GENERAL_TEST_PATH); acurayTest(GENERAL_TEST_PATH);
break; break;
} }
if (parser.has_or(2, "native_test", "-nt")) { if (parser.has_or(2, "native_test", "-nt")) {
acurayTest(NATIVE_TEST_PATH); acurayTest(NATIVE_TEST_PATH);
break; break;
} }
// svm trains // svm trains
if (parser.has_or(2, "svm_gen_learndata", "-sgl")) { if (parser.has_or(2, "svm_gen_learndata", "-sgl")) {
getLearnData(); getLearnData();
break; break;
} }
if (parser.has_or(2, "svm_tag_learndata", "-stl")) { if (parser.has_or(2, "svm_tag_learndata", "-stl")) {
label_data(); label_data();
break; break;
} }
if (parser.has_or(2, "svm_detect", "-sd")) { if (parser.has_or(2, "svm_detect", "-sd")) {
svmTrain(parser.has_or(2, "v", "svm_divide"), parser.has_or(2, "t", "svm_train")); svmTrain(parser.has_or(2, "v", "svm_divide"), parser.has_or(2, "t", "svm_train"));
break; break;
} }
// GDTS // GDTS
if (parser.has_or(2, "gdts", "gts")) { if (parser.has_or(2, "gdts", "gts")) {
general_test(); general_test();
break; break;
} }
// //
if (parser.has("group")) { if (parser.has("group")) {
// 开发团队; // 开发团队;
cout << endl; cout << endl;
@ -413,7 +413,7 @@ void cmdMain(int argc, char *argv[])
cout << endl; cout << endl;
break; break;
} }
if (parser.has("thanks")) { if (parser.has("thanks")) {
// 感谢名单 // 感谢名单
cout << endl; cout << endl;
@ -424,9 +424,9 @@ void cmdMain(int argc, char *argv[])
cout << endl; cout << endl;
break; break;
} }
} while(false); } while(false);
} catch (const std::exception &err) { } catch (const std::exception &err) {
cout << err.what() << endl; cout << err.what() << endl;
} }

@ -3,7 +3,7 @@
#include "../include/plate_recognize.h" #include "../include/plate_recognize.h"
#include "../include/util.h" #include "../include/util.h"
#include "../include/features.h" #include "../include/feature.h"
using namespace easypr; using namespace easypr;
@ -183,4 +183,4 @@ int acurayTest(const string& test_path) {
cout << "Unable to open file"; cout << "Unable to open file";
} }
return 0; return 0;
} }

@ -23,7 +23,7 @@
#include <stdio.h> #include <stdio.h>
#include "../include/plate_recognize.h" #include "../include/plate_recognize.h"
#include "../include/features.h" #include "../include/feature.h"
#include "../include/util.h" #include "../include/util.h"
using namespace easypr; using namespace easypr;
@ -59,14 +59,14 @@ Mat features(Mat in, int sizeData){
//Histogram features //Histogram features
Mat vhist=ProjectedHistogram(in,VERTICAL); Mat vhist=ProjectedHistogram(in,VERTICAL);
Mat hhist=ProjectedHistogram(in,HORIZONTAL); Mat hhist=ProjectedHistogram(in,HORIZONTAL);
//Low data feature //Low data feature
Mat lowData; Mat lowData;
resize(in, lowData, Size(sizeData, sizeData) ); resize(in, lowData, Size(sizeData, sizeData) );
//Last 10 is the number of moments components //Last 10 is the number of moments components
int numCols=vhist.cols+hhist.cols+lowData.cols*lowData.cols; int numCols=vhist.cols+hhist.cols+lowData.cols*lowData.cols;
Mat out=Mat::zeros(1,numCols,CV_32F); Mat out=Mat::zeros(1,numCols,CV_32F);
//Asign values to feature,ANN的样本特征为水平、垂直直方图和低分辨率图像所组成的矢量 //Asign values to feature,ANN的样本特征为水平、垂直直方图和低分辨率图像所组成的矢量
int j=0; int j=0;
@ -100,7 +100,7 @@ void annTrain(Mat TrainData, Mat classes, int nNeruns)
layers.at<int>(1) = nNeruns; layers.at<int>(1) = nNeruns;
layers.at<int>(2) = numAll; layers.at<int>(2) = numAll;
ann.create(layers, CvANN_MLP::SIGMOID_SYM, 1, 1); ann.create(layers, CvANN_MLP::SIGMOID_SYM, 1, 1);
//Prepare trainClases //Prepare trainClases
//Create a mat with n trained data by m classes //Create a mat with n trained data by m classes
Mat trainClasses; Mat trainClasses;
@ -117,7 +117,7 @@ void annTrain(Mat TrainData, Mat classes, int nNeruns)
} }
} }
Mat weights( 1, TrainData.rows, CV_32FC1, Scalar::all(1) ); Mat weights( 1, TrainData.rows, CV_32FC1, Scalar::all(1) );
//Learn classifier //Learn classifier
ann.train( TrainData, trainClasses, weights ); ann.train( TrainData, trainClasses, weights );
} }
@ -130,18 +130,18 @@ int saveTrainData()
Mat trainingDataf10; Mat trainingDataf10;
Mat trainingDataf15; Mat trainingDataf15;
Mat trainingDataf20; Mat trainingDataf20;
vector<int> trainingLabels; vector<int> trainingLabels;
string path = "train/data/chars_recognise_ann/chars2/chars2"; string path = "train/data/chars_recognise_ann/chars2/chars2";
for(int i = 0; i < numCharacter; i++) for(int i = 0; i < numCharacter; i++)
{ {
cout << "Character: "<< strCharacters[i] << "\n"; cout << "Character: "<< strCharacters[i] << "\n";
stringstream ss(stringstream::in | stringstream::out); stringstream ss(stringstream::in | stringstream::out);
ss << path << "/" << strCharacters[i]; ss << path << "/" << strCharacters[i];
auto files = Utils::getFiles(ss.str()); auto files = Utils::getFiles(ss.str());
int size = files.size(); int size = files.size();
for (int j = 0; j < size; j++) for (int j = 0; j < size; j++)
{ {
@ -151,7 +151,7 @@ int saveTrainData()
Mat f10=features(img, 10); Mat f10=features(img, 10);
Mat f15=features(img, 15); Mat f15=features(img, 15);
Mat f20=features(img, 20); Mat f20=features(img, 20);
trainingDataf5.push_back(f5); trainingDataf5.push_back(f5);
trainingDataf10.push_back(f10); trainingDataf10.push_back(f10);
trainingDataf15.push_back(f15); trainingDataf15.push_back(f15);
@ -159,9 +159,9 @@ int saveTrainData()
trainingLabels.push_back(i); //每一幅字符图片所对应的字符类别索引下标 trainingLabels.push_back(i); //每一幅字符图片所对应的字符类别索引下标
} }
} }
path = "train/data/chars_recognise_ann/charsChinese/charsChinese"; path = "train/data/chars_recognise_ann/charsChinese/charsChinese";
for (int i = 0; i < numChinese; i++) for (int i = 0; i < numChinese; i++)
{ {
cout << "Character: "<< strChinese[i] << "\n"; cout << "Character: "<< strChinese[i] << "\n";
@ -169,7 +169,7 @@ int saveTrainData()
ss << path << "/" << strChinese[i]; ss << path << "/" << strChinese[i];
auto files = Utils::getFiles(ss.str()); auto files = Utils::getFiles(ss.str());
int size = files.size(); int size = files.size();
for (int j = 0; j < size; j++) for (int j = 0; j < size; j++)
{ {
@ -179,7 +179,7 @@ int saveTrainData()
Mat f10=features(img, 10); Mat f10=features(img, 10);
Mat f15=features(img, 15); Mat f15=features(img, 15);
Mat f20=features(img, 20); Mat f20=features(img, 20);
trainingDataf5.push_back(f5); trainingDataf5.push_back(f5);
trainingDataf10.push_back(f10); trainingDataf10.push_back(f10);
trainingDataf15.push_back(f15); trainingDataf15.push_back(f15);
@ -187,13 +187,13 @@ int saveTrainData()
trainingLabels.push_back(i + numCharacter); trainingLabels.push_back(i + numCharacter);
} }
} }
trainingDataf5.convertTo(trainingDataf5, CV_32FC1); trainingDataf5.convertTo(trainingDataf5, CV_32FC1);
trainingDataf10.convertTo(trainingDataf10, CV_32FC1); trainingDataf10.convertTo(trainingDataf10, CV_32FC1);
trainingDataf15.convertTo(trainingDataf15, CV_32FC1); trainingDataf15.convertTo(trainingDataf15, CV_32FC1);
trainingDataf20.convertTo(trainingDataf20, CV_32FC1); trainingDataf20.convertTo(trainingDataf20, CV_32FC1);
Mat(trainingLabels).copyTo(classes); Mat(trainingLabels).copyTo(classes);
FileStorage fs("train/ann_data.xml", FileStorage::WRITE); FileStorage fs("train/ann_data.xml", FileStorage::WRITE);
fs << "TrainingDataF5" << trainingDataf5; fs << "TrainingDataF5" << trainingDataf5;
fs << "TrainingDataF10" << trainingDataf10; fs << "TrainingDataF10" << trainingDataf10;
@ -201,9 +201,9 @@ int saveTrainData()
fs << "TrainingDataF20" << trainingDataf20; fs << "TrainingDataF20" << trainingDataf20;
fs << "classes" << classes; fs << "classes" << classes;
fs.release(); fs.release();
cout << "End saveTrainData" << endl; cout << "End saveTrainData" << endl;
return 0; return 0;
} }
@ -211,10 +211,10 @@ void saveModel(int _predictsize, int _neurons)
{ {
FileStorage fs; FileStorage fs;
fs.open("train/ann_data.xml", FileStorage::READ); fs.open("train/ann_data.xml", FileStorage::READ);
Mat TrainingData; Mat TrainingData;
Mat Classes; Mat Classes;
string training; string training;
if(1) if(1)
{ {
@ -222,21 +222,21 @@ void saveModel(int _predictsize, int _neurons)
ss << "TrainingDataF" << _predictsize; ss << "TrainingDataF" << _predictsize;
training = ss.str(); training = ss.str();
} }
fs[training] >> TrainingData; fs[training] >> TrainingData;
fs["classes"] >> Classes; fs["classes"] >> Classes;
//train the Ann //train the Ann
cout << "Begin to saveModelChar predictSize:" << _predictsize cout << "Begin to saveModelChar predictSize:" << _predictsize
<< " neurons:" << _neurons << endl; << " neurons:" << _neurons << endl;
long start = Utils::getTimestamp(); long start = Utils::getTimestamp();
annTrain(TrainingData, Classes, _neurons); annTrain(TrainingData, Classes, _neurons);
long end = Utils::getTimestamp(); long end = Utils::getTimestamp();
cout << "Elapse:" << (end-start)/1000 << endl; cout << "Elapse:" << (end-start)/1000 << endl;
cout << "End the saveModelChar" << endl; cout << "End the saveModelChar" << endl;
string model_name = "train/ann.xml"; string model_name = "train/ann.xml";
//if(1) //if(1)
//{ //{
@ -244,7 +244,7 @@ void saveModel(int _predictsize, int _neurons)
// ss << "ann_prd" << _predictsize << "_neu"<< _neurons << ".xml"; // ss << "ann_prd" << _predictsize << "_neu"<< _neurons << ".xml";
// model_name = ss.str(); // model_name = ss.str();
//} //}
FileStorage fsTo(model_name, cv::FileStorage::WRITE); FileStorage fsTo(model_name, cv::FileStorage::WRITE);
ann.write(*fsTo, "ann"); ann.write(*fsTo, "ann");
} }
@ -252,9 +252,9 @@ void saveModel(int _predictsize, int _neurons)
int annMain() int annMain()
{ {
cout << "To be begin." << endl; cout << "To be begin." << endl;
saveTrainData(); saveTrainData();
//可根据需要训练不同的predictSize或者neurons的ANN模型 //可根据需要训练不同的predictSize或者neurons的ANN模型
//for (int i = 2; i <= 2; i ++) //for (int i = 2; i <= 2; i ++)
//{ //{
@ -265,11 +265,11 @@ int annMain()
// saveModel(size, neurons); // saveModel(size, neurons);
// } // }
//} //}
//这里演示只训练model文件夹下的ann.xml此模型是一个predictSize=10,neurons=40的ANN模型。 //这里演示只训练model文件夹下的ann.xml此模型是一个predictSize=10,neurons=40的ANN模型。
//根据机器的不同训练时间不一样但一般需要10分钟左右所以慢慢等一会吧。 //根据机器的不同训练时间不一样但一般需要10分钟左右所以慢慢等一会吧。
saveModel(10, 40); saveModel(10, 40);
cout << "To be end." << endl; cout << "To be end." << endl;
int end; int end;
cin >> end; cin >> end;

@ -1,7 +1,7 @@
// svm_train.cpp : svm模型的训练文件主要用在plate_detect中 // svm_train.cpp : svm模型的训练文件主要用在plate_detect中
#include "../include/plate_recognize.h" #include "../include/plate_recognize.h"
#include "../include/features.h" #include "../include/feature.h"
#include "../include/util.h" #include "../include/util.h"
/*! \namespace easypr /*! \namespace easypr
@ -34,7 +34,7 @@ void learn2HasPlate(float bound = 0.7)
cout << files[i].c_str() << endl; cout << files[i].c_str() << endl;
Mat img = imread(files[i].c_str()); Mat img = imread(files[i].c_str());
if(1) if(1)
{ {
stringstream ss(stringstream::in | stringstream::out); stringstream ss(stringstream::in | stringstream::out);
ss << "train/data/plate_detect_svm/train/HasPlate/hasplate_" << i << ".jpg"; ss << "train/data/plate_detect_svm/train/HasPlate/hasplate_" << i << ".jpg";
imwrite(ss.str(), img); imwrite(ss.str(), img);
@ -47,7 +47,7 @@ void learn2HasPlate(float bound = 0.7)
cout << files[i].c_str() << endl; cout << files[i].c_str() << endl;
Mat img = imread(files[i].c_str()); Mat img = imread(files[i].c_str());
if(1) if(1)
{ {
stringstream ss(stringstream::in | stringstream::out); stringstream ss(stringstream::in | stringstream::out);
ss << "train/data/plate_detect_svm/test/HasPlate/hasplate_" << i << ".jpg"; ss << "train/data/plate_detect_svm/test/HasPlate/hasplate_" << i << ".jpg";
imwrite(ss.str(), img); imwrite(ss.str(), img);
@ -79,7 +79,7 @@ void learn2NoPlate(float bound = 0.7)
cout << files[i].c_str() << endl; cout << files[i].c_str() << endl;
Mat img = imread(files[i].c_str()); Mat img = imread(files[i].c_str());
if(1) if(1)
{ {
stringstream ss(stringstream::in | stringstream::out); stringstream ss(stringstream::in | stringstream::out);
ss << "train/data/plate_detect_svm/train/NoPlate/noplate_" << i << ".jpg"; ss << "train/data/plate_detect_svm/train/NoPlate/noplate_" << i << ".jpg";
imwrite(ss.str(), img); imwrite(ss.str(), img);
@ -92,7 +92,7 @@ void learn2NoPlate(float bound = 0.7)
cout << files[i].c_str() << endl; cout << files[i].c_str() << endl;
Mat img = imread(files[i].c_str()); Mat img = imread(files[i].c_str());
if(1) if(1)
{ {
stringstream ss(stringstream::in | stringstream::out); stringstream ss(stringstream::in | stringstream::out);
ss << "train/data/plate_detect_svm/test/NoPlate/noplate_" << i << ".jpg"; ss << "train/data/plate_detect_svm/test/NoPlate/noplate_" << i << ".jpg";
imwrite(ss.str(), img); imwrite(ss.str(), img);
@ -100,7 +100,7 @@ void learn2NoPlate(float bound = 0.7)
} }
} }
void getHasPlateTrain(Mat& trainingImages, vector<int>& trainingLabels, void getHasPlateTrain(Mat& trainingImages, vector<int>& trainingLabels,
svmCallback getFeatures = getHisteqFeatures) svmCallback getFeatures = getHisteqFeatures)
{ {
int label = 1; int label = 1;
@ -131,7 +131,7 @@ void getHasPlateTrain(Mat& trainingImages, vector<int>& trainingLabels,
} }
void getNoPlateTrain(Mat& trainingImages, vector<int>& trainingLabels, void getNoPlateTrain(Mat& trainingImages, vector<int>& trainingLabels,
svmCallback getFeatures = getHisteqFeatures) svmCallback getFeatures = getHisteqFeatures)
{ {
int label = 0; int label = 0;
@ -356,14 +356,14 @@ int svmTrain(bool dividePrepared = true, bool trainPrepared = true,
//Train SVM //Train SVM
cout << "Begin to generate svm" << endl; cout << "Begin to generate svm" << endl;
try { try {
//CvSVM svm(trainingData, classes, Mat(), Mat(), SVM_params); //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::C),
CvSVM::get_default_grid(CvSVM::GAMMA), CvSVM::get_default_grid(CvSVM::GAMMA),
CvSVM::get_default_grid(CvSVM::P), CvSVM::get_default_grid(CvSVM::P),
CvSVM::get_default_grid(CvSVM::NU), CvSVM::get_default_grid(CvSVM::NU),
CvSVM::get_default_grid(CvSVM::COEF), CvSVM::get_default_grid(CvSVM::COEF),
CvSVM::get_default_grid(CvSVM::DEGREE), CvSVM::get_default_grid(CvSVM::DEGREE),
true); true);

@ -21,7 +21,7 @@
#include "../include/plate_recognize.h" #include "../include/plate_recognize.h"
#include "../include/util.h" #include "../include/util.h"
#include "../include/features.h" #include "../include/feature.h"
using namespace std; using namespace std;
using namespace cv; using namespace cv;
@ -32,8 +32,8 @@ Mat detectAndMaskFace(Mat& img, CascadeClassifier& cascade,
// 反人脸识别函数 // 反人脸识别函数
// 在发布数据到general_test数据集里请先用这里的方法对图像进行处理 // 在发布数据到general_test数据集里请先用这里的方法对图像进行处理
// EasyPR开源项目非常注重保护图片中驾驶人的隐私 // EasyPR开源项目非常注重保护图片中驾驶人的隐私
int deface() int deface()
{ {
CascadeClassifier cascade; CascadeClassifier cascade;
//string cascadeName="/Users/zhoushiwei/Dropbox/Avatar/SDMLIB/haarcascade_frontalface_alt2.xml"; //string cascadeName="/Users/zhoushiwei/Dropbox/Avatar/SDMLIB/haarcascade_frontalface_alt2.xml";
string cascadeName="model/haarcascade_frontalface_default.xml"; string cascadeName="model/haarcascade_frontalface_default.xml";
@ -104,10 +104,10 @@ Mat detectAndMaskFace(Mat& img, CascadeClassifier& cascade, double scale)
roi.at<uchar>(jj,ii*3+2)=s2; roi.at<uchar>(jj,ii*3+2)=s2;
} }
} }
} }
} }
} }
return img; return img;
} }

@ -4,7 +4,7 @@
#include "../include/plate_recognize.h" #include "../include/plate_recognize.h"
#include "../include/util.h" #include "../include/util.h"
#include "../include/features.h" #include "../include/feature.h"
using namespace easypr; using namespace easypr;
@ -20,40 +20,40 @@ int general_test()
{ {
////获取该路径下的所有文件 ////获取该路径下的所有文件
auto files = Utils::getFiles(src_path); auto files = Utils::getFiles(src_path);
CPlateLocate lo; CPlateLocate lo;
CPlateJudge ju; CPlateJudge ju;
CPlateRecognize pr; CPlateRecognize pr;
pr.LoadANN("model/ann.xml"); pr.LoadANN("model/ann.xml");
pr.LoadSVM("model/svm.xml"); pr.LoadSVM("model/svm.xml");
pr.setLifemode(true); pr.setLifemode(true);
int size = files.size(); int size = files.size();
//int size = 200; //int size = 200;
if (0 == size) if (0 == size)
{ {
cout << "No File Found!" << endl; cout << "No File Found!" << endl;
return 0; return 0;
} }
cout << "Begin to prepare general_test!" << endl; cout << "Begin to prepare general_test!" << endl;
for (int i = 0; i < size; i++) for (int i = 0; i < size; i++)
{ {
string filepath = files[i].c_str(); string filepath = files[i].c_str();
cout << "------------------" << endl; cout << "------------------" << endl;
// EasyPR开始判断车牌 // EasyPR开始判断车牌
Mat src = imread(filepath); Mat src = imread(filepath);
vector<string> plateVec; vector<string> plateVec;
int result = pr.plateRecognize(src, plateVec); int result = pr.plateRecognize(src, plateVec);
if (result == 0) if (result == 0)
{ {
int num = plateVec.size(); int num = plateVec.size();
if (num == 0) if (num == 0)
{ {
cout << ""<< "无车牌" <<endl; cout << ""<< "无车牌" <<endl;
@ -62,10 +62,10 @@ int general_test()
{ {
cout << plateVec[0] <<endl; cout << plateVec[0] <<endl;
string colorplate = plateVec[0]; string colorplate = plateVec[0];
// 输出"蓝牌:苏E7KU22"中冒号后面的车牌 // 输出"蓝牌:苏E7KU22"中冒号后面的车牌
vector<string> spilt_plate = Utils::splitString(colorplate, ':'); vector<string> spilt_plate = Utils::splitString(colorplate, ':');
int size = spilt_plate.size(); int size = spilt_plate.size();
if (size == 2) if (size == 2)
{ {
@ -74,12 +74,12 @@ int general_test()
imwrite(ss.str(), src); imwrite(ss.str(), src);
} }
} }
} }
else else
{ {
cout << "错误码:" << result << endl; cout << "错误码:" << result << endl;
} }
} }
return 0; return 0;
} }

@ -5,7 +5,7 @@
#include "../include/plate_recognize.h" #include "../include/plate_recognize.h"
#include "../include/util.h" #include "../include/util.h"
#include "../include/features.h" #include "../include/feature.h"
using namespace easypr; using namespace easypr;
@ -65,7 +65,7 @@ int generate_gdts()
if (spiltsize != 0) if (spiltsize != 0)
filename = spilt_path[spiltsize-1]; filename = spilt_path[spiltsize-1];
stringstream ss(stringstream::in | stringstream::out); stringstream ss(stringstream::in | stringstream::out);
ss << dst_path << "/" << filename; ss << dst_path << "/" << filename;
imwrite(ss.str(), dst); imwrite(ss.str(), dst);
@ -119,4 +119,4 @@ Mat imageProcess(Mat img)
Mat dst = img(rect); Mat dst = img(rect);
//GaussianBlur( dst, dst, Size(1, 1), 0, 0, BORDER_DEFAULT ); //GaussianBlur( dst, dst, Size(1, 1), 0, 0, BORDER_DEFAULT );
return dst; return dst;
} }

Loading…
Cancel
Save