您好,登錄后才能下訂單哦!
本篇文章為大家展示了怎么在python中使用OpenCV拼接圖像,內容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細介紹希望你能有所收獲。
from __future__ import print_function import cv2 as cv import numpy as np import argparse import sys modes = (cv.Stitcher_PANORAMA, cv.Stitcher_SCANS) parser = argparse.ArgumentParser(description='Stitching sample.') parser.add_argument('--mode', type = int, choices = modes, default = cv.Stitcher_PANORAMA, help = 'Determines configuration of stitcher. The default is `PANORAMA` (%d), ' 'mode suitable for creating photo panoramas. Option `SCANS` (%d) is suitable ' 'for stitching materials under affine transformation, such as scans.' % modes) parser.add_argument('--output', default = 'result.jpg', help = 'Resulting image. The default is `result.jpg`.') parser.add_argument('img', nargs='+', help = 'input images') args = parser.parse_args() # read input images imgs = [] for img_name in args.img: img = cv.imread(img_name) if img is None: print("can't read image " + img_name) sys.exit(-1) imgs.append(img) stitcher = cv.Stitcher.create(args.mode) status, pano = stitcher.stitch(imgs) if status != cv.Stitcher_OK: print("Can't stitch images, error code = %d" % status) sys.exit(-1) cv.imwrite(args.output, pano); print("stitching completed successfully. %s saved!" % args.output)
上面寫了一大堆, 然鵝, 直接拿來用的話, 用下面的代碼可以了, 簡單粗暴
import numpy as np import cv2 from cv2 import Stitcher if __name__ == "__main__": img1 = cv2.imread('1.jpg') img2 = cv2.imread('2.jpg') stitcher = cv2.createStitcher(False) #stitcher = cv2.Stitcher.create(cv2.Stitcher_PANORAMA), 根據不同的OpenCV版本來調用 (_result, pano) = stitcher.stitch((img1, img2)) cv2.imshow('pano',pano) cv2.waitKey(0)
上述內容就是怎么在python中使用OpenCV拼接圖像,你們學到知識或技能了嗎?如果還想學到更多技能或者豐富自己的知識儲備,歡迎關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。