我正在嘗試在一組視頻上在 google 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)}
uj5u.com熱心網友回復:
只需事先創建檔案夾。更改最后幾行:
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}'
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/518541.html
