[英]Read and extract keypoints from folder of videos opencv
I have a list of videos (10 sec each) in a folder and I'm trying to loop through each action video to extract keypoints and save them as json files.我在一个文件夹中有一个视频列表(每个 10 秒),我正在尝试循环播放每个动作视频以提取关键点并将它们保存为 json 文件。
path = "path to video folder"
for file in os.listdir(path):
cap = cv2.VideoCapture(path+file)
while cap.isOpened():
try:
ret, frame = cap.read()
I ran into a problem where the extracted data has some keypoints from other videos, and I just want to run this code, end with the stop time for the video is done, pause, start next video.我遇到了一个问题,其中提取的数据有一些来自其他视频的关键点,我只想运行这段代码,以视频的停止时间结束,暂停,开始下一个视频。 How can I help correct this?我怎样才能帮助纠正这个问题?
If you want to process multiple videos in turn you can check the ret
(success) value of cap.read()
to detect the end of each file.如果要依次处理多个视频,可以检查cap.read()
的ret
(成功)值来检测每个文件的结尾。 Here is a basic example you can start with:这是您可以开始的基本示例:
import os
import cv2
path = "videos"
for file in os.listdir(path):
print(file)
cap = cv2.VideoCapture(path + '/' + file)
count = 0
while True:
ret, frame = cap.read()
# check for end of file
if not ret:
break
# process frame
count += 1
print(f"{count} frames read")
cap.release()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.