add accuracy_test

1.3
Fenix 10 years ago
parent 5e1dbfd2d6
commit 4269b06a0c

1
.gitignore vendored

@ -21,6 +21,7 @@ build/
bld/
[Bb]in/
[Oo]bj/
general_test/
# Roslyn cache directories
*.ide/

@ -85,11 +85,12 @@
<ClCompile Include="src\core\chars_recognise.cpp" />
<ClCompile Include="src\core\chars_segment.cpp" />
<ClCompile Include="src\core\features.cpp" />
<ClCompile Include="src\test\accuracy_test.cpp" />
<ClCompile Include="src\train\ann_train.cpp" />
<ClCompile Include="src\train\svm_train.cpp" />
<ClCompile Include="src\util\mc_data_prepare.cpp" />
<ClCompile Include="src\main\main.cpp" />
<ClCompile Include="src\main\test.cpp" />
<ClCompile Include="src\test\test.cpp" />
<ClCompile Include="src\core\plate_detect.cpp" />
<ClCompile Include="src\core\plate_judge.cpp" />
<ClCompile Include="src\core\plate_locate.cpp" />

@ -62,15 +62,18 @@
<ClCompile Include="src\core\features.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="src\main\test.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="src\train\svm_train.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="src\train\ann_train.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="src\test\test.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="src\test\accuracy_test.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\include\chars_identify.h">

@ -45,6 +45,8 @@ int CPlateRecognize::plateRecognize(Mat src, vector<string>& licenseVec)
if (resultPD == 0)
{
int num = plateVec.size();
int resultCR = 0;
for (int j = 0; j < num; j++)
{
Mat plate = plateVec[j];

@ -8,6 +8,9 @@ void getFiles(string path, vector<string>& files);
//C++的spilt函数
void SplitString(const string& s, vector<string>& v, const string& c);
//C++的从文件路径名称到文件名称(不包括后缀)的方法
void getFileName(const string& filepath, string& name);
/// test.cpp中方法
int testMain();
@ -15,11 +18,13 @@ int testMain();
void getLearnData();
void Code2Province(const string& code, string& province);
void changeFileName();
void getPlateLicense(const string& filepath, string& plateLicense);
/// learn_prepare.cpp中方法
void label_data();
/// accuracy_test.cpp中方法
int acurayTest();
#endif
/* endif __UTIL_H__ */

@ -59,7 +59,7 @@ int main()
testMain();
break;
case 2:
// TODO
acurayTest();
break;
case 3:
svmMain();

@ -0,0 +1,74 @@
// 通用正确率测试文件
// AcurayTest对应到main控制命令中的选项2
#include "../include/plate_recognize.h"
#include "../include/util.h"
#include "../include/features.h"
using namespace easypr;
int acurayTest()
{
////获取该路径下的所有文件
vector<string> files;
getFiles("image/general_test", files);
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 in general_test!" << endl;
cout << "Begin to test the easypr accuracy!" << endl;
for (int i = 0; i < size; i++)
{
string filepath = files[i].c_str();
cout << "------------------" << endl;
// 获取真实的车牌
string plateLicense = "";
getFileName(filepath, plateLicense);
cout << "原牌:" << plateLicense << endl;
// EasyPR开始判断车牌
Mat src = imread(filepath);
vector<string> plateVec;
int result = pr.plateRecognize(src, plateVec);
if (result == 0)
{
int num = plateVec.size();
if (num == 0)
{
cout << ""<< "无车牌" <<endl;
}
else if ( num > 1)
{
for (int j = 0; j < num; j++)
cout << ""<< plateVec[j] << " (" << j+1 << ")"<<endl;
}
else
{
for (int j = 0; j < num; j++)
cout << ""<< plateVec[j] <<endl;
}
}
else
{
cout << "错误码:" << result << endl;
}
}
return 0;
}

@ -320,7 +320,7 @@ int test_plate_recognize()
cout << "test_plate_recognize" << endl;
//Mat src = imread("image/plate_locate.jpg");
Mat src = imread("image/1.png");
Mat src = imread("image/test.jpg");
CPlateRecognize pr;
pr.LoadANN("model/ann.xml");

@ -370,12 +370,12 @@ int svmTrain(bool dividePrepared = true, bool trainPrepared = true,
cout << "Svm generate done!" << endl;
FileStorage fsTo("train/model/svm.xml", cv::FileStorage::WRITE);
FileStorage fsTo("train/svm.xml", cv::FileStorage::WRITE);
svm.write(*fsTo, "svm");
}
else
{
string path = "train/model/svm.xml";
string path = "train/svm.xml";
svm.load(path.c_str(), "svm");
}

@ -20,8 +20,6 @@ char * notlabelPath = "F:/data/easypr-data/notlabel";
char * hasPaltePath = "F:/data/easypr-data/learn/hasPlate/";
char * noPlatePath = "F:/data/easypr-data/learn/noPlate/";
void getPlateLicense(const string& filepath, string& plateLicense);
//! 读取not label data生成learn data
void label_data()
{

@ -186,6 +186,7 @@ void getPlateLicense(const string& filepath, string& plateLicense)
}
}
//! MC将rawdata截取部分数据到learndata中
void getLearnData()
{

@ -52,3 +52,26 @@ void SplitString(const string& s, vector<string>& v, const string& c)
v.push_back(s.substr(pos1));
}
//! 通过文件夹名称获取文件名,不包括后缀
void getFileName(const string& filepath, string& name)
{
vector<string> spilt_path;
SplitString(filepath, spilt_path, "\\");
int spiltsize = spilt_path.size();
string filename = "";
if (spiltsize != 0)
{
filename = spilt_path[spiltsize-1];
vector<string> spilt_name;
SplitString(filename, spilt_name, ".");
int name_size = spilt_name.size();
if (name_size != 0)
{
name = spilt_name[0];
}
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save