赞
踩
import numpy as np import cv2 def video_demo(): # 加载已经训练好的模型路径,可以是绝对路径或者相对路径 weightsPath = "backup/yolo-obj_final.weights" configPath = "cfg/yolo-obj.cfg" labelsPath = "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) # 读入待检测的图像 # 0是代表摄像头编号,只有一个的话默认为0 yolo_num = 1 while (True): boxes = [] confidences = [] classIDs = [] print("yolo%d" % yolo_num) yolo_num = yolo_num
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。