【问题标题】:Using opencv to extract frames and output is empty使用opencv提取帧,输出为空
【发布时间】:2021-05-12 11:00:38
【问题描述】:

我正在阅读视频文件并尝试将它们保存在 train 文件夹中,但我看不到任何输出。我不确定这里有什么问题?

测试文件夹中未生成帧,否则会引发任何错误。谁能告诉我怎么了?

我正在使用 collab 来运行此代码。

Inside this **test['video_name']**

0   ../content/drive/MyDrive/Second_model/data/noncrash/event_frame_80.mp4
1   ../content/drive/MyDrive/Second_model/data/noncrash/event_frame_98.mp4
2   ../content/drive/MyDrive/Second_model/data/crash/event_frame_117.mp4
3   ../content/drive/MyDrive/Second_model/data/noncrash/event_frame_65.mp4

存储训练视频中的帧

for i in tqdm(range(test.shape[0])):
    count = 0
    videoFile = test['video_name'][i]
    cap = cv2.VideoCapture(' '+videoFile.split(' ')[0].split('/')[6])   # capturing the video from the given path
    frameRate = cap.get(10) #frame rate
    x=1
    while(cap.isOpened()):
        frameId = cap.get(1) #current frame number
        ret, frame = cap.read()
        if (ret != True):
            break
        if (frameId % math.floor(frameRate) == 0):
            # storing the frames in a new folder named train_1
            filename ='/content/drive/MyDrive/Second_model/test_1' + videoFile.split('/')[6].split(' ')[0] +"_frame%d.jpg" % count;count+=1
            cv2.imwrite(filename, frame)
    cap.release()
    

输出:

    100%|██████████| 4/4 [00:00<00:00, 2412.78it/s]

【问题讨论】:

    标签: python-3.x google-colaboratory opencv3.0 opencv-python


    【解决方案1】:

    将opencv升级到4.5..我希望它能解决你的问题,因为它也对我有用。

    Can't read a video file using Videocapture() on android

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-05-26
      • 2012-05-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-04
      相关资源
      最近更新 更多