cv2拼接图片

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/github_39611196/article/details/83340561

本篇文章介绍使用cv2对图片进行拼接,主要使用到cv2.createStitcher(try_use_gpu=None)方法,该方法里的参数try_use_gpu为是否尝试使用GPU进行图片拼接。

下面是示例代码:

import cv2
import os
import numpy as np

try_use_gpu =False
imgs = []
result_name = 'result.jpg'

pic_dir = 'pics/'
# 遍历文件夹读取图片
for root, dirs, files in os.walk(pic_dir):
    for file in files:
        # print(os.path.join(root, file))
        imgs.append(cv2.imread(os.path.join(root, file)))


# print(imgs)
# 图片拼接
stitcher = cv2.createStitcher(try_use_gpu=try_use_gpu)
retavol, pano = stitcher.stitch(imgs)
result = cv2.resize(pano, (int(pano.shape[1]/2), int(pano.shape[0]/2)))
# 显示拼接结果
cv2.imshow("result", result)
cv2.waitKey(0)

测试图片:

1.jpg

2.jpg

3.jpg

测试结果:

扫描二维码关注公众号,回复: 3840970 查看本文章

猜你喜欢

转载自blog.csdn.net/github_39611196/article/details/83340561
今日推荐