I am trying to implement openpose on google colab on a set of videos. My problem is I want to specifically output the JSON files to folders named according to the name of the video file. For example, the JSON files of hello.mp4 should be output in a folder named hello. I am using --write_json to output the JSON files and that works when I input an existing directory on Drive. However, I want the folders to be created automatically when I run it on a bunch of videos. I know I am doing something wrong. The folder gets created, but the JSON output doesn't write there. Any help is appreciated!
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)}
CodePudding user response:
Just create the folder beforehand. Change the last few lines:
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}'