From 1fbb6e9523217ba4088b6af04643625476a0af4f Mon Sep 17 00:00:00 2001 From: yuxue Date: Tue, 12 May 2020 16:58:33 +0800 Subject: [PATCH] no commit message --- res/image/test_image/debug_resize_2.jpg | Bin 0 -> 4104 bytes res/train/svm准确率提高历史.txt | 23 ----------- res/train/训练说明.txt | 2 +- .../com/yuxue/easypr/core/CharsIdentify.java | 5 +-- .../com/yuxue/easypr/core/CharsRecognise.java | 2 +- .../com/yuxue/easypr/core/CharsSegment.java | 14 +++---- src/test/java/com/yuxue/test/EasyPrTest.java | 36 +++++++++++++----- 7 files changed, 37 insertions(+), 45 deletions(-) create mode 100644 res/image/test_image/debug_resize_2.jpg delete mode 100644 res/train/svm准确率提高历史.txt diff --git a/res/image/test_image/debug_resize_2.jpg b/res/image/test_image/debug_resize_2.jpg new file mode 100644 index 0000000000000000000000000000000000000000..20ea30f86d5dd7034be54a14043fca9439bebd5d GIT binary patch literal 4104 zcmbW2c{H2p+s8xfOYIazQTtY7X-8E?6|JQiwAG|TMp4C}l-eR0s$y%6rBszrTh$V~ zR#i%ZQAIT>q>D%tMMzpp$o7kwbKdu#_mB5|ujky?d7krJ_kF&f`?}8g@@9EtfUKL# zc^80y001Dse*nCX04IQ;z(E{j!GjP29%Nx5A)t_mu!zV%OH^D;L{wZf{r2Z#K-RZtiR6qXPb5&fs+|CD&I0diu1V}MMcfDS-VP5>w;z{3Ny_&SCE zk;fPNZwLqig@i>!`7$K=1zoay`9L6Fv@l;WzdD8gA0Q+rEU#_pD5BsMAgU9s_)}_r zm6-0CwgDyYDf%(1YcXl!63QxvRn_$L4GfKpt!->ioc!6&>8!Jh>$&r8J{K=t_Pqju z1_lLR54jNr&(w+3X8K}&x?1I9g2gM~1OCLR{uBol7f7}3{lCcm3+%tSNB}9I0Ka)aIRFT-U&0leW9h-wm}4w$NJ1Hm-u!f$v^R70 z@1`dO;SE;1pBFD5rJi>14__+>?i}Sj*dA-Fp)VE_d+dU~c+PdTcjl7|d#%L!y-j{l zx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+2 zO9w%m(UhY{unSgw_g%AMKa@xKWn3AYJ!LgvQpz_3@Hd13!9f6ijyXpyhlY<~RaYmb z{KgA*4V&LKuRZ^6NwATj0W0D0oTqHp5c=TPC-1l#&`;tv9Y@IH&ssq@cO_~5=-8bK zQ93Z;1WwjDy!HyT#@4n?_8H)4tj72y^Q+yrDSZLO3i{Qlae*)eZ#OpPT;2X2Ivd-W z9*tvpG5hD2W=ZP>5%x*(*1oL?%L_g0%^2iJEWqm1| z<)Lvd#ar1=W+PH+WK0fMq)$8>SE0ycFl2DuyJ{Emp1KP6kPudn*g7t+;#5VcJjhvmyYG2Mb)kY%PA*ZP7o%&?l>zgy2;+^aMkoG3bwZV zwZUCR><#OwGw7A>+t_&$nu<)18|`zhNtjutmHd=g2)1rnf16ZTywtk}V;ULI0u`S& zQlC$Vh^)bR0I1=!SVJDbn3X?;-*fTFq_{=4Xv)K11*q&*$5=3pRA_;sV9n}ibcG;t zC+t-{a=;Z7R#G^DR6FAyH{PSQucYWJ+Fr|U+;BL-64h~QDpoG%o4M9^Ycjvrx!mbn zzh%OPx}R?=KLqV7`J=cJMyy{)Kt=YDu-h$;;T~v?M7BxAc_WCXzaMT+_%~-Idp-S% z-Fi`^pR}1ISHg+q0|{47dh2h}VdWZA6WLBC@2WS}aaytDTK?dJ@G_b=_Dz^M;PT=^^oTLnYVv#2GmNS*-1UtFw!I?FM9#)G!tPR(qq}CZB1+b>%<|a zpcr9AU(aJNE_m3w77zxETX8<#{i||d#LkPoXvP|Bx(~@{#6y>`hCjW+7ucP#Z9IOh g`ZV~LQ&Y}LyQT2J?USMJxFqsciOf6qb`WpwKWg>*XaE2J literal 0 HcmV?d00001 diff --git a/res/train/svm准确率提高历史.txt b/res/train/svm准确率提高历史.txt deleted file mode 100644 index 1c463ad5..00000000 --- a/res/train/svm准确率提高历史.txt +++ /dev/null @@ -1,23 +0,0 @@ -EasyPR 1.0: -svm liner -precise: 0.786207 -recall: 0.844444 -Fsocre: 0.814286 - -EasyPR 1.1: -svm liner -precise: 0.96798 -recall: 0.933492 -Fsocre: 0.950423 - -EasyPR 1.1: -svm liner: -precise: 0.968974 -recall: 0.964371 -Fsocre: 0.966667 - -EasyPR 1.1: -svm rbf(histom feature): -precise: 0.997596 -recall: 0.985748 -Fsocre: 0.991637 \ No newline at end of file diff --git a/res/train/训练说明.txt b/res/train/训练说明.txt index c6380e4e..f448bbe3 100644 --- a/res/train/训练说明.txt +++ b/res/train/训练说明.txt @@ -1,4 +1,4 @@ 要训练时,注意看src/train下的两个cpp文件 -数据在data文件夹下,svm对应Plate_detect,ann对应chars_recognise。要先解压,然后放置到正确的路径下,或者 +数据在data文件夹下,svm对应plate_detect_svm,ann对应chars_recognise。要先解压,然后放置到正确的路径下,或者 你可以修改cpp文件中的文件夹路径。 \ No newline at end of file diff --git a/src/main/java/com/yuxue/easypr/core/CharsIdentify.java b/src/main/java/com/yuxue/easypr/core/CharsIdentify.java index ab62eb95..c2c3c5c9 100644 --- a/src/main/java/com/yuxue/easypr/core/CharsIdentify.java +++ b/src/main/java/com/yuxue/easypr/core/CharsIdentify.java @@ -89,7 +89,7 @@ public class CharsIdentify { public void loadModel(String s) { this.ann.clear(); - ann=ANN_MLP.loadANN_MLP(s, "ann"); // 加载ann配置文件 + ann=ANN_MLP.loadANN_MLP(s, "ann"); // 加载ann配置文件 图像转文字的训练库文件 } @@ -118,7 +118,7 @@ public class CharsIdentify { int result = -1; Mat output = new Mat(1, numAll, CV_32FC1); - ann.predict(f, output, 0); + ann.predict(f, output, 0); // 预测结果 int ann_min = (!isChinses) ? ((isSpeci) ? 10 : 0) : numCharacter; int ann_max = (!isChinses) ? numCharacter : numAll; @@ -133,7 +133,6 @@ public class CharsIdentify { result = j; } } - return result; } diff --git a/src/main/java/com/yuxue/easypr/core/CharsRecognise.java b/src/main/java/com/yuxue/easypr/core/CharsRecognise.java index d8d0a8aa..ebed2e0c 100644 --- a/src/main/java/com/yuxue/easypr/core/CharsRecognise.java +++ b/src/main/java/com/yuxue/easypr/core/CharsRecognise.java @@ -40,7 +40,7 @@ public class CharsRecognise { if (0 == result) { for (int j = 0; j < matVec.size(); j++) { Mat charMat = matVec.get(j); - // 默认首个字符块是中文字符 + // 默认首个字符块是中文字符 第二个字符块是字母 String charcater = charsIdentify.charsIdentify(charMat, (0 == j), (1 == j)); plateIdentify = plateIdentify + charcater; } diff --git a/src/main/java/com/yuxue/easypr/core/CharsSegment.java b/src/main/java/com/yuxue/easypr/core/CharsSegment.java index 71bf2e41..ff4d809d 100644 --- a/src/main/java/com/yuxue/easypr/core/CharsSegment.java +++ b/src/main/java/com/yuxue/easypr/core/CharsSegment.java @@ -124,18 +124,19 @@ public class CharsSegment { CV_RETR_EXTERNAL, // retrieve the external contours CV_CHAIN_APPROX_NONE); // all pixels of each contours - // Start to iterate to each contour founded - // Remove patch that are no inside limits of aspect ratio and area. // 将不符合特定尺寸的图块排除出去 Vector vecRect = new Vector(); for (int i = 0; i < contours.size(); ++i) { Rect mr = boundingRect(contours.get(i)); - /*Mat temp = new Mat(img_threshold, mr); - String str = tempPath + "temp_"+i+".jpg"; - opencv_imgcodecs.imwrite(str, temp);*/ + Mat contour = new Mat(img_threshold, mr); + + if (this.isDebug) { + String str = tempPath + "debug_char_contour"+i+".jpg"; + opencv_imgcodecs.imwrite(str, contour); + } - if (verifySizes(new Mat(img_threshold, mr))) { + if (verifySizes(contour)) { // 将不符合特定尺寸的图块排除出去 vecRect.add(mr); } } @@ -149,7 +150,6 @@ public class CharsSegment { // 获得指示城市的特定Rect,如苏A的"A" int specIndex = GetSpecificRect(sortedRect, color); - System.err.println(specIndex); if (this.isDebug) { if (specIndex < sortedRect.size()) { diff --git a/src/test/java/com/yuxue/test/EasyPrTest.java b/src/test/java/com/yuxue/test/EasyPrTest.java index a9f0123b..e59972b9 100644 --- a/src/test/java/com/yuxue/test/EasyPrTest.java +++ b/src/test/java/com/yuxue/test/EasyPrTest.java @@ -1,22 +1,17 @@ package com.yuxue.test; -import static org.bytedeco.javacpp.opencv_imgproc.CV_CHAIN_APPROX_NONE; -import static org.bytedeco.javacpp.opencv_imgproc.CV_RETR_EXTERNAL; -import static org.bytedeco.javacpp.opencv_imgproc.boundingRect; -import static org.bytedeco.javacpp.opencv_imgproc.findContours; +import org.bytedeco.javacpp.opencv_imgproc; import java.io.File; import java.util.Vector; import org.bytedeco.javacpp.opencv_core.Mat; -import org.bytedeco.javacpp.opencv_core.MatVector; -import org.bytedeco.javacpp.opencv_core.Rect; +import org.bytedeco.javacpp.opencv_highgui; import org.bytedeco.javacpp.opencv_imgcodecs; import org.junit.Test; import com.yuxue.easypr.core.CharsIdentify; import com.yuxue.easypr.core.CharsRecognise; -import com.yuxue.easypr.core.CharsSegment; import com.yuxue.easypr.core.CoreFunc; import com.yuxue.easypr.core.PlateDetect; import com.yuxue.easypr.core.PlateLocate; @@ -185,8 +180,8 @@ public class EasyPrTest { @Test public void testGreenPlate() { - /*String imgPath = "res/image/test_image/result_0.png"; - Mat src = opencv_imgcodecs.imread(imgPath);*/ + String imgPath = "res/image/test_image/debug_resize_2.jpg"; + Mat src = opencv_imgcodecs.imread(imgPath); // 获取绿牌的H值范围 /*MatVector hsvSplit = new MatVector(); @@ -227,12 +222,33 @@ public class EasyPrTest { // 判断绿色车牌 /*Mat src_hsv = new Mat(); - cvtColor(src, src_hsv, CV_BGR2HSV); + opencv_imgproc.cvtColor(src, src_hsv, opencv_imgproc.CV_BGR2HSV); src_hsv = CoreFunc.colorMatch(src, PlateColor.GREEN, true); System.err.println(CoreFunc.plateColorJudge(src, PlateColor.GREEN, true)); String str = "d:/PlateDetect/src_hsv.png"; opencv_imgcodecs.imwrite(str, src_hsv);*/ + // 车牌检测对象 + PlateDetect plateDetect = new PlateDetect(); + plateDetect.setPDLifemode(true); + plateDetect.setDebug(false, ""); // 将过程的图块保存到盘符 + + Vector matVector = new Vector(); + + System.err.println(plateDetect.plateDetect(src, matVector)); + System.err.println(matVector.size()); + + for (int i = 0; i < matVector.size(); ++i) { // 遍历车牌图块Mat,进行识别 + Mat img = matVector.get(i); + // 识别的车牌,保存图片文件 + // 此方法生成的文件,中文名称都是乱码,试了各种编解码均无效,OpenCV自身的编解码问题。 + opencv_highgui.imshow("123", img); + + String str = "d:/PlateDetect/temp/result_.png"; + opencv_imgcodecs.imwrite(str, img); + + } + }