python 图像拼接
import cv2 import math import os # 文件夹所有图片 path = "Images/ROIRun" images = [] for filename in os.listdir(path): # listdir的参数是文件夹的路径 filenames = path + '\\' + filename # print(filenames) img_orig = cv2.imread(filenames, 1) print(filenames) if img_orig is None: print("Warning: No Pictures") else: images.append(img_orig) # 初始化OpenCV的图像sticher对象,然后执行图像拼接 print("[INFO] stitching images.........................") # stitcher = cv2.createStitcher() if imutils.is_cv3() else cv2.Stitcher_create() stitcher = cv2.Stitcher_create() (status, stitched) = stitcher.stitch(images) # print(status, stitched) # 如果状态为“0”,则OpenCV成功执行图像拼接 # if the status is '0', then OpenCV successfully performed image stitching if status == 0: # write the output stitched image to disk cv2.imwrite("Images/stitch.jpg", stitched) # display the output stitched image to our screen cv2.imshow("Stitched", stitched) cv2.waitKey(0) # otherwise the stitching failed, likely due to not enough keypoints) being detected else: print("[INFO] image stitching failed ({})".format(status))