python調用stitcher類進行圖像拼接融合

        BROWN大神03'ICCV和07'IJCV的AutoStitch AutoStitch對於圖像拼接效果很好,已經非常成熟,各路拼接軟件和應用都紛紛落地,Opencv中也實現了該算法。python調用測試如下:

from __future__ import print_function 
import cv2 as cv 
import numpy as np 
import argparse 
import sys 

output = 'result3.jpg'
txtpath = 'txtlists/files3.txt'   #文檔中保存圖像的存儲路徑
fp = open(txtpath, 'r')
filenames = [each.rstrip('\r\n') for each in  fp.readlines()]
print(filenames)

imgs = [] 
for img_name in filenames: 
    img = cv.imread(img_name) 
    if img is None: 
        print("can't read image " + img_name) 
        sys.exit(-1) 
    imgs.append(img) 

stitcher = cv.createStitcher(cv.Stitcher_PANORAMA)  #cv.Stitcher_SCANS
status, pano = stitcher.stitch(imgs) 
if status != cv.Stitcher_OK: 
    print("Can't stitch images, error code = %d" % status) 
    sys.exit(-1) 
cv.imwrite(output, pano); 
print("stitching completed successfully. %s saved!" % output)

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章