阅读opti文件夹中的所有视频

2024-10-01 22:39:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我想将多个avi视频读入光流python代码

这是我目前正在使用的一个视频

cap=cv.VideoCapture(“029f_hap_4.8_sta_1_2.9for4sc50.avi”)

你能告诉我如何创建一个循环来读取所有视频,这样我就可以在所有视频上运行代码了吗

谢谢


Tags: 代码视频cvcapavi光流stahap
2条回答

试试这个:

from os import listdir
from os.path import isfile
some_path = "enter your path here"

folder_contents = os.listdir(".")
for item in folder_contents:
    if os.path.isfile(item):
        do_something(item)

让我们试试这个:

import os
import cv2 as cv
dirpath = '/path/to/your/video/dir'
os.chdir(dirpath)

# assuming inside the folder, all the files are video file type
video_list = os.listdir('.')

for video in video_list:
    cap = cv.VideoCapture('./' + video)

相关问题 更多 >

    热门问题