import os
import cv2
path = 'E:\\'
filelist = os.listdir(path)
fourcc = cv2.VideoWriter_fourcc(*'XVID')
fps = 5
size = (512, 512)
video = cv2.VideoWriter('E:\\test.avi', fourcc, fps, size)
# for item in filelist:
# if item.endswith('.png'):
# item = path + item
# img = cv2.imread(item)
# video.write(img)
for i in range(1000):
item = path +'test' + str(i) + '.png'
img = cv2.imread(item)
font = cv2.FONT_HERSHEY_DUPLEX # 设置字体
# 图片对象、 文本、 位置像素、 字体、字体大小、 颜色、 字体粗细
imgzi = cv2.putText(img, "test"+str(i), (50, 50), font, 1, (0, 0, 0), 2)
video.write(img)
video.release()
cv2.destroyAllWindows()
注:
如果图片太小,可能无法正常运行,需要放大图片
img = cv2.resize(img, None, fx=2, fy=2, interpolation=cv2.INTER_CUBIC)