赞
踩
刚好需要写个脚本实现个小功能,把多张图片合成一张大图,用到的第三方库有numpy和opencv
- import numpy as np
- import cv2
-
-
- def merge_image(image_list, x_num=2, y_num=2):
- image_num = len(image_list)
- frame = np.zeros((720, 1080), dtype=np.uint8)
- new_image_list = []
- x_image_list = []
-
- if image_num%2 == 0:
- frame = np.zeros((720, 1080), dtype=np.uint8)
- image = cv2.imread("10005001_1618537982.jpg")
- for image in image_list:
- frame = cv2.resize(image, (1080, 720), interpolation=cv2.INTER_AREA) # 每张图片的大小可自行resize
- new_image_list.append(frame)
- for x in range(x_num):
- htich = np.hstack([i for i in new_image_list[y_num*x:y_num*(x+1)]])
- x_image_list.append(htich)
- vtich = np.vstack(x_image_list)
- else: # 在这里如果图片列表是单数的话,你可以填充一个空白图片
- pass
- return vtich
-
-
- if __name__ == "__main__":
-
- image = cv2.imread("test.jpg")
- image_list = [image,image,image,image] # 这里存放你的图片帧列表
- big_image = merge_image(image_list,2,2) # x_num为行数、y_num为列数,x与y的积为图像列表的长度
- cv2.imwrite("merge_image.jpg",big_image)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。