diff --git a/README.md b/README.md index 443f05d..65b7bf7 100644 --- a/README.md +++ b/README.md @@ -8,15 +8,18 @@ HyperLPR是一个使用深度学习针对对中文车牌识别的实现,与较 ### 更新 ++ 添加端到端的序列识别模型识别率大幅度提升 ++ 添加的端到端模型可以识别 新能源车牌,教练车牌,白色警用车牌 + 更新Windows版本的Visual Studio工程。(2017.11.15) -+ 增加cpp版本,目前仅支持标准蓝牌(需要依赖OpenCV 3.3)。 -+ 添加了简单的Android实现 (骁龙835 (*720*x*1280*) 200ms)。 ++ 增加cpp版本,目前仅支持标准蓝牌(需要依赖OpenCV 3.3) ++ 添加了简单的Android实现 (骁龙835 (*720*x*1280*) 200ms) ### 特性 + 速度快 720p ,单核 Intel 2.2G CPU (macbook Pro 2015)识别时间 <=140ms 。 ++ 基于端到端的车牌识别无需进行字符分割。 + 识别率高 EasyPR数据集上0-error达到 81.75%, 1-error识别率达到 94.1%。 + 轻量 总代码量不超1k行。 @@ -81,13 +84,14 @@ sudo make -j - [x] 单行蓝牌 - [x] 单行黄牌 -- [ ] 新能源车牌 +- [x] 新能源车牌 +- [x] 白色警用车牌 +- [x] 使馆/港澳车牌 +- [x] 教练车牌 - [ ] 双层黄牌 - [ ] 双层武警 - [ ] 双层军牌 - [ ] 农用车牌 -- [ ] 白色警用车牌 -- [ ] 使馆/港澳车牌 - [ ] 民航车牌 - [ ] 个性化车牌 diff --git a/hyperlpr/e2e.py b/hyperlpr/e2e.py new file mode 100755 index 0000000..76b96b8 --- /dev/null +++ b/hyperlpr/e2e.py @@ -0,0 +1,64 @@ +#coding=utf-8 +from keras import backend as K +from keras.models import load_model +from keras.layers import * +from captcha.image import ImageCaptcha +import numpy as np +import random +import string + +import cv2 +import e2emodel as model +chars = [u"京", u"沪", u"津", u"渝", u"冀", u"晋", u"蒙", u"辽", u"吉", u"黑", u"苏", u"浙", u"皖", u"闽", u"赣", u"鲁", u"豫", u"鄂", u"湘", u"粤", u"桂", + u"琼", u"川", u"贵", u"云", u"藏", u"陕", u"甘", u"青", u"宁", u"新", u"0", u"1", u"2", u"3", u"4", u"5", u"6", u"7", u"8", u"9", u"A", + u"B", u"C", u"D", u"E", u"F", u"G", u"H", u"J", u"K", u"L", u"M", u"N", u"P", u"Q", u"R", u"S", u"T", u"U", u"V", u"W", u"X", + u"Y", u"Z",u"港",u"学",u"使",u"警",u"澳",u"挂",u"军",u"北",u"南",u"广",u"沈",u"兰",u"成",u"济",u"海",u"民",u"航",u"空" + ]; +pred_model = model.construct_model("./model/ocr_plate_all_w_rnn_2.h5",) +import time + + + +def fastdecode(y_pred): + results = "" + confidence = 0.0 + table_pred = y_pred.reshape(-1, len(chars)+1) + + res = table_pred.argmax(axis=1) + + for i,one in enumerate(res): + if one0 and ptype<5: + if ptype>0 and ptype<4: plate = cv2.bitwise_not(plate) # demo = verticalEdgeDetection(plate) @@ -137,7 +137,7 @@ def RecognizePlateJson(image): image_rgb = fv.finemappingVertical(image_rgb) cache.verticalMappingToFolder(image_rgb) # print time.time() - t1,"校正" - + print "e2e:",e2e.recognizeOne(image_rgb)[0] image_gray = cv2.cvtColor(image_rgb,cv2.COLOR_BGR2GRAY) @@ -184,6 +184,40 @@ def RecognizePlateJson(image): +def SimpleRecognizePlateByE2E(image): + t0 = time.time() + images = detect.detectPlateRough(image,image.shape[0],top_bottom_padding_rate=0.1) + res_set = [] + for j,plate in enumerate(images): + plate, rect, origin_plate =plate + # plate = cv2.cvtColor(plate, cv2.COLOR_RGB2GRAY) + plate =cv2.resize(plate,(136,36*2)) + res,confidence = e2e.recognizeOne(origin_plate) + print "res",res + + t1 = time.time() + ptype = td.SimplePredict(plate) + if ptype>0 and ptype<5: + # pass + plate = cv2.bitwise_not(plate) + image_rgb = fm.findContoursAndDrawBoundingBox(plate) + image_rgb = fv.finemappingVertical(image_rgb) + image_rgb = fv.finemappingVertical(image_rgb) + cache.verticalMappingToFolder(image_rgb) + cv2.imwrite("./"+str(j)+".jpg",image_rgb) + res,confidence = e2e.recognizeOne(image_rgb) + print res,confidence + res_set.append([[],res,confidence]) + + if confidence>0.7: + image = drawRectBox(image, rect, res+" "+str(round(confidence,3))) + return image,res_set + + + + + + def SimpleRecognizePlate(image): t0 = time.time() @@ -200,8 +234,10 @@ def SimpleRecognizePlate(image): plate = cv2.bitwise_not(plate) image_rgb = fm.findContoursAndDrawBoundingBox(plate) + image_rgb = fv.finemappingVertical(image_rgb) cache.verticalMappingToFolder(image_rgb) + print "e2e:", e2e.recognizeOne(image_rgb) image_gray = cv2.cvtColor(image_rgb,cv2.COLOR_RGB2GRAY) # image_gray = horizontalSegmentation(image_gray)