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()
相关推荐
蓝博AI6 小时前
2027基于yolov8飞机蒙皮缺陷检测,支持图像,视频和摄像实时检测,python源码
开发语言·python·yolo
是菜鸡小小陈啊6 小时前
【CS329Z Assignment 1】从零构建 LLM Agent Harness(学习笔记)08
笔记·python·学习·大模型·llm
搁浅小泽7 小时前
泰克(Tektronix)示波器测试方法及注意事项技术规范
stm32·单片机·嵌入式硬件·汽车
人工智能技术咨询.8 小时前
高质量数据集的一致性
python
IT小小猪9 小时前
子进程闪黑窗:pythonw 没有控制台,0x08000000 一个参数解决
运维·windows·python·自动化·进程管理
2601_962885729 小时前
如何用 Python 计算终极振荡器(Ultimate Oscillator, UOS)?
开发语言·python
Thanks_ks9 小时前
Python 列表与元组:可变性与不可变性的差异及使用场景选择
数据结构·python·列表·元组·可变对象·不可变对象·可哈希
benchmark_cc11 小时前
一次获取多只股票实时行情:QuantDash `quotes.get(symbols=[...])` 批量快照
开发语言·python·数据分析·pandas·量化交易·股票数据·quantdash
geovindu11 小时前
python: PCA
开发语言·后端·python·算法
AI模型调用笔记11 小时前
流式 API 的 usage 为 null?用 cURL 看尾帧,别漏空 choices
python