一、HyperLPR开源项目地址:
https://github.com/zeusees/HyperLPR
二、简单使用
1、一键安装
pip install hyperlpr
2、代码调用
#导入包
from hyperlpr import *
#导入OpenCV库
import cv2
#读入图片
image = cv2.imread("demo.jpg")
#识别结果
print(HyperLPR_PlateRecogntion(image))
如上图,返回识别结果,置信度和左上 右下坐标点
3、在检测视频流中应用
- Font 识别结果字体标注
- model 识别模型
- src 识别数据源
更多关于model下模型介绍见截图
详细调用流程如下:
import sys
from importlib import reload
import time
import HyperLPR_CarNum.HyperLPRLite as pr
import cv2
import numpy as np
from PIL import ImageFont
from PIL import Image
from PIL import ImageDraw
reload(sys)
fontC = ImageFont.truetype("./Font/platech.ttf", 14, 0)
'''
车牌边框号码绘制
'''
def drawRectBox(image, rect, addText):
cv2.rectangle(image, (int(rect[0]), int(rect[1])), (int(rect[0] + rect[2]), int(rect[1] + rect[3])), (0, 0, 255), 2,
cv2.LINE_AA)
cv2.rectangle(image, (int(rect[0] - 1), int(rect[1]) - 16), (int(rect[0] + 115), int(rect[1])), (0, 0, 255), -1,
cv2.LINE_AA)
img = Image.fromarray(image)
draw = ImageDraw.Draw(img)
draw.text((int(rect[0] + 1), int(rect[1] - 16)), addText, (255, 255, 255), font=fontC)
imagex = np.array(img)
return imagex
'''
预测
'''
def carnum_rec(grr):
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.namedWindow("enhanced", 0)
# cv2.resizeWindow("enhanced", 640, 480)
cv2.imshow("enhanced", image)
'''
数据源
'''
def video_capture():
# 视频源
capture = cv2.VideoCapture("src/carnum.avi")
i = 1
while True:
ref, frame = capture.read()
if ref:
cv2.imshow("enhanced", frame)
i = i + 1
if i % 10 == 0: # 每10帧 取一帧检测
i = 0
carnum_rec(frame)
# 等待30ms显示图像,若过程中按“Esc”退出
c = cv2.waitKey(30) & 0xff
if c == 27: # ESC 按键 对应键盘值 27
capture.release()
break
else:
break
if __name__ == '__main__':
model = pr.LPR("model/cascade.xml", "model/model12.h5", "model/ocr_plate_all_gru.h5")
video_capture()
cv2.destroyAllWindows()
以上代码已上传百度网盘
链接:https://pan.baidu.com/s/11MZJy76KgF0SNpa20gbSeQ
提取码:j5va