Added easypr/config.h to save constants.

v1.6alpha
Micooz 11 years ago
parent 0e35129b7e
commit c2069d1272

@ -0,0 +1,36 @@
#ifndef EASYPR_TRAIN_TRAIN_H_
#define EASYPR_TRAIN_TRAIN_H_
namespace easypr{
static char *kDefaultSvmPath = "resources/model/svm.xml";
static char *kDefaultAnnPath = "resources/model/ann.xml";
static int kPredictSize = 10;
static char * kChinese[] = {
"zh_cuan" /* 川 */, "zh_e" /* 鄂 */, "zh_gan" /* 赣*/,
"zh_gan1" /*甘*/, "zh_gui" /* 贵 */, "zh_gui1" /* 桂 */,
"zh_hei" /* 黑 */, "zh_hu" /* 沪 */, "zh_ji" /* 冀 */,
"zh_jin" /* 津 */, "zh_jing" /* 京 */, "zh_jl" /* 吉 */,
"zh_liao" /* 辽 */, "zh_lu" /* 鲁 */, "zh_meng" /* 蒙 */,
"zh_min" /* 闽 */, "zh_ning" /* 宁 */, "zh_qing" /* 青 */,
"zh_qiong" /* 琼 */, "zh_shan" /* 陕 */, "zh_su" /* 苏 */,
"zh_sx" /* 晋 */, "zh_wan" /* 皖 */, "zh_xiang" /* 湘 */,
"zh_xin" /* 新 */, "zh_yu" /* 豫 */, "zh_yu1" /* 渝 */,
"zh_yue" /* 粤 */, "zh_yun" /* 云 */, "zh_zang" /* 藏 */,
"zh_zhe" /* 浙 */
};
static char kCharacters[] = {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', /* 没有I */
'J', 'K', 'L', 'M', 'N', /* 没有O */ 'P', 'Q',
'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
};
}
#endif // EASYPR_TRAIN_TRAIN_H_

@ -7,29 +7,6 @@
namespace easypr{
const char* kChinese[] = {
"zh_cuan" /* 川 */, "zh_e" /* 鄂 */, "zh_gan" /* 赣*/,
"zh_gan1" /*甘*/, "zh_gui" /* 贵 */, "zh_gui1" /* 桂 */,
"zh_hei" /* 黑 */, "zh_hu" /* 沪 */, "zh_ji" /* 冀 */,
"zh_jin" /* 津 */, "zh_jing" /* 京 */, "zh_jl" /* 吉 */,
"zh_liao" /* 辽 */, "zh_lu" /* 鲁 */, "zh_meng" /* 蒙 */,
"zh_min" /* 闽 */, "zh_ning" /* 宁 */, "zh_qing" /* 青 */,
"zh_qiong" /* 琼 */, "zh_shan" /* 陕 */, "zh_su" /* 苏 */,
"zh_sx" /* 晋 */, "zh_wan" /* 皖 */, "zh_xiang" /* 湘 */,
"zh_xin" /* 新 */, "zh_yu" /* 豫 */, "zh_yu1" /* 渝 */,
"zh_yue" /* 粤 */, "zh_yun" /* 云 */, "zh_zang" /* 藏 */,
"zh_zhe" /* 浙 */
};
const char kCharacters[] = {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', /* 没有I */
'J', 'K', 'L', 'M', 'N', /* 没有O */ 'P', 'Q',
'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
};
const int kPredictSize = 10;
class AnnTrain{
public:
explicit AnnTrain(const char* chars_folder, const char* zhchars_folder, const char* xml);

@ -3,45 +3,45 @@
#include <vector>
#include <opencv2/opencv.hpp>
#include "easypr/config.h"
namespace easypr {
const char *kDefaultSvmPath = "resources/model/svm.xml";
class SvmTrain {
public:
typedef enum {
kForward = 1, // correspond to "has plate"
kInverse = 0 // correspond to "no plate"
} Label;
class SvmTrain {
public:
typedef enum {
kForward = 1, // correspond to "has plate"
kInverse = 0 // correspond to "no plate"
} Label;
SvmTrain(const char* forward_data_folder, const char* inverse_data_folder);
SvmTrain(const char* forward_data_folder, const char* inverse_data_folder);
void train(bool divide = true, float divide_percentage = 0.7,
const char* out_svm_folder = kDefaultSvmPath);
void train(bool divide = true, float divide_percentage = 0.7,
const char* out_svm_folder = kDefaultSvmPath);
void runTest(const char* svm_path = kDefaultSvmPath);
void runTest(const char* svm_path = kDefaultSvmPath);
private:
/*
* divide images into train part and test part by percentage
*/
void divide(const char* images_folder, float percentage = 0.7);
private:
/*
* divide images into train part and test part by percentage
*/
void divide(const char* images_folder, float percentage = 0.7);
void getTrain();
void getTrain();
void getTest();
void getTest();
const char* forward_;
const char* inverse_;
const char* forward_;
const char* inverse_;
// these two variables are used for cv::CvSVM::train_auto()
cv::Mat classes_;
cv::Ptr<cv::ml::TrainData> trainingData_;
// these two variables are used for cv::CvSVM::train_auto()
cv::Mat classes_;
cv::Ptr<cv::ml::TrainData> trainingData_;
// these two variables are used for cv::CvSVM::predict()
std::vector<cv::Mat> test_imgaes_;
std::vector<Label> test_labels_;
};
// these two variables are used for cv::CvSVM::predict()
std::vector<cv::Mat> test_imgaes_;
std::vector<Label> test_labels_;
};
}

@ -1,4 +0,0 @@
要训练时注意看src/train下的两个cpp文件
数据在data文件夹下svm对应Plate_detectann对应chars_recognise。要先解压然后放置到正确的路径下或者
你可以修改cpp文件中的文件夹路径。

@ -1,6 +1,7 @@
#include "easypr/core/chars_identify.h"
#include "easypr/core/core_func.h"
#include "easypr/train/ann_train.h"
#include "easypr/config.h"
namespace easypr {
@ -48,7 +49,7 @@ namespace easypr {
}
CharsIdentify::CharsIdentify() {
ann_ = ml::ANN_MLP::load<ml::ANN_MLP>("resources/model/ann.xml");
ann_ = ml::ANN_MLP::load<ml::ANN_MLP>(kDefaultAnnPath);
}
string CharsIdentify::identify(Mat input, bool isChinese, bool isSpeci) {
@ -71,7 +72,9 @@ namespace easypr {
int CharsIdentify::classify(Mat f, bool isChinses, bool isSpeci) {
int result = -1;
Mat output(1, sizeof(kCharacters) + sizeof(kChinese), CV_32FC1);
const int chars_number = sizeof(kCharacters);
const int zhchars_number = sizeof(kChinese);
Mat output(1, chars_number + zhchars_number, CV_32FC1);
ann_->predict(f, output); //使用ann对字符做判断
if (!isChinses) // 对数字和英文字母的判断
@ -80,7 +83,7 @@ namespace easypr {
// A-Z
result = 0;
float maxVal = -2;
for (int j = 10; j < sizeof(kCharacters); j++) {
for (int j = 10; j < chars_number; j++) {
float val = output.at<float>(j);
// cout << "j:" << j << "val:"<< val << endl;
if (val > maxVal) {
@ -93,7 +96,7 @@ namespace easypr {
// 0-9
result = 0;
float maxVal = -2;
for (int j = 0; j < sizeof(kCharacters); j++) {
for (int j = 0; j < chars_number; j++) {
float val = output.at<float>(j);
// cout << "j:" << j << "val:"<< val << endl;
if (val >
@ -107,9 +110,9 @@ namespace easypr {
}
else // 对中文字符的判断
{
result = sizeof(kCharacters);
result = chars_number;
float maxVal = -2;
for (int j = sizeof(kCharacters); j < sizeof(kCharacters) + sizeof(sizeof(kChinese)); j++) {
for (int j = chars_number; j < chars_number + zhchars_number; j++) {
float val = output.at<float>(j);
// cout << "j:" << j << "val:"<< val << endl;
if (val > maxVal) {

@ -1,8 +1,6 @@
#include "easypr/core/plate_judge.h"
#include "easypr/config.h"
/*! \namespace easypr
Namespace where all the C++ EasyPR functionality resides
*/
namespace easypr {
PlateJudge* PlateJudge::instance_ = nullptr;
@ -15,7 +13,7 @@ namespace easypr {
}
PlateJudge::PlateJudge() {
svm_ = ml::SVM::load<ml::SVM>("resources/model/svm.xml");
svm_ = ml::SVM::load<ml::SVM>(kDefaultSvmPath);
}
//! 直方图均衡
@ -94,4 +92,4 @@ namespace easypr {
return 0;
}
} /*! \namespace easypr*/
}

@ -1,4 +1,5 @@
#include "easypr/train/ann_train.h"
#include "easypr/config.h"
namespace easypr{

@ -56,11 +56,13 @@
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(SolutionDir)include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>C:\Users\Micooz\Documents\opencv3\build\include;$(SolutionDir)include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>C:\Users\Micooz\Documents\opencv3\build\x86\vc12\lib</AdditionalLibraryDirectories>
<AdditionalDependencies>opencv_world300d.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@ -72,13 +74,15 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(SolutionDir)include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>C:\Users\Micooz\Documents\opencv3\build\include;$(SolutionDir)include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalLibraryDirectories>C:\Users\Micooz\Documents\opencv3\build\x86\vc12\lib</AdditionalLibraryDirectories>
<AdditionalDependencies>opencv_world300.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>

@ -102,6 +102,7 @@
<ItemGroup>
<ClInclude Include="..\include\easypr.h" />
<ClInclude Include="..\include\easypr\api.hpp" />
<ClInclude Include="..\include\easypr\config.h" />
<ClInclude Include="..\include\easypr\core\chars_identify.h" />
<ClInclude Include="..\include\easypr\core\chars_recognise.h" />
<ClInclude Include="..\include\easypr\core\chars_segment.h" />

@ -152,5 +152,8 @@
<ClInclude Include="..\include\easypr\core\plate_recognize.h">
<Filter>头文件\easypr\core</Filter>
</ClInclude>
<ClInclude Include="..\include\easypr\config.h">
<Filter>头文件\easypr</Filter>
</ClInclude>
</ItemGroup>
</Project>
Loading…
Cancel
Save