glass_img = cv2.imread(glass_dir + glass_img_name) test_img = cv2.imread(test_dir + test_img_name) all_w = max(test_img.shape[1], glass_img.shape[1])*2 all_h = max(test_img.shape[0], glass_img.shape[0]) #save glass_img 和 test_img glass_test_img = np.zeros((all_h, all_w, 3), dtype="uint8")
left_img_xmin = int(glass_test_img.shape[1]/4 - glass_img.shape[1]/2)
left_img_ymin = int(glass_test_img.shape[0]/2 - glass_img.shape[0]/2)
left_img_xmax = int(left_img_xmin + glass_img.shape[1])
left_img_ymax = int(left_img_ymin + glass_img.shape[0])
right_img_xmin = int(glass_test_img.shape[1]/2 + (glass_test_img.shape[1]/4 - test_img.shape[1]/2))
right_img_ymin = int(glass_test_img.shape[0]/2 - test_img.shape[0]/2)
right_img_xmax = int(right_img_xmin + test_img.shape[1])
right_img_ymax = int(right_img_ymin + test_img.shape[0])
glass_test_img[left_img_ymin:left_img_ymax,left_img_xmin:left_img_xmax,:] = glass_img glass_test_img[right_img_ymin:right_img_ymax,right_img_xmin:right_img_xmax,:] = test_img cv2.imwrite('./1/'+str(num)+'_'+'0.png',glass_test_img)
长、宽不一致的两张图像,拼接一起显示,不进行resize操作