framenr = 0 if not videoframe.isOpened(): print("Error opening video stream or file") while videoframe.isOpened(): ret, img = videoframe.read() if not ret: # reached end of video break start = time.time() img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) detections = detector.detect(img) det_list, crop_list = detector.get_detections(img, detections) det_ids = reid.evaluate_query(crop_list) detector.save_pic_with_detections(img, detections, det_ids, title=f"pic-{framenr:04}") print(f"Elaborating frame {framenr} fps: {1 / (time.time() - start):.3}") framenr += 1 print("Processing finished, saving video") videoframe.release() cv2.destroyAllWindows() save_video(work_dir, output_dir, filename=opt.outname) print(f"Video saved as {os.path.join(output_dir, opt.outname)}") clear_folder(work_dir)