[Python] Combine multiple pictures into one row/column

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) 

Insert picture description here

Note: If the cv2.imreadresult 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

Guess you like

Origin blog.csdn.net/weixin_38705903/article/details/106607568