我已经使用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()
要设置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()
答案 0 :(得分:1)
cv2.VideoWriter([filename, fourcc, fps, frameSize[, isColor]]) → <VideoWriter object>
检查文档并设置fps。您当前的帧率为1 fps。
编辑:
应该是这样的:
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))
答案 1 :(得分:1)
这是正确的代码
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()