关于HyperLPR车牌检测使用笔迹

一、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、在检测视频流中应用

  1. Font   识别结果字体标注
  2. model 识别模型
  3. 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

  • 3
    点赞
  • 40
    收藏
    觉得还不错? 一键收藏
  • 40
    评论
评论 40
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值