重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
本篇文章为大家展示了怎么在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拼接图像,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注创新互联行业资讯频道。