# 1.研究背景
近年来,智能交通系统(ITS)在我国应用日益广泛。作为ITS重要组成部分的自动车牌识别系统在交通流量检测、交通诱导控制、违章车辆监控等方面有着广泛的应用,是确保道路安全畅通的重要手段,也为统计有关资料,为管理者决策提供有效数字依据的重要途径。由于一般的识别系统单幅图像的检测时间较长,达不到实时的要求,从而限制了这种系统在某些方面的应用,比如不停车监控、收费等。而且,即使在固定的地方使用,也必须埋设地感线圈等触发装置,施工及维护都有一定的困难。因此,发展基于视频图像的快速准确的车牌识别系统,具有广阔的发展前景和巨大的经济价值。
# 2.支持图片识别:
![3.png](9404a0ee55390dd4627a65eff02e1201.png)
# 3.支持视频识别:
![2.png](c9ce3bd7d9ea735c4670147fa2bdb25f.png)
# 4.支持实时识别:
![4.png](9532a53b9bd70fdab0f1d1817f8bfa61.png)
# 5.视频演示:
[Python基于OpenCV的视频车牌识别(源码&教程)上半篇_哔哩哔哩_bilibili](https://www.bilibili.com/video/BV11G4y1q7WB/?vd_source=bc9aec86d164b67a7004b996143742dc)
[实时视频流车牌识别(源码)下半篇_哔哩哔哩_bilibili](https://www.bilibili.com/video/BV1qP4y1d7QP?spm_id_from=333.999.0.0&vd_source=bc9aec86d164b67a7004b996143742dc)
# 6.实现原理:
[参考博客提出的如下可调用函数](https://afdian.net/item?plan_id=80488aa85cd611edb70952540025c377)
入口文件 demo.py(部分):
```
import HyperLPRLite as pr
import cv2
import numpy as np
grr = cv2.imread("images_rec/2_.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:"
print pstr
print "plate_confidence"
print confidence
cv2.imshow("image",image)
cv2.waitKey(0)
```
(1) opencv2的imread函数导入图片, 返回的是Mat类型。
(2) HyperLPRLiite.py中的LPR类构造函数导入model, 参数就是训练好的三个模型文件,名字分别是:
- model/cascade.xml
- model/model12.h5
- model/ocr_plate_all_gru.h5
#### HyperLPRLite.py:
```
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)
```
(3)参数 model_detection 就是文件 model/cascade.xml
用到了 opencv2的CascadeClassifier()函数
cv2.CascadeClassifier()
参数输入.xml或者.yaml文件,表示加载模型
一种基于Haar特征的级联分类器用于物体检测的模型
#### model.SImpleRecognizePlateByE2E()函数:
```
for pstr,confidence,rect in model.SimpleRecognizePlateByE2E(grr):
if confidence>0.7:
image = drawRectBox(grr, rect, pstr+" "+str(round(confidence,3)))
print "plate_str:"
print pstr
print "plate_confidence"
print confidence
```
输入为一个Mat类型的图片
输出为识别的车牌字符串,以及confidence可信度,
定义在 HyperLPRLite.py:
```
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
```
其中又用到detectPlateRough()函数
[该博客有详细说明detectPlateRough函数](https://mbd.pub/o/bread/Y5aakp1r)
是返回图像中所有车牌的边框在图片中的bbox
返回的是一个表示车牌区域坐标边框的list
for循环中,对于每个识别出来的车牌用到filemappingVertical()函数
#### detectPlateRough函数
```
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
```
输入参数:
image_gray: 一个rgb图像,Mat类型
resize_h: 重新设定的图像大小
top_bottom_padding_rate: 表示要裁剪掉图片的上下部占比
这个函数实现的处理:
1.resize图像大小,cv2.resize函数,按照原来图像比例
2.裁剪图片,根据输入的top_bottom_padding_rate如果是0.1,那么上面裁剪掉0.1*height,下面也裁剪掉0.1*height
3.将图像从rgb转化为灰度 cv2.cvtColor函数,cv2.COLOR_RGB2GRAY
4.根据前面的cv2.CascadeClassifier()物体检测模型(3),输入image_gray灰度图像,边框可识别的最小size,最大size,输出得到车牌在图像中的offset,也就是边框左上角坐标( x, y )以及边框高度( h )和宽度( w )
5.对得到的车牌边框的bbox进行扩大,也就是宽度左右各扩大0.14倍,高度上下各扩大0.15倍。
6.返回图片中所有识别出来的车牌边框bbox,这个list作为返回结果。
#### filemappingVertical函数
```
def finemappingVertical(self,image,rect):
resized = cv2.resize(image,(66,16))
resized = resized.astype(np.float)/255
res_raw= (np.array([resized]))[0]
res =res_raw*image.shape[1]
res = res.astype(np.int)
H,T = res
H-=3
if H<0:
H=0
T+=2;
if T>= 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
```
输入参数:
裁剪的车牌区域图像(Mat类型),rect也是裁剪的车牌部分的图像(Mat类型)
实现处理:
1.将原来车牌图像resize大小:66*16*3
2.将原来灰度图颜色通道[0, 255]转化为float类型[0,1]
3.将输入66*16(float),输入进模型进行测试self.modelFineMapping.predict
#### modelFineMapping模型
```
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)
```
#### model_finemapping()函数
```
def model_finemapping(self):
input = Input(shape=[16, 66, 3]) # change this shape to [None,None,3] to enable arbitraty shape input
x = Conv2D(10, (3, 3), strides=1, padding='valid', name='c
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
近年来,智能交通系统(ITS)在我国应用日益广泛。作为ITS重要组成部分的自动车牌识别系统在交通流量检测、交通诱导控制、违章车辆监控等方面有着广泛的应用,是确保道路安全畅通的重要手段,也为统计有关资料,为管理者决策提供有效数字依据的重要途径。由于一般的识别系统单幅图像的检测时间较长,达不到实时的要求,从而限制了这种系统在某些方面的应用,比如不停车监控、收费等。而且,即使在固定的地方使用,也必须埋设地感线圈等触发装置,施工及维护都有一定的困难。因此,发展基于视频图像的快速准确的车牌识别系统,具有广阔的发展前景和巨大的经济价值
资源推荐
资源详情
资源评论
收起资源包目录
opencv-python-main.zip (18个子文件)
opencv-python-main
finemappingVertical.py 603B
9404a0ee55390dd4627a65eff02e1201.png 1.35MB
import_HyperLPRLite_.py 528B
c9ce3bd7d9ea735c4670147fa2bdb25f.png 1.14MB
chars_u_京_u_沪_u_津_u_.py 647B
32742c4b561dbea289d82adc0353a2a0.png 327KB
9532a53b9bd70fdab0f1d1817f8bfa61.png 1.05MB
for_pstr_confidence_.py 300B
LPR.py 341B
2a714c6f485a27e17916c8524fe217b0.png 2.19MB
for_j_plate_in_enume.py 269B
SimpleRecognizePlateByE2E.py 453B
detectPlateRough.py 1KB
model_finemapping.py 763B
model_seq_rec.py 1KB
README.md 15KB
27ec20a9ca6e33e2cfba29448ee4a136.png 106KB
recognizeOne.py 286B
共 18 条
- 1
资源评论
MarcoPage
- 粉丝: 2134
- 资源: 797
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功