Python OpenCV将多个帧转换为视频
我正在尝试使用opencv将多个帧合并到一个视频中。 这可能吗 我的程序可以保存多个图像,但不能将它们组合成一个视频Python OpenCV将多个帧转换为视频,python,opencv,Python,Opencv,我正在尝试使用opencv将多个帧合并到一个视频中。 这可能吗 我的程序可以保存多个图像,但不能将它们组合成一个视频 import time import cv2 import mss import numpy frame = 1 with mss.mss() as sct: # Part of the screen to capture monitor = {'top': 40, 'left': 0, 'width': 800, 'height': 640} whi
import time
import cv2
import mss
import numpy
frame = 1
with mss.mss() as sct:
# Part of the screen to capture
monitor = {'top': 40, 'left': 0, 'width': 800, 'height': 640}
while 'Screen capturing':
last_time = time.time()
# Get raw pixels from the screen, save it to a Numpy array
img = numpy.array(sct.grab(monitor))
# Display the picture
frame += 1
name = 'C:/Users/samih/SublimePython/Game_Play_Recorder/Imgs/img' + str(frame) + '.png'
cv2.imwrite(name, img)
if cv2.waitKey(25) & 0xFF == ord('q'):
cv2.destroyAllWindows()
break
它应该能够将所有这些图像转换为一个视频。您要查找的是。请参见上的官方教程,在“保存视频”下
import time
import cv2
import mss
import numpy
frame = 1
with mss.mss() as sct:
# Part of the screen to capture
monitor = {'top': 40, 'left': 0, 'width': 800, 'height': 640}
while 'Screen capturing':
last_time = time.time()
# Get raw pixels from the screen, save it to a Numpy array
img = numpy.array(sct.grab(monitor))
# Display the picture
frame += 1
name = 'C:/Users/samih/SublimePython/Game_Play_Recorder/Imgs/img' + str(frame) + '.png'
cv2.imwrite(name, img)
if cv2.waitKey(25) & 0xFF == ord('q'):
cv2.destroyAllWindows()
break
在编写/保存视频时查看此项是的,这是可能的。CV具有在视频文件中写入帧的功能。视频必须使用与帧相同的大小、宽度、高度,或者在保存前必须调整帧的大小。但是使用会更容易,比如ffmpeg*.png output.mv4