如何使用 cv2 使用 python3 提高图像播放速度
How do I increase speed of playback of images using python3 using 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()
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))
这是正确的代码
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()
我用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()
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))
这是正确的代码
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()