YOLOv8-DeepSORT-PaddleOCR-监督车辆管理

完整项目链接:https://github.com/lingskr/YOLOV8-PaddleOCR-Vehicle-Management

目录

  1. 动机
  2. 安装
  3. 文件说明
  4. 致谢

YOLOV8模型和PaddleOCR进行车辆管理系统的开发

在这里插入图片描述

动机

近年来,人工智能领域发展迅速。这种发展促使我们探索如何利用先进技术来增强高速公路交通摄像头系统。该项目的主要动机是将尖端的深度学习算法无缝集成到我们的车辆管理系统中。为了实现这一目标,我们的项目旨在实现以下目标:

  1. 检测和分类道路上的车辆,包括汽车、卡车、公共汽车和摩托车。

  2. 通过实施强大的跟踪系统,在车辆进入和离开监控区域时对其进行计数

  3. 实时估计二维帧上的速度

  4. 检测和识别车牌,进一步增强系统的功能。

通过实现这些目标,我们希望创建一个更高效、更智能的交通监控系统,利用人工智能的力量来增强高速公路的安全和交通管理。

安装

  • Python >= 3.6
  • surveillance ~= 0.1.0
  • ultralytics ~= 8.0.190
  • deep-sort-realtime == 1.3.1
  • paddleocr >= 2.0.1
  • PyMuPDF == 1.21.1
  • numpy < 1.24|
  • opencv-python ~= 4.8.1.78
  • pyaml_env ~= 1.2.1

要安装此项目及其依赖项,请按照以下步骤操作:

  1. 克隆此存储库:
git clone https://github.com/lingskr/YOLOV8-PaddleOCR-Vehicle-Management.git
  1. 使用 pip 安装项目的依赖项:
pip install requirements.txt
  1. 运行命令:
python main.py --config-path ./utils/config.yml --source-video ./data/videos/vehicle-counting.mp4 --target-video ./output.mp4

或者您可以点击我上面提供的 Vehicle_Quick_Test 笔记本来快速运行测试并查看结果。

文件描述

═── README.md
═── main.py *** 运行 ConfigManager 和 VideoProcessor
═── requirements.txt
═── data
│ ═── models
│ │ ═── yolov8x.pt *** 车辆检测权重
│ │ ═── license_plate_detector.pt
│ ═── videos
│ │ ═── vehicle-counting.mp4 *** 输入视频
│ │ ═── output.mp4
═── modules
│ ═── comment.py *** 注释注释和跟踪轨迹
│ ═── plate_recognition.py *** 检测、识别和注释车牌
│ ═── speed_estimation.py *** 利用 2D 摄像头的信息估计速度
│ ═── video_processor.py *** 利用 surveillance、yolov8、deepsort、paddleOCR 的核心类
└── utils
═── config.py *** ConfigManager 加载配置文件
└── config.yml

建立环境

import sys
if 'google.colab' in sys.modules:
    print('Running in Colab.')
    !git clone https://github.com/lingskr/YOLOV8-PaddleOCR-Vehicle-Management.git
else:
    sys.path.append('..')
cd './YOLOv8-DeepSORT-PaddleOCR-Supervision-Vehicle-Management-System'
!pip install supervision==0.1.0
!pip install deep-sort-realtime==1.3.1
!pip install ultralytics
!pip install opencv-python
!pip install paddlepaddle-gpu
!pip install paddleocr
!pip install pyaml_env

下载包

!wget http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.0g-2ubuntu4_amd64.deb
!sudo dpkg -i libssl1.1_1.1.0g-2ubuntu4_amd64.deb

设置视频和模型

SOURCE_VIDEO_PATH = "./data/videos/vehicle-counting.mp4"
TARGET_VIDEO_PATH = "output.mp4"
model = YOLO("./data/models/yolov8x.pt")
model.fuse()
CLASS_NAMES_DICT = model.model.names
CLASS_ID = [2, 3, 5, 7]
CLASS_DICT = {}
for id in CLASS_ID:
    CLASS_DICT[id] = CLASS_NAMES_DICT[id]
print(CLASS_DICT)

单帧推理

# 创建 VideoInfo 实例,帧生成器
video_info = VideoInfo.from_video_path(SOURCE_VIDEO_PATH)
generator = get_video_frames_generator(SOURCE_VIDEO_PATH)

# 创建 BoxAnnotator 实例
box_annotator = BoxAnnotator(color=ColorPalette(), thickness=4, text_thickness=4, text_scale=1)
# 获取前50个视频帧
for _ in range(50):
    iterator = iter(generator)
    frame = next(iterator)

检测车辆

# 使用置信度阈值 0.7 进行预测
results = model(frame, conf=0.7)

注释车辆

# 模型预测到监督检测
detections = Detections(
    xyxy=results[0].boxes.xyxy.cpu().numpy(),
    confidence=results[0].boxes.conf.cpu().numpy(),
    class_id=results[0].boxes.cls.cpu().numpy().astype(int)
)

# 格式化自定义标签
labels = [
    f"{CLASS_NAMES_DICT[class_id]} {confidence:.2f}"
    for _, confidence, class_id, tracker_id
    in detections
]
%matplotlib inline
frame_ = frame.copy()
frame_ = box_annotator.annotate(frame=frame_, detections=detections, labels=None)
show_frame_in_notebook(frame_, (16, 16))
from IPython.display import Image
Image(filename='/home/aistudio/data/1.png')

检测并注释车牌

license_plate_detector = YOLO("./data/models/license_plate_detector.pt")


from paddleocr import PaddleOCR

ocr_model = PaddleOCR(lang='en', show_log=False, use_angle_cls=True, use_gpu=False)

from modules.plate_recognition import PlateRecognizer

plate_recognizer = PlateRecognizer(license_plate_detector, ocr_model)




import numpy as np

for data in results[0].boxes.data.cpu().numpy():
    x1, y1, x2, y2, car_conf, label = data
    car_frame = frame[int(y1):int(y2), int(x1):int(x2)]
    plates = license_plate_detector(car_frame, conf=0.7)

    if plates[0]:
        x1_, y1_, x2_, y2_, plate_conf, label = plates[0].boxes.data.cpu().numpy()[0]
        plate_frame = car_frame[int(y1_):int(y2_), int(x1_):int(x2_)]

        result = ocr_model.ocr(plate_frame, cls=True)
        if result:
            info = result[0][0][-1]
            print(f"Licence Plate: {info[0]}, Conf: {info[1]}, Car_conf: {car_conf}, Plate_conf: {plate_conf}")

            # Visualize the plates
            text = f"[{info[0]}] Conf: {info[1]:0.2f}"
            frame_ = plate_recognizer.annotate(frame_, np.array([x1, y1, x2, y2]), text)
        else:
            print(f"None, Car_conf: {car_conf}, Plate_conf: {plate_conf}")
        print("-"*80)

视频推理

!python main.py --config-path ./utils/config.yml --source-video ./data/videos/vehicle-counting.mp4 --target-video ./output.mp4

致谢

我们感谢以下存储库为我们的项目做出的宝贵贡献:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hsling松子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值