import cv2
import numpy as np
def concatenate_img(img_list, img_name, axis=1):
img_list = [cv2.imread(img) for img in img_list]
img = np.concatenate(([i for i in img_list]), axis=axis)
cv2.imwrite(img_name, img)
if __name__=='__main__':
img_list = [''] # 图片的本地地址
# 合并方式为合成一行,若要为一列,则axis改为0
concatenate_img(img_list, img_name='img.png', axis=1)
Note: If the cv2.imread
result is None
, it may be because your file name contains Chinese. The solution is
image = cv2.imread(image_path)
Replace with image = cv2.imdecode(np.fromfile(image_path,dtype=np.uint8),-1)
Reference: The cv2.imread() function in the opencv python interface cannot read Chinese file name files
If you want to compress pictures, refer to python opencv to modify the quality of the saved pictures