OpenCV自带了图像拼接算法stitch,而且效果还不错。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
import glob

import cv2

st = cv2.createStitcher()
STITCH_DIR = '/home/wjmr/GitHub/opencv_extra/testdata/stitching/'
imgs = [cv2.imread(f) for f in glob.glob(STITCH_DIR + 'boat*')]
result = st.stitch(imgs)
cv2.imwrite("result.jpg", result[1])
cv2.namedWindow('demo', cv2.WINDOW_GUI_NORMAL)
cv2.imshow('demo', cv2.imread('result.jpg'))
cv2.waitKey(0)
cv2.destroyAllWindows()

使用了opencv_extra里的图片。