python车流量检测车流统计车辆计数yolov5 deepsort车流检测

python车流量检测车流统计车辆计数yolov5 deepsort车流检测

基于之前的yolo+deepsort上,将person类别改为车辆类别,因为coco数据集中,车辆类别有几种【car,bus,truck】,所以都要保存下来。

首先来看一下yolov5+deepsort的车辆跟踪初始效果,看着密密麻麻的框和id,思考一下该如何去设计这些规则进行统计。


labelsPath = "./yolo-coco/coco.names"
LABELS = open(labelsPath).read().strip().split("\n")

np.random.seed(42)
COLORS = np.random.randint(0, 255, size=(200, 3),dtype="uint8")

weightsPath = "./yolo-coco/yolov5.weights"
configPath = "./yolo-coco/yolov5.cfg"

net = cv2.dnn.readNetFromDarknet(configPath, weightsPath)
ln = net.getLayerNames()
ln = [ln[i - 1] for i in net.getUnconnectedOutLayers()]

# ----------------------------------------------------------------------------------------------------------------------
"""
# cv2.VideoCapture() --- 里面参数如果地址,打开视频文件 --- 里面参数是0/1,打开摄像头
# 当参数是0的时候,打开计算机的内置摄像头,当参数为1的时候打开计算机的外置摄像头
# (W, H) = (None, None) --- 视频的宽度和高度,初始化视频编写器(writer)和帧尺寸

"""
# ----------------------------------------------------------------------------------------------------------------------

vs = cv2.VideoCapture('./input/123.mp4')
(W, H) = (None, None)

# ----------------------------------------------------------------------------------------------------------------------
"""
# try to determine the total number of frames in the video file
# 打开一个指向视频文件的文件指针,循环读取帧 --- 尝试确定视频文件中的总帧数(total),以便估计整个视频的处理时间;
# CV_CAP_PROP_FRAME_COUNT --- 视频的帧数
# 这里使用是处理视频的时候固定的过程,不必过度的纠结其使用 ---
#					   if imutils.is_cv2():
#					   	  prop = cv2.cv.CV_CAP_PROP_FRAME_COUNT
#					   else:
#					   	  prop = cv2.CAP_PROP_FRAME_COUNT
#
# vs.get(prop) --- cv2.VideoCapture.get(prop) --- 得到视频的总帧数 
# print("[INFO] {} total frames in video".format(total)) --- 输出视频的帧数

"""
# ----------------------------------------------------------------------------------------------------------------------
try:
    prop = cv2.cv.CV_CAP_PROP_FRAME_COUNT if imutils.is_cv2() \
        else cv2.CAP_PROP_FRAME_COUNT
    total = int(vs.get(prop))
    print("[INFO] {} total frames in video".format(total))

except:
    print("[INFO] could not determine # of frames in video")
    print("[INFO] no approx. completion time can be provided")
    total = -1

while True:
    # ----------------------------------------------------------------------------------------------------------------------

    """
    # cv2.VideoCapture.read() ---> 读取视频,在while中循环读取视频的frame
    # vs.read() ---> 得到两个参数,其中ret是布尔值,如果读取帧是正确的则返回True,
    # 如果文件读取到结尾,它的返回值就为False。frame就是每一帧的图像,是个三维矩阵。
    # 第一个参数为False的时候,if not grabbed --- True --- 循环结束,

    """
    (grabbed, frame) = vs.read()

    if not grabbed:
        break

    if W is None or H is None:
        (H, W) = frame.shape[:2]


 

python车流量检测双向车流计数

 python车流量检测车流统计车辆计数yolov5deepsort车流检测-机器学习文档类资源-CSDN下载

0 代码基础视频跑通教程:

https://download.csdn.net/download/babyai996/85100267

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

babyai997

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

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

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

打赏作者

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

抵扣说明:

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

余额充值