From 856c3fe71bffdef485da44bb83f04575e2c531fe Mon Sep 17 00:00:00 2001 From: Micooz Date: Thu, 11 Jun 2015 19:40:36 +0800 Subject: [PATCH] Fixed all warnings by Visual Studio 2013. --- src/core/chars_segment.cpp | 8 ++++---- src/core/core_func.cpp | 2 +- src/core/plate.cpp | 12 +++++------- src/core/plate_detect.cpp | 4 ++-- src/core/plate_locate.cpp | 28 ++++++++++++++-------------- test/accuracy.hpp | 28 ++++++++++++++++++++++------ 6 files changed, 48 insertions(+), 34 deletions(-) diff --git a/src/core/chars_segment.cpp b/src/core/chars_segment.cpp index 5ad7edd..b2563c2 100644 --- a/src/core/chars_segment.cpp +++ b/src/core/chars_segment.cpp @@ -101,7 +101,7 @@ int CCharsSegment::charsSegment(Mat input, vector& resultVec) { int w = input_grey.cols; int h = input_grey.rows; - Mat tmp = input_grey(Rect_(w * 0.1, h * 0.1, w * 0.8, h * 0.8)); + Mat tmp = input_grey(Rect_(w * 0.1, h * 0.1, w * 0.8, h * 0.8)); int threadHoldV = ThresholdOtsu(tmp); // utils::imwrite("E:/img_inputgray2.jpg", input_grey); @@ -116,7 +116,7 @@ int CCharsSegment::charsSegment(Mat input, vector& resultVec) { img_threshold = input_grey.clone(); int w = input_grey.cols; int h = input_grey.rows; - Mat tmp = input_grey(Rect_(w * 0.1, h * 0.1, w * 0.8, h * 0.8)); + Mat tmp = input_grey(Rect_(w * 0.1, h * 0.1, w * 0.8, h * 0.8)); int threadHoldV = ThresholdOtsu(tmp); utils::imwrite("resources/image/tmp/inputgray2.jpg", input_grey); @@ -270,13 +270,13 @@ int CCharsSegment::SortRect(const vector& vecRect, vector& out) { orderIndex.push_back(i); xpositions.push_back(vecRect[i].x); } - + int min = xpositions[0]; int minIdx = 0; for (size_t i = 0; i < xpositions.size(); i++) { min = xpositions[i]; minIdx = i; - for (size_t j = i; j < xpositions.size(); j++) { + for (size_t j = i; j < xpositions.size(); j++) { if (xpositions[j] < min) { min = xpositions[j]; minIdx = j; diff --git a/src/core/core_func.cpp b/src/core/core_func.cpp index e9b09eb..c625a7b 100644 --- a/src/core/core_func.cpp +++ b/src/core/core_func.cpp @@ -290,7 +290,7 @@ bool plateColorJudge(const Mat& src, const Color r, const bool adaptive_minsv, float& percent) { // 判断阈值 const float thresh = 0.45f; - + Mat src_gray; colorMatch(src, src_gray, r, adaptive_minsv); diff --git a/src/core/plate.cpp b/src/core/plate.cpp index 9ce711e..8492233 100644 --- a/src/core/plate.cpp +++ b/src/core/plate.cpp @@ -3,12 +3,10 @@ /*! \namespace easypr Namespace where all the C++ EasyPR functionality resides */ -namespace easypr{ +namespace easypr { - CPlate::CPlate() - { - //cout << "CPlate" << endl; - bColored = true; - } +CPlate::CPlate() { + bColored = true; +} -} /*! \namespace easypr*/ \ No newline at end of file +} /*! \namespace easypr*/ \ No newline at end of file diff --git a/src/core/plate_detect.cpp b/src/core/plate_detect.cpp index 4e7d82b..faa137a 100644 --- a/src/core/plate_detect.cpp +++ b/src/core/plate_detect.cpp @@ -83,7 +83,7 @@ int CPlateDetect::plateDetectDeep(Mat src, vector& resultVec, sobel_result_Plates.push_back(sobel_Plates[i]); }*/ - for (size_t i = 0; i < sobel_result_Plates.size(); i++) { + for (size_t i = 0; i < sobel_result_Plates.size(); i++) { CPlate plate = sobel_result_Plates[i]; if (0) { @@ -110,7 +110,7 @@ int CPlateDetect::plateDetectDeep(Mat src, vector& resultVec, int CPlateDetect::showResult(const Mat& result) { namedWindow("EasyPR", CV_WINDOW_AUTOSIZE); - const int RESULTWIDTH = 640; // 640 930 + const int RESULTWIDTH = 640; // 640 930 const int RESULTHEIGHT = 540; // 540 710 Mat img_window; diff --git a/src/core/plate_locate.cpp b/src/core/plate_locate.cpp index cf7981a..1faec5d 100644 --- a/src/core/plate_locate.cpp +++ b/src/core/plate_locate.cpp @@ -7,7 +7,7 @@ using namespace std; Namespace where all the C++ EasyPR functionality resides */ namespace easypr { - + const float DEFAULT_ERROR = 0.9f; // 0.6 const float DEFAULT_ASPECT = 3.75f; // 3.75 @@ -322,8 +322,8 @@ int CPlateLocate::sobelSecSearchPart(Mat& bound, Point2f refpoint, //找到两个边界后进行连接修补处理 if (posRight != 0 && posLeft != 0 && posLeft < posRight) { int posY = int(bound_threshold.rows * 0.5); - for (int i = posLeft + (int)(bound_threshold.rows * 0.1); i < posRight - 4; - i++) { + for (int i = posLeft + (int)(bound_threshold.rows * 0.1); + i < posRight - 4; i++) { bound_threshold.data[posY * bound_threshold.cols + i] = 255; } } @@ -504,7 +504,7 @@ void DeleteNotArea(Mat& inmat) { Mat img_threshold; if (BLUE == plateType) { img_threshold = input_grey.clone(); - Mat tmp = input_grey(Rect_(w * 0.15, h * 0.15, w * 0.7, h * 0.7)); + Mat tmp = input_grey(Rect_(w * 0.15, h * 0.15, w * 0.7, h * 0.7)); int threadHoldV = ThresholdOtsu(tmp); threshold(input_grey, img_threshold, threadHoldV, 255, CV_THRESH_BINARY); @@ -515,7 +515,7 @@ void DeleteNotArea(Mat& inmat) { } else if (YELLOW == plateType) { img_threshold = input_grey.clone(); - Mat tmp = input_grey(Rect_(w * 0.1, h * 0.1, w * 0.8, h * 0.8)); + Mat tmp = input_grey(Rect_(w * 0.1, h * 0.1, w * 0.8, h * 0.8)); int threadHoldV = ThresholdOtsu(tmp); threshold(input_grey, img_threshold, threadHoldV, 255, @@ -963,7 +963,7 @@ int CPlateLocate::deskewOld(Mat src, vector& inRects, plTri[1] = Point2f(middle_crop.cols - 1.f, 0); plTri[2] = Point2f(0 + (float)xdiff, middle_crop.rows - 1.f); } - + dstTri[0] = Point2f(0, 0); dstTri[1] = Point2f(WIDTH - 1, 0); dstTri[2] = Point2f(0, HEIGHT - 1); @@ -1141,11 +1141,11 @@ int CPlateLocate::plateSobelLocate(Mat src, vector& candPlates, Point2f refpoint(bound_rect.x, bound_rect.y); float x = bound_rect.x > 0 ? bound_rect.x : 0; - float y = bound_rect.y > 0 ? bound_rect.y : 0; + float y = bound_rect.y > 0 ? bound_rect.y : 0; - float width = + float width = x + bound_rect.width < src.cols ? bound_rect.width : src.cols - x; - float height = + float height = y + bound_rect.height < src.rows ? bound_rect.height : src.rows - y; Rect_ safe_bound_rect(x, y, width, height); @@ -1159,15 +1159,15 @@ int CPlateLocate::plateSobelLocate(Mat src, vector& candPlates, Rect_ bound_rect = bound_rects[i]; Point2f refpoint(bound_rect.x, bound_rect.y); - float x = bound_rect.x > 0 ? bound_rect.x : 0; - float y = bound_rect.y > 0 ? bound_rect.y : 0; + float x = bound_rect.x > 0 ? bound_rect.x : 0; + float y = bound_rect.y > 0 ? bound_rect.y : 0; - float width = + float width = x + bound_rect.width < src.cols ? bound_rect.width : src.cols - x; - float height = + float height = y + bound_rect.height < src.rows ? bound_rect.height : src.rows - y; - Rect_ safe_bound_rect(x, y, width, height); + Rect_ safe_bound_rect(x, y, width, height); Mat bound_mat = src(safe_bound_rect); // Sobel第二次精细搜索 diff --git a/test/accuracy.hpp b/test/accuracy.hpp index 0e4cf16..775ff4a 100644 --- a/test/accuracy.hpp +++ b/test/accuracy.hpp @@ -40,6 +40,8 @@ int accuracyTest(const char* test_path) { int count_err = 0; // 未识别的图片数量 int count_norecogin = 0; + // not recognized pictures + std::list not_recognized_files; // 总的字符差距 float diff_all = 0; @@ -76,7 +78,10 @@ int accuracyTest(const char* test_path) { if (num == 0) { cout << "无车牌" << endl; - if (plateLicense != "无车牌") count_norecogin++; + if (plateLicense != "无车牌") { + not_recognized_files.push_back(plateLicense); + count_norecogin++; + } } else if (num > 1) { // 多车牌使用diff最小的那个记录 int mindiff = 10000; @@ -142,11 +147,15 @@ int accuracyTest(const char* test_path) { float count_recogin = float(count_all - (count_err + count_norecogin)); float count_rate = count_recogin / count_all; - // float count_norate = 1 - count_rate; cout << "定位率:" << count_rate * 100 << "% " << endl; - diff_avg = diff_all / count_recogin; - match_rate = match_count / count_recogin * 100; + if (count_recogin > 0) { + diff_avg = diff_all / count_recogin; + } + + if (count_recogin > 0) { + match_rate = match_count / count_recogin * 100; + } cout << "平均字符差距:" << diff_avg << "个, "; cout << "完全匹配数:" << match_count << "张, "; @@ -156,7 +165,14 @@ int accuracyTest(const char* test_path) { double avgsec = seconds / double(count_all); cout << "总时间:" << seconds << "秒, "; - cout << "平均执行时间:" << avgsec << "秒 " << endl; + cout << "平均执行时间:" << avgsec << "秒" << endl; + + cout << "未识出图片:" << endl; + + for (auto it = not_recognized_files.begin(); it != not_recognized_files.end(); + ++it) { + cout << *it << endl; + } cout << endl; @@ -178,7 +194,7 @@ int accuracyTest(const char* test_path) { myfile << "完全匹配数:" << match_count << "张, "; myfile << "完全匹配率:" << match_rate << "% " << endl; myfile << "总时间:" << seconds << "秒, "; - myfile << "平均执行时间:" << avgsec << "秒 " << endl; + myfile << "平均执行时间:" << avgsec << "秒" << endl; myfile.close(); } else { cout << "Unable to open file";