1 左右拼接(height要求一样)
import cv2 from google.colab.patches import cv2_imshow img_left = cv2.imread("./left.jpg") img_right = cv2.imread("./right.jpg") img = cv2.hconcat([img_left, img_right]) cv2.imwrite("merge.jpg", img)
2 垂直拼接(width要求一样)
import cv2 from google.colab.patches import cv2_imshow img_left = cv2.imread("./top.jpg") img_right = cv2.imread("./bottom.jpg") img = cv2.vconcat([img_left, img_right]) cv2.imwrite("merge.jpg", img)
3 按像素切分,左右
sp = img.shape sp_height = sp[0] sp_width = sp[1] # 左右居中切分 sp = sp[1] / 2 img_left_new = img[0:sp_height,0:sp] cv2.imwrite("left_new.jpg", img_left_new) img_right_new = img[0:sp_height,sp:sp_width] cv2.imwrite("right_new.jpg", img_right_new)