python将两张图片拼在一起并加上描述

from hashlib import new
from importlib.resources import path
from os import listdir, mkdir
import cv2,os,glob
import numpy as np
from tqdm import tqdm
from colorama import Fore


save_path = ""

path1 = ''
path2 = ''


if not os.path.exists((save_path)):
    os.mkdir(save_path)
else:
    print('文件夹已经存在')
    exit()

for i in tqdm(glob.glob(rf'{path1}\\*.jpg'),bar_format ='{l_bar}%s{bar}%s{r_bar}' % (Fore.BLUE,Fore.RESET)):

    name = i.split('\\')[-1]
    img1 = cv2.imread(i)
    img2 = cv2.imread(f'{path2}\\{name}')

    cv2.putText(img1,txt,(10,50), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
    cv2.putText(img2,txt,(10,50), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
   
    #横向连接
    image = np.hstack([img1,img2])

    # image = cv2.resize(image,(2784,1000))
    #cv2.imshow("",image)
    #cv2.waitKey()
    cv2.imwrite(save_path+'\\'f'{name}',image)






你可能感兴趣的:(opencv,python)