计算机视觉:python车辆行人检测与跟踪系统 YOLO模型 SORT算法 PyQt5界面 目标检测+目标跟踪 深度学习 计算机✅

博主介绍:✌全网粉丝10W+,前互联网大厂软件研发、集结硕博英豪成立软件开发工作室,专注于计算机相关专业项目实战6年之久,累计开发项目作品上万套。凭借丰富的经验与专业实力,已帮助成千上万的学生顺利毕业,选择我们,就是选择放心、选择安心毕业✌
> 🍅想要获取完整文章或者源码,或者代做,拉到文章底部即可与我联系了。🍅

点击查看作者主页,了解更多项目!

🍅感兴趣的可以先收藏起来,点赞、关注不迷路,大家在毕设选题,项目以及论文编写等相关问题都可以给我留言咨询,希望帮助同学们顺利毕业 。🍅

1、毕业设计:2026年计算机专业毕业设计选题汇总(建议收藏)✅

2、最全计算机专业毕业设计选题大全(建议收藏)✅

1、项目介绍

技术栈:

Python语言、YOLO模型、SORT算法、PyQt5界面、目标检测、目标跟踪

2、项目界面

(1)车辆识别检测跟踪

(2)车辆+行人识别检测跟踪

(3)车辆识别检测跟踪

(4)摄像头---识别检测跟踪

(5)行人识别检测跟踪

(6)系统界面

3、项目说明

摘要:

本文详细介绍如何利用深度学习中的YOLO及SORT算法实现车辆、行人等多目标的实时检测和跟踪,并利用PyQt5设计了清新简约的系统UI界面,在界面中既可选择自己的视频、图片文件进行检测跟踪,也可以通过电脑自带的摄像头进行实时处理,可选择训练好的YOLO v3/v4等模型参数。该系统界面优美、检测精度高,功能强大,设计有多目标实时检测、跟踪、计数功能,可自由选择感兴趣的跟踪目标。

4、核心代码

python 复制代码
# -*- coding: utf-8 -*-
# 本程序用于调用摄像头进行车辆行人等多目标检测跟踪



import warnings
import os
import time
from collections import deque
import cv2
import numpy as np
from sort import Sort
warnings.filterwarnings('ignore')

if __name__ == '__main__':
    CAM_NUM = 0  # 摄像头序号
    if_save = 1  # 是否需要保存录制的视频,1表示保存
    filter_confidence = 0.5  # 用于筛除置信度过低的识别结果
    threshold_prob = 0.3  # 用于NMS去除重复的锚框
    model_path = "./yolo-obj"  # 模型文件的目录

    # 载入数据集标签
    labelsPath = os.path.sep.join([model_path, "coco.names"])
    LABELS = open(labelsPath).read().strip().split("\n")
    # 载入模型参数文件及配置文件
    weightsPath = os.path.sep.join([model_path, "yolov4-tiny.weights"])
    configPath = os.path.sep.join([model_path, "yolov4-tiny.cfg"])

    # 初始化用于标记框的颜色
    np.random.seed(42)
    COLORS = np.random.randint(0, 255, size=(200, 3), dtype="uint8")

    # 用于展示目标移动路径
    pts = [deque(maxlen=30) for _ in range(9999)]

    # 从配置和参数文件中载入模型
    print("[INFO] 正在载入模型...")
    net = cv2.dnn.readNetFromDarknet(configPath, weightsPath)
    ln = net.getLayerNames()
    ln = [ln[i[0] - 1] for i in net.getUnconnectedOutLayers()]

    # 初始化视频流
    vs = cv2.VideoCapture(CAM_NUM)
    (W, H) = (None, None)
    frameIndex = 0

    ret, frame = vs.read()
    vw = frame.shape[1]
    vh = frame.shape[0]
    print("[INFO] 视频尺寸:{} * {}".format(vw, vh))

    if if_save:
        fourcc = cv2.VideoWriter_fourcc(*'XVID')
        output_video = cv2.VideoWriter("./output/captured.avi", fourcc, 20.0, (vw, vh))  # 处理后的视频对象
    else:
        output_video = None

    tracker = Sort()  # 实例化追踪器对象

    # 遍历视频帧进行检测
    while True:
        # 逐帧读取画面
        (grabbed, frame) = vs.read()

        # 获取画面长宽
        if W is None or H is None:
            (H, W) = frame.shape[:2]

        # 将一帧画面读入网络
        blob = cv2.dnn.blobFromImage(frame, 1 / 255.0, (416, 416), swapRB=True, crop=False)
        net.setInput(blob)

        start = time.time()
        layerOutputs = net.forward(ln)
        end = time.time()

        boxes = []  # 用于检测框坐标
        confidences = []  # 用于存放置信度值
        classIDs = []  # 用于识别的类别序号

        # 逐层遍历网络获取输出
        for output in layerOutputs:
            # loop over each of the detections
            for detection in output:
                # extract the class ID and confidence (i.e., probability)
                # of the current object detection
                scores = detection[5:]
                classID = np.argmax(scores)
                confidence = scores[classID]

                # 过滤低置信度值的检测结果
                if confidence > filter_confidence:
                    box = detection[0:4] * np.array([W, H, W, H])
                    (centerX, centerY, width, height) = box.astype("int")

                    # 转换标记框
                    x = int(centerX - (width / 2))
                    y = int(centerY - (height / 2))

                    # 更新标记框、置信度值、类别列表
                    boxes.append([x, y, int(width), int(height)])
                    confidences.append(float(confidence))
                    classIDs.append(classID)

        # 使用NMS去除重复的标记框
        idxs = cv2.dnn.NMSBoxes(boxes, confidences, filter_confidence, threshold_prob)

        dets = []
        if len(idxs) > 0:
            # 遍历索引得到检测结果
            for i in idxs.flatten():
                (x, y) = (boxes[i][0], boxes[i][1])
                (w, h) = (boxes[i][2], boxes[i][3])
                dets.append([x, y, x + w, y + h, confidences[i], classIDs[i]])

        np.set_printoptions(formatter={'float': lambda x: "{0:0.3f}".format(x)})
        dets = np.asarray(dets)

        # 使用sort算法,开始进行追踪
        tracks = tracker.update(dets)

        boxes = []  # 存放追踪到的标记框
        indexIDs = []
        cls_IDs = []
        c = []

        for track in tracks:
            boxes.append([track[0], track[1], track[2], track[3]])
            indexIDs.append(int(track[4]))
            cls_IDs.append(int(track[5]))

        if len(boxes) > 0:
            i = int(0)
            for box in boxes:  # 遍历所有标记框
                (x, y) = (int(box[0]), int(box[1]))
                (w, h) = (int(box[2]), int(box[3]))

                # 在图像上标记目标框
                color = [int(c) for c in COLORS[indexIDs[i] % len(COLORS)]]
                cv2.rectangle(frame, (x, y), (w, h), color, 4)

                center = (int(((box[0]) + (box[2])) / 2), int(((box[1]) + (box[3])) / 2))
                pts[indexIDs[i]].append(center)
                thickness = 5
                # 显示某个对象标记框的中心
                cv2.circle(frame, center, 1, color, thickness)

                for j in range(1, len(pts[indexIDs[i]])):
                    if pts[indexIDs[i]][j - 1] is None or pts[indexIDs[i]][j] is None:
                        continue
                    thickness = int(np.sqrt(64 / float(j + 1)) * 2)
                    cv2.line(frame, (pts[indexIDs[i]][j - 1]), (pts[indexIDs[i]][j]), color, thickness)

                # 标记跟踪到的目标和数目
                text = "{}-{}".format(LABELS[int(cls_IDs[i])], indexIDs[i])
                cv2.putText(frame, text, (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX, 1, color, 3)
                i += 1

        # 实时显示检测画面
        cv2.imshow('Stream', frame)
        if if_save:
            output_video.write(frame)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

        print("FPS:{}".format(int(0.6/(end-start))))
        frameIndex += 1

    print("[INFO] 运行结束...")
    if if_save:
        output_video.release()
    vs.release()
    exit()

🍅✌感兴趣的可以先收藏起来,点赞关注不迷路,想学习更多项目可以查看主页,大家在毕设选题,项目编程以及论文编写等相关问题都可以给我留言咨询,希望可以帮助同学们顺利毕业!🍅✌

5、源码获取方式

🍅由于篇幅限制,获取完整文章或源码、代做项目的,拉到文章底部即可看到个人联系方式。🍅

点赞、收藏、关注,不迷路,下方查看 👇🏻获取联系方式👇🏻

相关推荐
qq_252941316836 分钟前
无人机视角公路两侧滑坡检测数据集 | 公路巡检 滑坡检测 地质灾害 无人机航拍9302期
yolo·目标检测·目标跟踪·无人机·地质灾害·无人机视角·滑坡检测
深蓝AI1 小时前
无头浏览器不必从 Chrome 改:Lightpanda 用 Zig 从零造,100 个页面只占 123MB 内存
人工智能·程序员
奈落243 小时前
AI辅助的另一面:从2026年国际AI安全报告的“故障”清单到国内专家的可靠性短板,自主行动的Agent为什么更难及时干预
人工智能·安全·agent·本地部署·ai 办公
火山引擎开发者社区5 小时前
eMudhra 证书失陷:容器用户最容易忽略的镜像信任链漏洞
人工智能
LabVIEW开发6 小时前
LabVIEW 机载 DIAL:每秒万次甲烷测量
人工智能·labview·labview知识·labview功能·labview程序
实名上网宋凯宣7 小时前
Django
后端·python·django
飞猫的边缘AI7 小时前
英特尔量子生意
人工智能·量子计算·边缘ai
深蓝AI7 小时前
桌面 Agent 缺的不是视觉:Vercel 开源 agent-desktop,用无障碍树 ref 替代截图坐标
人工智能·程序员
镜子AI7 小时前
镜子AI 技术复盘:三条自动化链路上的“停止条件“设计
运维·人工智能·自动化
向哆哆8 小时前
羊行为目标检测数据集:4类别、2,000张图像 | 目标检测
人工智能·yolo·目标检测·目标跟踪