效果展示
第一组:
第二组:
第三组:
第四组:
运行代码
import os
import sys
import cv2
import numpy as npdef Stitch(imgs,savePath): stitcher = cv2.Stitcher.create(cv2.Stitcher_PANORAMA)(result, pano) = stitcher.stitch(imgs) if result != cv2.Stitcher_OK:print("不能拼接图片, error code = %d" % result)sys.exit(-1)output = os.path.join(savePath,stitch.jpg)cv2.imencode('.jpg',pano)[1].tofile(output)print("拼接成功)if __name__ == "__main__":# 待拼接图片路径imgPath = r'xxxx/imgs'#拼好图片保存路径savePath=r'xxxx/imgs'imgList = os.listdir(imgPath)imgs = []for imgName in imgList:pathImg = os.path.join(imgPath, imgName)img=cv2.imdecode(np.fromfile(pathImg,dtype=np.uint8),flags=cv2.IMREAD_COLOR)imgs.append(img) Stitch(imgs,savePath) cv2.waitKey(0)cv2.destroyAllWindows()