用yolov7对视频进行人体关键点检测,在run方法中传入了一个视频文件。如果想同时检测多个视频文件应该怎么改?
def run(poseweights="yolov7-w6-pose.pt", source="", device='cpu', view_img=False,
save_conf=False, line_thickness=3, hide_labels=False, hide_conf=True):
frame_count = 0 # count no of frames
total_fps = 0 # count total fps
time_list = [] # list to store time
fps_list = [] # list to store fps
device = select_device(opt.device) # select device
half = device.type != 'cpu'
model = attempt_load(poseweights, map_location=device) # Load model
_ = model.eval()
names = model.module.names if hasattr(model, 'module') else model.names # get class
if source.isnumeric():
cap = cv2.VideoCapture(int(source)) # pass video to videocapture object
else:
cap = cv2.VideoCapture(source) # pass video to videocapture object
if (cap.isOpened() == False): # check if videocapture not opened
print('Error while trying to read video. Please check path again')
raise SystemExit()
else:
frame_width = int(cap.get(3)) # get video frame width
frame_height = int(cap.get(4)) # get video frame height
vid_write_image = letterbox(cap.read()[1], (frame_width), stride=64, auto=True)[0] # init videowriter
resize_height, resize_width = vid_write_image.shape[:2]
out_video_name = f"{source.split('/')[-1].split('.')[0]}"
out = cv2.VideoWriter(f"{source}_keypoint.mp4",
cv2.VideoWriter_fourcc(*'mp4v'), 30,
(resize_width, resize_height))