基于 YOLOX + DeepSeek-OCR 的车牌检测与识别系统。
- 车辆检测:使用 YOLOX 检测图片中的车辆(支持 car、motorcycle、bus、truck)
- 车牌识别:使用 DeepSeek-OCR 识别车牌号码
- 无牌车检测:自动识别无牌车辆
- 变形检测:通过 aspect ratio 判断车牌是否变形严重
- 批量处理:支持批量处理图片并与 Ground Truth 对比
├── plategate/
│ ├── __init__.py
│ ├── ocr_deepseek.py
│ ├── preprocess_plate_image.py # 车牌图片增强,提升彩色字体识别
│ ├── yolox_vehicle.py
│ └── plate_detection_system.py # 核心模块:整合车辆检测和车牌识别
├── test_plate_detection.py # 测试脚本
├── requirements.txt # Python 依赖
├── README.md
├── YOLOX/ # YOLOX 仓库(需手动克隆)
│ └── weights/ # 模型权重目录
│ ├── yolox_s.pth
│ └── yolox_m.pth
├── images/ # 测试图片目录(需自行准备)
│ └── info.json # Ground Truth 文件(可选)
└── tempfiles/ # 临时文件目录(自动创建)
└── YYYY-MM-DD/ # 按日期分类的截取图片
PlateGate 的整体处理流程如下:
-
车辆检测(Vehicle Detection)
- 使用 YOLOX 对输入图像中的所有车辆进行检测。
- 从检测结果中选取 面积最大的车辆 作为目标车辆。
- 基于车辆在图像中所占的 宽度 / 高度比例阈值 进行过滤,防止过小或过远的车辆被误选。
-
车辆区域裁剪(Vehicle Cropping)
- 根据目标车辆的检测框裁剪出车辆区域(ROI)。
- 该步骤可显著减少背景干扰,提高后续识别的稳定性和准确率。
-
图像增强与预处理(Image Enhancement & Preprocessing)
- 使用 Green 通道提取(Green Channel Extraction),从物理层面抑制红色成分。
- 采用 自适应 CLAHE(对比度受限自适应直方图均衡),获得更稳定的对比度增强效果。
- 上述处理对于提升彩色字符(如部分特殊车牌、警车车牌中的红色元素)在 OCR 中的识别准确率尤为有效。
- 额外的预处理步骤包括裁剪、Padding、尺寸归一化与对齐等。
-
车牌识别(License Plate Recognition)
- 对增强后的图像使用 DeepSeek-OCR 进行文字识别。
- 结合 正则表达式 与规则化后处理,提取合法的车牌字符串。
-
最终输出(Final Output)
- 输出最终识别到的车牌结果,并进行置信度过滤与格式化处理。
pip install -r requirements.txt
pip install flash-attn==2.7.3 --no-build-isolation # recommended to use CUDAgit clone https://github.com/Megvii-BaseDetection/YOLOX.git# 创建权重目录
mkdir -p YOLOX/weights
# 下载 yolox_s 权重(小模型,推荐)
wget https://github.com/Megvii-BaseDetection/YOLOX/releases/download/0.1.1rc0/yolox_s.pth -O YOLOX/weights/yolox_s.pth
# 下载 yolox_m 权重(中等模型,更准确)
wget https://github.com/Megvii-BaseDetection/YOLOX/releases/download/0.1.1rc0/yolox_m.pth -O YOLOX/weights/yolox_m.pth下载 https://huggingface.co/deepseek-ai/DeepSeek-OCR 模型
修改 test_plate_detection.py 中的模型路径:
# DeepSeek-OCR 模型路径
MODEL_DIR = "/your/path/to/deepseek-ai/DeepSeek-OCR"将测试图片放入 images/ 目录,支持的格式:.jpg、.jpeg、.png、.webp、.bmp
在 images/ 目录下创建 info.json 文件:
[
{ "image": "IMG_01.jpg", "plate": "苏A·XXXXX" },
{ "image": "IMG_02.png", "plate": "沪B·XXXXXX" },
{ "image": "IMG_03.png", "plate": "" }
]注:无牌车的
plate字段留空或填"无牌"、"-"、"N/A"
python test_plate_detection.py================================================================================
处理图片: images/IMG_01.jpg
车辆检测: 是 (共2辆)
选中车辆: [car] x1=4.3, y1=2.2, x2=956.0, y2=935.8, score=0.912
截取图片: ./tempfiles/2025-01-04/2025-01-04-13-49-54-NDHEGL.png
识别结果: 成功
车牌号码: 苏A·XXXXX
================================================================================
汇总结果
================================================================================
总图片数: 16
检测到车辆: 16 (100.0%)
成功识别车牌: 14 (87.5%)
疑似无牌车: 1
识别失败: 1
================================================================================
与 Ground Truth 对比
================================================================================
准确率: 15/16 (93.8%)
识别错误 (1个):
文件名 正确车牌 识别结果
--------------- --------------- ---------------
IMG_04.png 沪A·XXXXXX 沪A·YYYYYY
在 plate_detection_system.py 中调整:
base_size=1280, # OCR 基础尺寸
image_size=1280, # OCR 输入尺寸
crop_mode=False, # 开启切 tile (Gundam)conf_thre=0.25, # 置信度阈值
nms_thre=0.45, # NMS 阈值
min_wh_ratio=(0.25, 0.25), # 最小宽高比(相对原图)min_aspect=1.2, # 车牌 aspect ratio 阈值(低于此值判定为变形严重)
padding=0.05, # 截取时扩展默认使用 yolox_s,如需使用 yolox_m,取消注释以下配置:
YOLOX_EXP_FILE = "YOLOX/exps/default/yolox_m.py"
YOLOX_CKPT_PATH = "YOLOX/weights/yolox_m.pth"
...
exp_file=YOLOX_EXP_FILE, # 取消注释使用其他模型
ckpt_path=YOLOX_CKPT_PATH,| 状态 | 说明 |
|---|---|
detected |
成功识别车牌 |
no_plate |
无牌车(未检测到省份字符) |
recognition_failed |
识别失败(车牌变形严重或其他原因) |
no_vehicle |
未检测到车辆 |
This repository’s original code is licensed under the MIT License (Copyright © 2026 FlashUnlimited2019).
This project depends on:
-
YOLOX (Apache-2.0) — cloned by user
-
DeepSeek-OCR (MIT) — installed/used by user
