HyperLPR3汽车车牌识别

HyperLPR3 是开源高性能中文车牌识别框架,基于深度学习,专为智慧停车、交通监控、网约车场站大屏车牌抓拍识别开发。

具体代码如下:

python 复制代码
"""
pip install opencv-python
pip install hyperlpr3
pip install opencv-contrib-python
"""
import cv2
import hyperlpr3 as lpr3

# 1.车牌识别
def test_01():
    # 初始化识别器 detect_level:LOW快速 / HIGH高精度(停车场推荐HIGH)
    catcher = lpr3.LicensePlateCatcher(detect_level=lpr3.DETECT_LEVEL_HIGH)

    # 读取监控抓拍图片(车场摄像头截图)
    img = cv2.imread("a.jpeg")
    # 执行识别,返回列表:[(号牌,置信度,车牌类型索引,[x1,y1,x2,y2])]
    results = catcher(img)

    # 遍历打印识别结果
    plate_type_map = {0:"蓝牌",1:"黄牌",2:"新能源绿牌",4:"港澳牌",9:"双层黄牌"}
    for plate_code, conf, type_idx, box in results:
        x1,y1,x2,y2 = box
        print(f"车牌:{plate_code},置信度:{conf:.2f},类型:{plate_type_map.get(type_idx,'其他')}")
        print(f"车牌画面坐标:左上角({x1},{y1}) 右下角({x2},{y2})")
# 2.可视化绘制(在监控图上框出车牌 + 号牌文字)

def test_02():
    # 初始化识别器 detect_level:LOW快速 / HIGH高精度(停车场推荐HIGH)
    catcher = lpr3.LicensePlateCatcher(detect_level=lpr3.DETECT_LEVEL_HIGH)

    # 读取监控抓拍图片(车场摄像头截图)
    img = cv2.imread("a1.jpeg")
    # 执行识别,返回列表:[(号牌,置信度,车牌类型索引,[x1,y1,x2,y2])]
    results = catcher(img)
    # 循环绘制所有车牌
    for plate_code, conf, type_idx, box in results:
        text = f"{plate_code} {conf:.2f}"
        img = draw_plate_on_image(img, box, text)

    cv2.imwrite("result.jpg", img)
    cv2.imshow("识别结果", img)
    cv2.waitKey(0)

def draw_plate_on_image(img, box, text, color=(0,255,0), thickness=2):
    """
    复刻hyperlpr3内置绘图函数
    :param img: 原图mat
    :param box: [x1,y1,x2,y2] 车牌坐标
    :param text: 显示文字(车牌+置信度)
    """
    x1, y1, x2, y2 = box
    # 绘制车牌矩形框
    cv2.rectangle(img, (x1, y1), (x2, y2), color, thickness)
    # 绘制文字背景底色
    text_size, _ = cv2.getTextSize(text, cv2.FONT_HERSHEY_SIMPLEX, 0.6, 1)
    text_w, text_h = text_size
    cv2.rectangle(img, (x1, y1 - text_h - 5), (x1 + text_w, y1), color, -1)
    # 绘制文字
    cv2.putText(img, text, (x1, y1 - 5), cv2.FONT_HERSHEY_SIMPLEX, 0.6, (255,255,255), 1)
    return img

if __name__ == "__main__":
    # test_01()
    test_02()
相关推荐
言乐611 小时前
HTML视频审核模型
python·django·virtualenv·pygame·tornado
言乐612 小时前
Python根据无法识别搜索词找出可能输入内容模型
开发语言·python·django·virtualenv·pygame
yl453013 小时前
硫酸泄露处理生产商怎么选才够专业
大数据·人工智能·python
笨笨饿13 小时前
140_AI新手村MCP与Skills是干嘛的
开发语言·人工智能·python·stm32·单片机·嵌入式硬件·物联网
for_ever_love__14 小时前
机器学习入门——手写线性回归与梯度下降
人工智能·python·学习·机器学习·线性回归
打工仔折腾 AI14 小时前
从 Demo 到生产级 Agent:8 个关键设计机制与 Python 实现拆解
java·jvm·人工智能·后端·python·langchain·ai agent 实战
I Am a robert girl14 小时前
当传感器学会“说谎“:拆解可靠性门控的稀疏惯性动捕融合
python·姿态估计·传感器融合·惯性动捕·imu传感器·可靠性门控·可穿戴计算
李航198315 小时前
AI定制柜建模,需要详细的建模规范和标准流程
人工智能·python·计算机视觉·ai·ai编程
沙漠之主15 小时前
Python 教学设计资料:从入门到实战的完整课程方案
爬虫·python
ebiobiz16 小时前
极海 APM32 使用 Nimmake 编译指南
c++·python·单片机·嵌入式硬件·mcu