diff --git a/.idea/workspace.xml b/.idea/workspace.xml
new file mode 100644
index 0000000..3ff0d64
--- /dev/null
+++ b/.idea/workspace.xml
@@ -0,0 +1,397 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ print
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ $USER_HOME$/.subversion
+
+
+
+
+ 1523462206021
+
+
+ 1523462206021
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/HyperLPRLite.py b/HyperLPRLite.py
new file mode 100644
index 0000000..170d30e
--- /dev/null
+++ b/HyperLPRLite.py
@@ -0,0 +1,164 @@
+#coding=utf-8
+import cv2
+import numpy as np
+from keras import backend as K
+from keras.models import *
+from keras.layers import *
+
+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"空"
+ ]
+
+class LPR():
+ def __init__(self,model_detection,model_finemapping,model_seq_rec):
+ self.watch_cascade = cv2.CascadeClassifier(model_detection)
+ self.modelFineMapping = self.model_finemapping()
+ self.modelFineMapping.load_weights(model_finemapping)
+ self.modelSeqRec = self.model_seq_rec(model_seq_rec)
+
+ def computeSafeRegion(self,shape,bounding_rect):
+ top = bounding_rect[1] # y
+ bottom = bounding_rect[1] + bounding_rect[3] # y + h
+ left = bounding_rect[0] # x
+ right = bounding_rect[0] + bounding_rect[2] # x + w
+ min_top = 0
+ max_bottom = shape[0]
+ min_left = 0
+ max_right = shape[1]
+ if top < min_top:
+ top = min_top
+ if left < min_left:
+ left = min_left
+ if bottom > max_bottom:
+ bottom = max_bottom
+ if right > max_right:
+ right = max_right
+ return [left,top,right-left,bottom-top]
+
+ def cropImage(self,image,rect):
+ x, y, w, h = self.computeSafeRegion(image.shape,rect)
+ return image[y:y+h,x:x+w]
+
+ def detectPlateRough(self,image_gray,resize_h = 720,en_scale =1.08 ,top_bottom_padding_rate = 0.05):
+ if top_bottom_padding_rate>0.2:
+ print "error:top_bottom_padding_rate > 0.2:",top_bottom_padding_rate
+ exit(1)
+ height = image_gray.shape[0]
+ padding = int(height*top_bottom_padding_rate)
+ scale = image_gray.shape[1]/float(image_gray.shape[0])
+ image = cv2.resize(image_gray, (int(scale*resize_h), resize_h))
+ image_color_cropped = image[padding:resize_h-padding,0:image_gray.shape[1]]
+ image_gray = cv2.cvtColor(image_color_cropped,cv2.COLOR_RGB2GRAY)
+ watches = self.watch_cascade.detectMultiScale(image_gray, en_scale, 2, minSize=(36, 9),maxSize=(36*40, 9*40))
+ cropped_images = []
+ for (x, y, w, h) in watches:
+ x -= w * 0.14
+ w += w * 0.28
+ y -= h * 0.15
+ h += h * 0.3
+ cropped = self.cropImage(image_color_cropped, (int(x), int(y), int(w), int(h)))
+
+ cropped_images.append([cropped,[x, y+padding, w, h]])
+ return cropped_images
+
+ def fastdecode(self,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 one= image.shape[1]-1:
+ T= image.shape[1]-1
+
+ rect[2] -= rect[2]*(1-res_raw[1] + res_raw[0])
+ rect[0]+=res[0]
+
+ image = image[:,H:T+2]
+
+ image = cv2.resize(image, (int(136), int(36)))
+ return image,rect
+
+ def recognizeOne(self,src):
+ x_tempx = src
+ x_temp = cv2.resize(x_tempx,( 164,48))
+ x_temp = x_temp.transpose(1, 0, 2)
+ y_pred = self.modelSeqRec.predict(np.array([x_temp]))
+ y_pred = y_pred[:,2:,:]
+ return self.fastdecode(y_pred)
+
+ def SimpleRecognizePlateByE2E(self,image):
+ images = self.detectPlateRough(image,image.shape[0],top_bottom_padding_rate=0.1)
+ res_set = []
+ for j,plate in enumerate(images):
+ plate, rect =plate
+ image_rgb,rect_refine = self.finemappingVertical(plate,rect)
+ res,confidence = self.recognizeOne(image_rgb)
+ res_set.append([res,confidence,rect_refine])
+ return res_set
+
+
+
+
+
diff --git a/README.md b/README.md
index 6b53948..80edf35 100644
--- a/README.md
+++ b/README.md
@@ -1,24 +1,36 @@
-# High Accuracy Chinese License Plate Recognition Framework
+# High Accuracy Chinese Plate Recognition Framework
### 介绍
This research aims at simply developping plate recognition project based on deep learning methods, with low complexity and high speed. This
-project has been used by some commercial corporations. Free and open source, deploying by Zeusee. this pipline also can apply to other countries license plate by training
+project has been used by some commercial corporations. Free and open source, deploying by Zeusee.
-HyperLPR是一个使用深度学习针对对中文车牌识别的实现,与其他开源的中文车牌识别框架相比,它的检测速度和鲁棒性和多场景的适应性都要好于其他的开源框架。
+HyperLPR是一个使用深度学习针对对中文车牌识别的实现,与较为流行的开源的[EasyPR](https://github.com/liuruoze/EasyPR)相比,它的检测速度和鲁棒性和多场景的适应性都要好于目前开源的EasyPR。
+
+##### 更新热点:
+
+- 添加的新的Python 序列模型-识别率大幅提高(尤其汉字)(2018.3.12)
+- 新添加了HyperLPR Lite 只需要一个文件 160行代码即可完全整个车牌识别流程.
+- 提供精确定位的车牌矩形框(2018.3.12)
#### 相关资源
+
+ [在线测试地址](http://sftera.vicp.io:8000/uploader)(已失效)。
+ [相关技术博客](http://blog.csdn.net/relocy/article/details/78705662)(技术文章会在接下来的几个月的时间内连续更新)。
+ [带UI界面的工程](https://pan.baidu.com/s/1cNWpK6)(感谢群内小伙伴的工作)。
+ [端到端(多标签分类)训练代码](https://github.com/LCorleone/hyperlpr-train_e2e)(感谢群内小伙伴的工作)。
+ [端到端(CTC)训练代码](https://github.com/armaab/hyperlpr-train)(感谢群内小伙伴工作)。
-+ [训练代码和字符分割介绍](https://github.com/zeusees/HyperLPR-Training)。
-+ [IOS版本 xiaojun123456贡献](https://github.com/xiaojun123456)。
-+ [编译好的OpenCV_3.3.1_VS2013_Win64 版本](https://pan.baidu.com/s/1c3cgGyk);(采用VS2015可以使用opencv_3.3以上官方提供的Release版本)。
### 更新
-+ 增加了端到端模型的cpp实现,识别速度比分割快30%(Linux)(2018.1.31)
-+ 增加字符分割[训练代码和字符分割介绍](https://github.com/zeusees/HyperLPR-Training)(2018.1)
+
++ 添加的新的Python 序列模型-识别率大幅提高(尤其汉字)(2018.3.12)
++ 添加了HyperLPR Lite 仅仅需160 行代码即可实现车牌识别(2018.3.12)
++ 提供精确定位的车牌矩形框(2018.3.12)
+
+
++ 增加了端到端模型的cpp实现(Linux)(2018.1.31)
+
+
++ 增加字符分割[训练代码和字符分割介绍](https://github.com/zeusees/HyperLPR-Training)(2018.1.)
+ 更新了Android实现,大幅提高准确率和速度 (骁龙835 (*720*x*1280*) ~50ms )(2017.12.27)
+ 添加了IOS版本的实现(感谢[xiaojun123456](https://github.com/xiaojun123456)的工作)
+ 添加端到端的序列识别模型识别率大幅度提升,使得无需分割字符即可识别,识别速度提高20% (2017.11.17)
@@ -39,6 +51,19 @@ HyperLPR是一个使用深度学习针对对中文车牌识别的实现,与其
+ 识别率高,仅仅针对车牌ROI在EasyPR数据集上,0-error达到 95.2%, 1-error识别率达到 97.4% (指在定位成功后的车牌识别率)
+ 轻量 总代码量不超1k行
+### 模型资源说明
+
++ cascade.xml 检测模型 - 目前效果最好的cascade检测模型
++ cascade_lbp.xml 召回率效果较好,但其错检太多
++ char_chi_sim.h5 Keras模型-可识别34类数字和大写英文字 使用14W样本训练
++ char_rec.h5 Keras模型-可识别34类数字和大写英文字 使用7W样本训练
++ ocr_plate_all_w_rnn_2.h5 基于CNN的序列模型
++ ocr_plate_all_gru.h5 基于GRU的序列模型从OCR模型修改,效果目前最好但速度较慢,需要20ms。
++ plate_type.h5 用于车牌颜色判断的模型
++ model12.h5 左右边界回归模型
+
+
+
### 注意事项:
+ Win工程中若需要使用静态库,需单独编译
@@ -61,12 +86,25 @@ HyperLPR是一个使用深度学习针对对中文车牌识别的实现,与其
### 简单使用方式
+新更新的HyperLPR Lite
+
```python
-from hyperlpr import pipline as pp
+import HyperLPRLite as pr
import cv2
-image = cv2.imread("filename")
-image,res = pp.SimpleRecognizePlate(image)
-print(res)
+import numpy as np
+grr = cv2.imread("images_rec/demo1.jpg")
+model = pr.LPR("model/cascade.xml","model/model12.h5","model/ocr_plate_all_gru.h5")
+
+for pstr,confidence,rect in model.SimpleRecognizePlateByE2E(grr):
+ if confidence>0.7:
+ image = drawRectBox(grr, rect, pstr+" "+str(round(confidence,3)))
+ print("plate_str",pstr)
+ print("plate_confidence",confidence)
+
+
+cv2.imshow("image",image)
+cv2.waitKey(0)
+
```
### Linux/Mac 编译
diff --git a/model/ocr_plate_all_gru.h5 b/model/ocr_plate_all_gru.h5
new file mode 100644
index 0000000..ca1761c
Binary files /dev/null and b/model/ocr_plate_all_gru.h5 differ