简体   繁体   English

从视频 opencv 文件夹中读取和提取关键点

[英]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.

相关问题 OpenCV:从用户定义的关键点中提取SURF功能 - OpenCV: Extract SURF Features from user-defined keypoints 从筛选检测器中提取关键点 - Extract keypoints from sift detector OpenCV - 从自定义算法中找到的匹配关键点 - OpenCV - Matching Keypoints Found from a Custom Algorithm 如何使用 python 在外部文件中存储和提取 Opencv 关键点/描述符 - How to store and extract Opencv keypoints/ Descriptor in external file using python OpenCV从Blob检测,Python返回关键点的坐标和面积 - OpenCV return keypoints coordinates and area from blob detection, Python 如何在OpenCV窗口中从Dlib覆盖面部关键点 - How to overlay facial keypoints from Dlib in an OpenCV window 从OpenCV Python中ORB生成的关键点提取像素值 - Extracting pixel values from keypoints generated by ORB in OpenCV Python 从文件夹中的所有视频中获取视频帧,使用 openCV 处理,保存到自己的文件夹? - Grab video frames from all videos in folder, process with openCV, save to own folder? 从图像中提取 CV2.Keypoints 对象的像素值 - Extract pixel values from an image for CV2.Keypoints objects 如何从 mp4 视频文件夹中提取帧并将它们传输到另一个文件夹? - How do I extract the frames from a folder of mp4 videos and transfer them to another folder?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM