From 851bf5f9dc50a4d40ae5b2ffdb347c7c06349dff Mon Sep 17 00:00:00 2001 From: liuruoze Date: Mon, 8 Jun 2015 21:43:37 +0800 Subject: [PATCH] =?UTF-8?q?1.3=20ver=20=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- run_accuracy.txt | 4 ++ src/core/plate_detect.cpp | 33 ++++++------- src/core/plate_recognize.cpp | 89 +++++++++++++++-------------------- src/include/chars_recognise.h | 1 - src/include/core_func.h | 2 + src/include/plate.h | 7 +++ src/include/plate_locate.h | 2 - src/test/accuracy_test.cpp | 19 ++++---- 8 files changed, 72 insertions(+), 85 deletions(-) diff --git a/run_accuracy.txt b/run_accuracy.txt index 5e47017..e3c383c 100644 --- a/run_accuracy.txt +++ b/run_accuracy.txt @@ -1049,3 +1049,7 @@ 总图片数:120张, 未识出图片:2张, 定位率:98.3333% 平均字符差距:0.398305个, 完全匹配数:96张, 完全匹配率:81.3559% 总时间:178秒, 平均执行时间:1.48333秒 +2015-06-06 15:04:53 +总图片数:120张, 未识出图片:2张, 定位率:98.3333% +平均字符差距:0.398305个, 完全匹配数:96张, 完全匹配率:81.3559% +总时间:417秒, 平均执行时间:3.475秒 diff --git a/src/core/plate_detect.cpp b/src/core/plate_detect.cpp index fffd5fc..396226b 100644 --- a/src/core/plate_detect.cpp +++ b/src/core/plate_detect.cpp @@ -70,36 +70,30 @@ int CPlateDetect::plateDetectDeep(Mat src, vector& resultVec, bool showD const int color_find_max = m_maxPlates; m_plateLocate->plateColorLocate(src, color_Plates, index); - - //m_plateJudge->plateJudge(color_Plates, color_result_Plates); - //下面代码是sunjunlishi添加 - for (int i=0;iplateJudge(color_Plates, color_result_Plates); + + //for (int i=0;iplateSobelLocate(src, sobel_Plates, index); - //m_plateJudge->plateJudge(sobel_Plates, sobel_result_Plates); + m_plateJudge->plateJudge(sobel_Plates, sobel_result_Plates); - //下面代码是sunjunlishi添加 - for (int i=0;i& resultVec, bool showD } plate.bColored = false; + plate.setPlateLocateType(SOBEL); all_result_Plates.push_back(plate); } @@ -131,8 +126,8 @@ int CPlateDetect::showResult(const Mat& result) { namedWindow("EasyPR", CV_WINDOW_AUTOSIZE); - const int RESULTWIDTH = 930; //640 930 - const int RESULTHEIGHT = 710; //540 710 + const int RESULTWIDTH = 640; //640 930 + const int RESULTHEIGHT = 540; //540 710 Mat img_window; img_window.create(RESULTHEIGHT, RESULTWIDTH, CV_8UC3); diff --git a/src/core/plate_recognize.cpp b/src/core/plate_recognize.cpp index d4ceb2a..17fbf16 100644 --- a/src/core/plate_recognize.cpp +++ b/src/core/plate_recognize.cpp @@ -12,51 +12,21 @@ CPlateRecognize::CPlateRecognize() //m_charsRecognise = new CCharsRecognise(); } -////! 装载SVM模型 -//void CPlateRecognize::LoadSVM(string strSVM) -//{ -// m_plateDetect->LoadModel(strSVM.c_str()); -//} -// -////! 装载ANN模型 -//void CPlateRecognize::LoadANN(string strANN) -//{ -// m_charsRecognise->LoadModel(strANN.c_str()); -//} -// -//int CPlateRecognize::plateDetect(Mat src, vector& resultVec) -//{ -// int result = m_plateDetect->plateDetect(src, resultVec); -// return result; -//} -// -//int CPlateRecognize::charsRecognise(Mat plate, string& plateLicense) -//{ -// int result = m_charsRecognise->charsRecognise(plate, plateLicense); -// return result; -//} - - // !车牌识别模块 int CPlateRecognize::plateRecognize(Mat src, vector& licenseVec, int index) { // 车牌方块集合 vector plateVec; - // 如果设置了Debug模式,就依次显示所有的图片 - bool showDetectArea = getPDDebug(); - // 进行深度定位,使用颜色信息与二次Sobel - int resultPD = plateDetectDeep(src, plateVec, showDetectArea, 0); - - Mat result; - src.copyTo(result); + int resultPD = plateDetectDeep(src, plateVec, getPDDebug(), 0); if (resultPD == 0) { int num = plateVec.size(); int index = 0; + //依次识别每个车牌内的符号 for (int j = 0; j < num; j++) { CPlate item = plateVec[j]; @@ -72,36 +42,51 @@ int CPlateRecognize::plateRecognize(Mat src, vector& licenseVec, int ind { string license = plateType + ":" + plateIdentify; licenseVec.push_back(license); + } + } + //完整识别过程到此结束 + + + //如果是Debug模式,则还需要将定位的图片显示在原图左上角 + if (getPDDebug() == true) + { + Mat result; + src.copyTo(result); + + for (int j = 0; j < num; j++) + { + CPlate item = plateVec[j]; + Mat plate = item.getPlateMat(); - /*int height = 36; + int height = 36; int width = 136; - if(height*index + height < result.rows) + if( height*index + height < result.rows ) { Mat imageRoi = result(Rect(0, 0 + height*index, width, height)); - addWeighted(imageRoi, 0, plate, 1, 0, imageRoi); + addWeighted(imageRoi, 0, plate, 1, 0, imageRoi); } - index++;*/ + index++; RotatedRect minRect = item.getPlatePos(); - Point2f rect_points[4]; - minRect.points( rect_points ); + Point2f rect_points[4]; + minRect.points(rect_points); - if(item.bColored) - { - for (int j = 0; j < 4; j++) - line(result, rect_points[j], rect_points[(j + 1) % 4], Scalar(255, 255, 0), 2, 8); - } - else - { - for( int j = 0; j < 4; j++ ) - line(result, rect_points[j], rect_points[(j+1)%4], Scalar(0,0,255), 2, 8 );//sobel定位车牌,红色方框 - } + Scalar lineColor = Scalar(255, 255, 255); + + if (item.getPlateLocateType() == SOBEL) + lineColor = Scalar(255, 0, 0); + + if (item.getPlateLocateType() == COLOR) + lineColor = Scalar(0, 255, 0); + + for (int j = 0; j < 4; j++) + line(result, rect_points[j], rect_points[(j + 1) % 4], lineColor, 2, 8); } - } - } - if (showDetectArea) - showResult(result); + //显示定位框的图片 + showResult(result); + } + } return resultPD; } diff --git a/src/include/chars_recognise.h b/src/include/chars_recognise.h index cbdb61e..f61f437 100644 --- a/src/include/chars_recognise.h +++ b/src/include/chars_recognise.h @@ -41,7 +41,6 @@ namespace easypr { //! 获取调试模式状态 inline int getCRDebug(){ return m_charsSegment->getDebug(); } - //! 获得车牌颜色 inline string getPlateColor(Mat input) const { diff --git a/src/include/core_func.h b/src/include/core_func.h index b613402..20563d4 100644 --- a/src/include/core_func.h +++ b/src/include/core_func.h @@ -8,6 +8,8 @@ namespace easypr { enum Color{ BLUE, YELLOW, WHITE, UNKNOWN}; + enum LocateType { SOBEL, COLOR, OTHER }; + //! 根据一幅图像与颜色模板获取对应的二值图 //! 输入RGB图像, 颜色模板(蓝色、黄色) //! 输出灰度图(只有0和255两个值,255代表匹配,0代表不匹配) diff --git a/src/include/plate.h b/src/include/plate.h index 18bb53f..9be4dae 100644 --- a/src/include/plate.h +++ b/src/include/plate.h @@ -11,6 +11,7 @@ #define __PLATE_H__ #include "prep.h" +#include "core_func.h" /*! \namespace easypr Namespace where all the C++ EasyPR functionality resides @@ -35,6 +36,9 @@ namespace easypr { inline void setPlateStr(String param){ m_plateStr = param; } inline String getPlateStr() const{ return m_plateStr; } + inline void setPlateLocateType(LocateType param){ m_locateType = param; } + inline LocateType getPlateLocateType() const{ return m_locateType; } + private: //! 车牌的图块 Mat m_plateMat; @@ -44,6 +48,9 @@ namespace easypr { //! 车牌字符串 String m_plateStr; + + //! 车牌定位的方法 + LocateType m_locateType; }; } /*! \namespace easypr*/ diff --git a/src/include/plate_locate.h b/src/include/plate_locate.h index 4568997..4e96f3a 100644 --- a/src/include/plate_locate.h +++ b/src/include/plate_locate.h @@ -29,8 +29,6 @@ class CPlateLocate public: CPlateLocate(); - enum LocateType { SOBEL, COLOR }; - //! Sobel第一次搜索 //! 不限制大小和形状,获取的BoundRect进入下一步 int sobelFrtSearch(const Mat& src, vector>& outRects); diff --git a/src/test/accuracy_test.cpp b/src/test/accuracy_test.cpp index 042501f..2c1a1f2 100644 --- a/src/test/accuracy_test.cpp +++ b/src/test/accuracy_test.cpp @@ -7,30 +7,27 @@ using namespace easypr; -int acurayTest(const string& test_path) { - ////获取该路径下的所有文件 +int acurayTest(const string& test_path) +{ auto files = Utils::getFiles(test_path); - // CPlateLocate lo; - // CPlateJudge ju; CPlateRecognize pr; pr.LoadANN("model/ann.xml"); pr.LoadSVM("model/svm.xml"); - pr.setLifemode(true); + + // 设置Debug模式 pr.setDebug(false); + pr.setLifemode(true); + // 设置要处理的一张图片中最多有多少车牌 pr.setMaxPlates(4); - // CPlateDetect pd; - // pd.LoadSVM("model/svm.xml"); - // pd.setPDLifemode(true); - int size = files.size(); - // int size = 200; - if (0 == size) { + if (0 == size) + { cout << "No File Found in general_test/native_test!" << endl; return 0; }