Skip to content

Commit

Permalink
svm problem fix, 3.1 support
Browse files Browse the repository at this point in the history
  • Loading branch information
liuruoze committed Jan 12, 2016
1 parent a197f44 commit 0331a9c
Show file tree
Hide file tree
Showing 17 changed files with 250 additions and 31 deletions.
12 changes: 11 additions & 1 deletion EasyPR.sln
Original file line number Diff line number Diff line change
@@ -1,7 1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.31101.0
VisualStudioVersion = 12.0.21005.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "demo", "vcprojs\demo.vcxproj", "{FADCD7E1-8071-4F1C-8071-C469569C3B56}"
EndProject
Expand All @@ -10,17 10,27 @@ EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Debug|x64 = Debug|x64
Release|Win32 = Release|Win32
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{FADCD7E1-8071-4F1C-8071-C469569C3B56}.Debug|Win32.ActiveCfg = Debug|Win32
{FADCD7E1-8071-4F1C-8071-C469569C3B56}.Debug|Win32.Build.0 = Debug|Win32
{FADCD7E1-8071-4F1C-8071-C469569C3B56}.Debug|x64.ActiveCfg = Debug|x64
{FADCD7E1-8071-4F1C-8071-C469569C3B56}.Debug|x64.Build.0 = Debug|x64
{FADCD7E1-8071-4F1C-8071-C469569C3B56}.Release|Win32.ActiveCfg = Release|Win32
{FADCD7E1-8071-4F1C-8071-C469569C3B56}.Release|Win32.Build.0 = Release|Win32
{FADCD7E1-8071-4F1C-8071-C469569C3B56}.Release|x64.ActiveCfg = Release|x64
{FADCD7E1-8071-4F1C-8071-C469569C3B56}.Release|x64.Build.0 = Release|x64
{2791E339-04FB-44EF-9F92-C90131FE7772}.Debug|Win32.ActiveCfg = Debug|Win32
{2791E339-04FB-44EF-9F92-C90131FE7772}.Debug|Win32.Build.0 = Debug|Win32
{2791E339-04FB-44EF-9F92-C90131FE7772}.Debug|x64.ActiveCfg = Debug|x64
{2791E339-04FB-44EF-9F92-C90131FE7772}.Debug|x64.Build.0 = Debug|x64
{2791E339-04FB-44EF-9F92-C90131FE7772}.Release|Win32.ActiveCfg = Release|Win32
{2791E339-04FB-44EF-9F92-C90131FE7772}.Release|Win32.Build.0 = Release|Win32
{2791E339-04FB-44EF-9F92-C90131FE7772}.Release|x64.ActiveCfg = Release|x64
{2791E339-04FB-44EF-9F92-C90131FE7772}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 12,15 @@ EasyPR是一个中文的开源车牌识别系统,其目标是成为一个简

本次更新是1.4版,主要改进在于几个方面:

1.支持opencv3.0,注意,这与2.x不兼容,要想支持的话请下载1.3版本。
1.支持opencv3.0与3.1,注意,这与opencv2.x不兼容,要想支持的话请下载1.3版本。

2.ANN训练开放。

3.代码优化。
3.修正了SVM训练异常的问题。

4.代码优化。

不知道怎么下载以前的版本的小伙伴可以在github或gitosc的"branch"里选择"tags",然后点击"v1.3",再然后点击"download zip"。当然如果直接git clone的话可以随时方便切换。

在后面的版本中计划做以下几点改善:

Expand Down
32 changes: 32 additions & 0 deletions accuracy.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1313,3 1313,35 @@
��ͼƬ��:204��, δʶ��ͼƬ:3��, ��λ��:98.5294%
ƽ���ַ����:0.681592��, ��ȫƥ����:141��, ��ȫƥ����:70.1493%
��ʱ��:178��, ƽ��ִ��ʱ��:0.872549��
2016-01-12 09:46:45
��ͼƬ��:204��, δʶ��ͼƬ:5��, ��λ��:97.549%
ƽ���ַ����:0.688442��, ��ȫƥ����:141��, ��ȫƥ����:70.8543%
��ʱ��:180��, ƽ��ִ��ʱ��:0.882353��
2016-01-12 09:53:28
��ͼƬ��:204��, δʶ��ͼƬ:57��, ��λ��:72.0588%
ƽ���ַ����:1.4898��, ��ȫƥ����:87��, ��ȫƥ����:59.1837%
��ʱ��:187��, ƽ��ִ��ʱ��:0.916667��
2016-01-12 10:00:05
��ͼƬ��:204��, δʶ��ͼƬ:5��, ��λ��:97.549%
ƽ���ַ����:0.688442��, ��ȫƥ����:141��, ��ȫƥ����:70.8543%
��ʱ��:181��, ƽ��ִ��ʱ��:0.887255��
2016-01-12 10:11:33
��ͼƬ��:204��, δʶ��ͼƬ:5��, ��λ��:97.549%
ƽ���ַ����:0.688442��, ��ȫƥ����:141��, ��ȫƥ����:70.8543%
��ʱ��:179��, ƽ��ִ��ʱ��:0.877451��
2016-01-12 10:25:30
��ͼƬ��:204��, δʶ��ͼƬ:5��, ��λ��:97.549%
ƽ���ַ����:0.688442��, ��ȫƥ����:141��, ��ȫƥ����:70.8543%
��ʱ��:170��, ƽ��ִ��ʱ��:0.833333��
2016-01-12 10:37:31
��ͼƬ��:204��, δʶ��ͼƬ:10��, ��λ��:95.098%
ƽ���ַ����:0.618557��, ��ȫƥ����:139��, ��ȫƥ����:71.6495%
��ʱ��:172��, ƽ��ִ��ʱ��:0.843137��
2016-01-12 11:27:17
��ͼƬ��:204��, δʶ��ͼƬ:5��, ��λ��:97.549%
ƽ���ַ����:0.688442��, ��ȫƥ����:141��, ��ȫƥ����:70.8543%
��ʱ��:174��, ƽ��ִ��ʱ��:0.852941��
2016-01-12 11:30:49
��ͼƬ��:204��, δʶ��ͼƬ:5��, ��λ��:97.549%
ƽ���ַ����:0.688442��, ��ȫƥ����:141��, ��ȫƥ����:70.8543%
��ʱ��:207��, ƽ��ִ��ʱ��:1.01471��
2 changes: 1 addition & 1 deletion include/easypr/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 45,7 @@ static const char *kChars[] = {
/* 31 */
};

static const std::map<const char*, const char*> kCharsMap = {
static const std::map<std::string, std::string> kCharsMap = {
{"zh_cuan" , ""}, {"zh_e" , ""}, {"zh_gan" , ""},
{"zh_gan1" , ""}, {"zh_gui" , ""}, {"zh_gui1" , ""},
{"zh_hei" , ""}, {"zh_hu" , ""}, {"zh_ji" , ""},
Expand Down
2 changes: 1 addition & 1 deletion include/easypr/core/chars_recognise.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 23,7 @@ class CCharsRecognise {

~CCharsRecognise();

std::string charsRecognise(cv::Mat plate);
int charsRecognise(cv::Mat plate, std::string& plateLicense);

//! 获得车牌颜色
inline std::string getPlateColor(cv::Mat input) const {
Expand Down
2 changes: 2 additions & 0 deletions include/easypr/train/svm_train.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 7,8 @@

namespace easypr {

//int svmTrain(bool dividePrepared, bool trainPrepared);

class SvmTrain : public ITrain {
public:
typedef struct {
Expand Down
6 changes: 5 additions & 1 deletion src/core/chars_identify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 24,11 @@ std::pair<std::string, std::string> CharsIdentify::identify(cv::Mat input) {
return std::make_pair(kChars[index], kChars[index]);
} else {
const char* key = kChars[index];
return std::make_pair(key, kCharsMap.at(key));
std::string s = key;
//std::cout << s << std::endl;
std::string province = kCharsMap.at(s);
//std::cout << province << std::endl;
return std::make_pair(s, province);
}
}
}
13 changes: 9 additions & 4 deletions src/core/chars_recognise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 7,22 @@ CCharsRecognise::CCharsRecognise() { m_charsSegment = new CCharsSegment(); }

CCharsRecognise::~CCharsRecognise() { SAFE_RELEASE(m_charsSegment); }

std::string CCharsRecognise::charsRecognise(Mat plate) {
int CCharsRecognise::charsRecognise(Mat plate, std::string& plateLicense) {
std::vector<Mat> matChars;
std::string license;

int result = m_charsSegment->charsSegment(plate, matChars);
if (result == 0) {
for (auto block : matChars) {
auto character = CharsIdentify::instance()->identify(block);
license.append(character.second);
plateLicense.append(character.second);
}
}
return license;

if (plateLicense.size() < 7) {
return -1;
}

return result;

}
}
2 changes: 1 addition & 1 deletion src/core/feature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 44,7 @@ void getHistogramFeatures(const Mat& image, Mat& features) {
Mat grayImage;
cvtColor(image, grayImage, CV_RGB2GRAY);

// grayImage = histeq(grayImage);
//grayImage = histeq(grayImage);

Mat img_threshold;
threshold(grayImage, img_threshold, 0, 255,
Expand Down
10 changes: 7 additions & 3 deletions src/core/plate_recognize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 27,13 @@ int CPlateRecognize::plateRecognize(Mat src,
std::string plateType = getPlateColor(plate);

//获取车牌号
std::string license = charsRecognise(plate);
std::string full_license = plateType ":" license;
licenseVec.push_back(full_license);
std::string plateIdentify = "";
int resultCR = charsRecognise(plate, plateIdentify);
if (resultCR == 0)
{
std::string license = plateType ":" plateIdentify;
licenseVec.push_back(license);
}
}
//完整识别过程到此结束

Expand Down
22 changes: 13 additions & 9 deletions src/train/svm_train.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 21,8 @@ void SvmTrain::train() {
svm_->setType(cv::ml::SVM::C_SVC);
svm_->setKernel(cv::ml::SVM::RBF);
svm_->setDegree(0.1);
svm_->setGamma(1);
// 1.4 bug fix: old 1.4 ver gamma is 1
svm_->setGamma(0.1);
svm_->setCoef0(0.1);
svm_->setC(1);
svm_->setNu(0.1);
Expand All @@ -32,11 33,11 @@ void SvmTrain::train() {

fprintf(stdout, ">> Training SVM model, please wait...\n");
long start = utils::getTimestamp();
svm_->trainAuto(train_data, 10, SVM::getDefaultGrid(SVM::C),
SVM::getDefaultGrid(SVM::GAMMA), SVM::getDefaultGrid(SVM::P),
SVM::getDefaultGrid(SVM::NU), SVM::getDefaultGrid(SVM::COEF),
SVM::getDefaultGrid(SVM::DEGREE), true);
//svm_->train(train_data);
//svm_->trainAuto(train_data, 10, SVM::getDefaultGrid(SVM::C),
// SVM::getDefaultGrid(SVM::GAMMA), SVM::getDefaultGrid(SVM::P),
// SVM::getDefaultGrid(SVM::NU), SVM::getDefaultGrid(SVM::COEF),
// SVM::getDefaultGrid(SVM::DEGREE), true);
svm_->train(train_data);

long end = utils::getTimestamp();
fprintf(stdout, ">> Training done. Time elapse: %ldms\n", end - start);
Expand All @@ -49,7 50,9 @@ void SvmTrain::train() {
}

void SvmTrain::test() {
svm_ = cv::ml::SVM::load<cv::ml::SVM>(svm_xml_);
// 1.4 bug fix: old 1.4 ver there is no null judge
if (NULL == svm_)
svm_ = cv::ml::SVM::load<cv::ml::SVM>(svm_xml_);

if (test_file_list_.empty()) {
this->prepare();
Expand All @@ -70,9 73,10 @@ void SvmTrain::test() {
}
cv::Mat feature;
getHistogramFeatures(image, feature);
feature.reshape(1, 1).convertTo(feature, CV_32FC1);

auto predict = static_cast<int>(svm_->predict(feature));
//std::cout << "predict: " << result << std::endl;

auto predict = int(svm_->predict(feature));
auto real = item.label;
if (predict == kForward && real == kForward) ptrue_rtrue ;
if (predict == kForward && real == kInverse) ptrue_rfalse ;
Expand Down
5 changes: 4 additions & 1 deletion test/chars.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 65,10 @@ int test_chars_recognise() {
cv::Mat src = cv::imread("resources/image/chars_recognise.jpg");
CCharsRecognise cr;

std::cout << "charsRecognise: " << cr.charsRecognise(src) << std::endl;
std::string plateLicense = "";
int result = cr.charsRecognise(src, plateLicense);
if (result == 0)
std::cout << "charsRecognise: " << plateLicense << std::endl;
return 0;
}
}
Expand Down
17 changes: 10 additions & 7 deletions test/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 387,7 @@ int main(int argc, const char* argv[]) {
{
easypr::SvmTrain svm("tmp/svm", "tmp/svm.xml");
svm.train();
//easypr::svmTrain(true, false);
}
break;
case 4:
Expand All @@ -401,16 402,18 @@ int main(int argc, const char* argv[]) {
break;
case 6: {
// 开发团队;
// 暂时不接受应聘信息,谢谢!
std::cout << std::endl;
const char* recruitment[] = {
const char* recruitment[] = {
"我们EasyPR团队目前有一个5人左右的小组在进行EasyPR后续版本的开发"
"工作。",
"如果你对本项目感兴趣,并且愿意为开源贡献一份力量,我们很欢迎你的"
"加入。",
"目前招聘的主要人才是:车牌定位,图像识别,深度学习,网站建设相关"
"方面的牛人。",
"如果你觉得自己符合条件,请发邮件到地址([email protected])"
",期待你的加入!",
"人数已满,暂时不接受应聘信息,谢谢!",
//"如果你对本项目感兴趣,并且愿意为开源贡献一份力量,我们很欢迎你的"
//"加入。",
//"目前招聘的主要人才是:车牌定位,图像识别,深度学习,网站建设相关"
//"方面的牛人。",
//"如果你觉得自己符合条件,请发邮件到地址([email protected])"
//",期待你的加入!",
NULL};
easypr::Utils::print_str_lines(recruitment);
std::cout << std::endl;
Expand Down
Loading

0 comments on commit 0331a9c

Please sign in to comment.