【问题标题】:Frame Extraction at Fixed FPS Value固定 FPS 值的帧提取
【发布时间】:2021-11-09 15:44:57
【问题描述】:

在使用 OpenCV 从视频中提取帧时,我如何设置将进行帧提取的特定值?

我已经看到许多可用的图像提取示例代码,但它们没有显示任何帧速率选项。

【问题讨论】:

    标签: python opencv


    【解决方案1】:

    帧提取的方法有很多种,一种是使用ffmg进行帧提取。

    另外,您可以尝试此代码,但我们不能使用您在尝试不同值时会理解的任何随机值。 根据您的系统更改目录

    import math
    count = 0
    videoFile = "train/train.mp4"
    cap = cv2.VideoCapture(videoFile)  
    frameRate = cap.get(5) #frame rate
    x=1
    while(cap.isOpened()):
        frameId = cap.get(1) 
        ret, frame = cap.read()
        if (ret != True):
            break
        else (frameId % math.floor(frameRate) == 0):
            filename ="train/frame2/frame%d.jpg" % count;count+=1
            cv2.imwrite(filename, frame)
    cap.release()
    print ("Done!")
    

    【讨论】:

    • 对于 ffmg 我们是否需要使用任何软件之类的东西?
    • 我对 ffmg 不太了解,通过我的一个项目我了解了 ffmg,在处理它时要求进行一些安装,我认为我们需要先配置它。
    • 这里也一样,它开始给出错误并需要一些安装。谢谢?
    猜你喜欢
    • 2021-09-15
    • 1970-01-01
    • 1970-01-01
    • 2021-12-31
    • 1970-01-01
    • 1970-01-01
    • 2014-04-13
    • 2013-09-18
    • 1970-01-01
    相关资源
    最近更新 更多