从视频保存图像帧而不会损失分辨率和质量

问题描述

我想保存从视频中提取的图像,而又不丢失任何信息,分辨率和质量。我已经使用OpenCV保存了四种格式png,bmp,jpg,tif代码如下

    file = "video.MP4"
    video = cv2.VideoCapture(file)    
    # Find OpenCV version
    (major_ver,minor_ver,subminor_ver) = (cv2.__version__).split('.')
    
    # With webcam get(CV_CAP_PROP_FPS) does not work.
    # Let's see for ourselves.
    
    if int(major_ver)  < 3 :
        fps = video.get(cv2.cv.CV_CAP_PROP_FPS)
        print ("Frames per second using video.get(cv2.cv.CV_CAP_PROP_FPS): {0}".format(fps))
    else :
        fps = video.get(cv2.CAP_PROP_FPS)
        print ("Frames per second using video.get(cv2.CAP_PROP_FPS) : {0}".format(fps))
    

    # Number of frames to capture
    num_frames = 120;
    
    
    print ("Capturing {0} frames".format(num_frames))

    # Start time
    start = time.time()
    
    data = []
    # Grab a few frames
    for i in range(0,num_frames) :
        ret,frame = video.read()
        data.append(frame)
    print("Shape",frame.shape)
    # End time
    end = time.time()

    # Time elapsed
    seconds = end - start
    print ("Time taken : {0} seconds".format(seconds))

    # Calculate frames per second
    fps  = num_frames / seconds;
    print ("Estimated frames per second : {0}".format(fps))

    for i,img in enumerate(data):
        fileName = 'Frames\img_'+ str(i) + '.tif'
        cv2.imwrite(fileName,img)
    # Release video
    video.release()

我的问题是

  1. 我应该保存哪种格式(png,tif),以免丢失视频的分辨率和质量。
  2. 仅将.tif之类的扩展名放入cv2.imwrite()会将其保存为该特定格式吗?
  3. 哪个图书馆最适合保存OpenCV,scikit-image or Pillow

任何帮助或建议将不胜感激。

致谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...