简体   繁体   English

如何使用 cv2 使用 python3 提高图像播放速度

[英]How do I increase speed of playback of images using python3 using cv2

I have used cv2 to combine a folder of images into a video using cv2 but the speed in which the video plays is too slow is there a way to increase the speed?我已经使用cv2将一个图像文件夹组合成一个使用cv2的视频,但是视频播放的速度太慢了有没有办法提高速度?


import cv2
import os

image_folder = 'd:/deep/data'
video_name = 'video.avi'

images = [img for img in os.listdir(image_folder) if img.endswith(".jpg")]
frame = cv2.imread(os.path.join(image_folder, images[0]))
height, width, layers = frame.shape

video = cv2.VideoWriter(video_name, 0, 1, (width,height))

for image in images:
    video.write(cv2.imread(os.path.join(image_folder, image)))

cv2.destroyAllWindows()
video.release()

to set fps i tried this peice of code and it still dint work设置 fps 我尝试了这段代码,但它仍然有效

import cv2
import os
import numpy as np

image_folder = 'd:/deep/data'
video_name = 'video.avi'
fps=100
images = [img for img in os.listdir(image_folder) if img.endswith(".jpg")]
frame = cv2.imread(os.path.join(image_folder, images[0]))
height, width, layers = frame.shape

video = cv2.VideoWriter(video_name, 0, 1, (width,height),fps)



for image in images:
    video.write(cv2.imread(os.path.join(image_folder, image)))


cv2.destroyAllWindows()
video.release()
cv2.VideoWriter([filename, fourcc, fps, frameSize[, isColor]]) → <VideoWriter object>

Check documentation and set fps.检查文档并设置 fps。 your current framerate is 1 fps .您当前的帧率为 1 fps 。

Edit :编辑 :

Should be something like this :应该是这样的:

fourcc = cv2.VideoWriter_fourcc(*'DIVX')  # codec for windows (supported by your device?)
fps = 25.0   # adjust the framerate here
cv2.ViewoWriter(video_name, fourcc, fps , (width,height))

this is the right code这是正确的代码

import cv2
import os
import numpy as np

image_folder = 'd:/deep/data'
video_name = 'video.avi'

images = [img for img in os.listdir(image_folder) if img.endswith(".jpg")]
frame = cv2.imread(os.path.join(image_folder, images[0]))
height, width, layers = frame.shape
fourcc = cv2.VideoWriter_fourcc(*'XVID')
video = cv2.VideoWriter(video_name, fourcc,15.0, (width,height))



for image in images:
    video.write(cv2.imread(os.path.join(image_folder, image)))


cv2.destroyAllWindows()
video.release()


声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM