opencv图像转视频-左右拼接图像

2024-05-08 21:46:16
/
0 点赞
/
225 阅读
2024-05-08

opencv图像转视频

import os, json, glob
from PIL import Image
import cv2
import numpy as np

def img2video(src_path, outputname="video.avi"):
    file_list = [x for x in glob.glob(os.path.join(src_path, "*"))]
    file_list.sort()

    img_src = Image.open(file_list[0])
    fourcc = cv2.VideoWriter_fourcc(*'XVID')
    videoWriter = cv2.VideoWriter(outputname, fourcc, 30, (img_src.width, img_src.height))

    for filename in file_list:
        img = cv2.imread(filename)
        videoWriter.write(img)

    videoWriter.release()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

左右拼接图像转视频

如果要左右拼接图像,并转为视频,可以使用如下代码片段

from PIL import Image

a_img = Image.open(filename)
b_img = Image.open(dstfile)

dst = Image.new('RGB', (a_img.width * 2, a_img.height))
dst.paste(a_img, (0, 0))
dst.paste(b_img, (a_img.width, 0))
videoWriter.write(cv2.cvtColor(np.array(dst), cv2.COLOR_RGB2BGR))
1
2
3
4
5
6
7
8
9
版权属于:

那棵树看起来生气了

本文链接:

https://dengyb.com/archives/95.html(转载时请注明本文出处及文章链接)

那棵树看起来生气了
参差荇菜,左右流之。窈窕淑女,寤寐求之。
138 文章数
13043 浏览量