yolov5_deepsort避免重复计数笔记

避免重复计数讲解: 每个被候选框检测到的车辆会拥有自己唯一的id和类别信息,每一帧所有的车辆被检测到,并且通过满足相应上行、下行规则,在第一个循环判断中,满足条件的车辆其id会被记录下来放在一个数组,并且其相应的种类会被进行计数,每次进行规则判断决定是否计数之前,都会判断该检测框的id与之前出现过的id进行对比,判断是否重新计数 

def counter_vehicles(outputs, line_pixel, dividing_pixel, counter_recording,up_counter,down_counter):
    box_centers = []

    for i, each_box in enumerate(outputs):
        ###求得每个框的中心点
        box_centers.append([(each_box[0] + each_box[2]) // 2, (each_box[1] + each_box[3]) // 2, each_box[4],
                             each_box[5]])
    for box_center in box_centers:
        id_recorded = False
        if len(counter_recording)==0:
            if box_center[0] <= dividing_pixel and box_center[1] >= line_pixel:
                down_counter[box_center[3]] += 1
                counter_recording.append(box_center[2])
                continue
            elif box_center[0] > dividing_pixel and box_center[1] < line_pixel:
                up_counter[box_center[3]] += 1
                counter_recording.append(box_center[2])
                continue
        if len(counter_recording)>0:
            for n in counter_recording:
                if n == box_center[2]:  ###判断该车辆是否已经记过数
                    id_recorded = True
                    break
            if id_recorded:
                continue
            if box_center[0] <= dividing_pixel and box_center[1] >= line_pixel:
                down_counter[box_center[3]] += 1
                counter_recording.append(box_center[2])
                continue
            elif box_center[0] > dividing_pixel and box_center[1] < line_pixel:
                up_counter[box_center[3]] += 1
                counter_recording.append(box_center[2])
                continue
    return counter_recording, up_counter, down_counter

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值