import cv2
import glob
def resize(img_array, align_mode):
_height = len(img_array[0])
_width = len(img_array[0][0])
for i in range(1, len(img_array)):
img = img_array[i]
height = len(img)
width = len(img[0])
if align_mode == 'smallest':
if height < _height:
_height = height
if width < _width:
_width = width
else:
if height > _height:
_height = height
if width > _width:
_width = width
for i in range(0, len(img_array)):
img1 = cv2.resize(img_array[i], (_width, _height), interpolation=cv2.INTER_CUBIC)
img_array[i] = img1
return img_array, (_width, _height)
def images_to_video(path):
img_array = []
for filename in glob.glob(path+'/*.png'):
img = cv2.imread(filename)
if img is None:
print(filename + " is error!")
continue
img_array.append(img)
# 图片的大小需要一致
img_array, size = resize(img_array, 'largest')
fps = 1
out = cv2.VideoWriter('/data/wwwroot/default/Data/demo.avi', cv2.VideoWriter_fourcc(*'DIVX'), fps, size)
for i in range(len(img_array)):
out.write(img_array[i])
out.release()
def main():
path = "/data/wwwroot/default/asset"
images_to_video(path)
if __name__ == "__main__":
main()
网友回复
python能写一个检测nginx rewrite高危漏洞的工具代码?
css如何给video视频进行mask遮罩?
windows如何同时允许两个用户远程桌面连接同一个电脑?
nginx升级到1.30.1导致无法启动 [emerg] SSL_CTX_new() failed怎么办?
什么是ASLR(地址随机化)?
有没有不依赖embedding向量的RAG技术?
有没有支持实时打断语音通话并后台帮你执行任何的ai模型?
开源ai大模型文件格式GGUF、MLX、Safetensors、 ONNX 有什么区别?
出海挣钱支付收款PayPal、Wise 、PingPong、Stripe如何选择?
如何实现类似google的图片隐形水印添加和识别技术?


