import os import cv2 import numpy as np Adir = './trainA/' Bdir = './trainB/' ABdir = './datasets/train/' num=0 for fi in os.listdir(Adir): im_A = cv2.imread(Adir+fi) # python2: cv2.CV_LOAD_IMAGE_COLOR; python3: cv2.IMREAD_COLOR im_B = cv2.imread(Bdir+'0'+fi[1:]) # python2: cv2.CV_LOAD_IMAGE_COLOR; python3: cv2.IMREAD_COLOR im_AB = np.concatenate([im_A, im_B], 1) cv2.imwrite(ABdir+str(num)+'.jpg', im_AB) num = num + 1 print (num)