为什么 JSON 文件没有输出到正在创建的文件夹?



我正试图在谷歌colab上的一组视频上实现openpose。我的问题是,我想专门将JSON文件输出到根据视频文件名称命名的文件夹中。例如,hello.mp4的JSON文件应该在名为hello的文件夹中输出。我使用--write_json来输出json文件,当我在Drive上输入现有目录时,它就可以工作了。但是,当我在一堆视频上运行它时,我希望文件夹能够自动创建。我知道我做错了什么。创建了文件夹,但JSON输出不会写入其中。感谢您的帮助!

import os
from os.path import exists, join, basename, splitext
folder_path = '/content/drive/My Drive/Project/optest/'
files = os.listdir(folder_path)
files.reverse()
for filename in files:
if filename.endswith('.mp4') and not filename.endswith('-openpose.mp4'):
print(filename)
colab_video_path = folder_path + filename
print(colab_video_path)
colab_openpose_video_path = colab_video_path.replace('.mp4', '') + '-openpose.mp4'
print(colab_openpose_video_path)
#output_path = 

if not exists(colab_openpose_video_path):
!cd openpose && ./build/examples/openpose/openpose.bin --hand --number_people_max 1 --video '{colab_video_path}' --display 0 --write_video_with_audio --write_video '{colab_openpose_video_path}' --write_json {os.makedirs('/content/drive/My Drive/Project/optest/output ' +str(filename), exist_ok=True)}

只需预先创建文件夹。更改最后几行:

json_folder_path = '/content/drive/My Drive/Project/optest/output' + str(filename).replace('.mp4', '')
os.makedirs(json_folder_path, exist_ok=True)
if not exists(colab_openpose_video_path):
!cd openpose && ./build/examples/openpose/openpose.bin --hand --number_people_max 1 --video '{colab_video_path}' --display 0 --write_video_with_audio --write_video '{colab_openpose_video_path}' --write_json '{json_folder_path}'

最新更新