【问题标题】:Get Frame at half of video with opencv使用opencv在视频的一半处获取帧
【发布时间】:2021-09-23 15:06:13
【问题描述】:

有没有办法从opencv中获取帧,但大约是视频的一半(例如,如果视频是10分钟,我想在5:00分钟保存一帧)。我已经在互联网上看到了一些东西,但每个人都只是逐帧进行。谢谢你的帮助

【问题讨论】:

    标签: python opencv opencv3.0 opencv-python


    【解决方案1】:

    我相信您正在寻找这样的东西:

    import cv2
    
    # Read the Video (Change the filename as per your file)
    cap = cv2.VideoCapture("video.mp4")
    
    # Get the total number of frames
    length = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
    half_point = length//2 # Approximately half if number of frames are odd
    
    # Set the reader to the given frame number (half_point)
    cap.set(cv2.CAP_PROP_POS_FRAMES, half_point)
    
    # Read the frame
    ret, frame = cap.read()
    
    # Release the file pointer
    cap.release()
    

    你应该得到变量frame中的半点帧。

    【讨论】:

      猜你喜欢
      • 2015-08-28
      • 2012-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-11
      • 2013-11-08
      • 2012-05-14
      • 2016-02-13
      相关资源
      最近更新 更多