社交距离检测——目标检测+距离检测

参考

window10下打开摄像头实现Pytorch-YOLOv3的实时监测
python+OpenCV+YOLOv3打开笔记本摄像头模型检测
基于yoloV3的目标检测
社交距离检测器——Tensorflow检测模型设计

1.社交距离的目标检测,只需要检测人即可

import numpy as np
import cv2


def video_demo():
    # 加载已经训练好的模型路径,可以是绝对路径或者相对路径
    weightsPath = r'D:\YOLO\darknet-master\build\darknet\x64\yolov3.weights'
    configPath = r"D:\YOLO\darknet-master\cfg\yolov3.cfg"
    labelsPath = r"D:\YOLO\darknet-master\data\coco.names"
    # 初始化一些参数
    LABELS = open(labelsPath).read().strip().split("\n")  # 物体类别
    COLORS = np.random.randint(0, 255, size=(len(LABELS), 3), dtype="uint8")  # 颜色
    net = cv2.dnn.readNetFromDarknet(configPath, weightsPath)
    # net.setPreferableBackend(cv2.dnn.DNN_BACKEND_CUDA)
    # net.setPreferableTarget(cv2.dnn.DNN_TARGET_CUDA)

    # 读入待检测的图像
    # 0是代表摄像头编号,只有一个的话默认为0
    # capture = cv2.VideoCapture(0)
    capture = cv2.VideoCapture(r'C:\Users\lenovo\Desktop\shipin\01.mp4')
    # 读入待检测的图像
    # 0是代表摄像头编号,只有一个的话默认为0
    yolo_num = 1
    while (True):
        boxes = []
        confidences = []
        classIDs = []
        print("yolo%d" % yolo_num)
        yolo_num = yolo_num + 1
        ref, image = capture.read()
        #image = cv2.resize(image, (300, 300), fx=0.25, fy=0.25)
        (H, W) = image.shape[:2]

        # 得到 YOLO需要的输出层
        ln = net.getLayerNames()
        ln = [ln[i[0] - 1] for i in net.getUnconnectedOutLayers()]

        # 从输入图像构造一个blob,然后通过加载的模型,给我们提供边界框和相关概率
        blob = cv2.dnn.blobFromImage(image, 1 / 255.0, (416, 416), swapRB=True, crop=False)
        net.setInput(blob)
        layerOutputs = net.forward(ln)

        # 在每层输出上循环
        for output in layerOutputs:
            # 对每个检测进行循环
            for detection in output:
                scores = detection[5:]
                classID = np.argmax(scores)
                confidence = scores[classID]
                # 过滤掉那些置信度较小的检测结果
                if confidence > 0.5:
                    # 框后接框的宽度和高度
                    box = detection[0:4] * np.array([W, H, W, H])
                    (centerX, centerY, width, height) = box.astype("int")
                    # 边框的左上角
                    x = int(centerX - (width / 2))
                    y = int<
  • 3
    点赞
  • 57
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值