• 企业400电话
  • 微网小程序
  • AI电话机器人
  • 电商代运营
  • 全 部 栏 目

    企业400电话 网络优化推广 AI电话机器人 呼叫中心 网站建设 商标✡知产 微网小程序 电商运营 彩铃•短信 增值拓展业务
    python调用stitcher类自动实现多个图像拼接融合功能

    使用stitcher需要注意,图像太大会报错而且计算慢。

    特点和适用范围:图像需有足够重合相同特征区域。

    优点:适应部分倾斜/尺度变换和畸变情形,拼接效果好,使用简单,可以一次拼接多张图片。

    缺点:需要有足够的相同特征区域进行匹配,速度较慢(和图像大小有关)。

    原图(可下载)

    代码(两张图片拼接)

    import sys
    import cv2
     
    if __name__ == "__main__":
        img1 = cv2.imread('C:/Users/Guaguan/Desktop/img/1.jpg')    # 图片绝对路径,
        img2 = cv2.imread('C:/Users/Guaguan/Desktop/img/2.jpg')
     
        # stitcher = cv2.createStitcher(False)    # 老的OpenCV版本,用这一个
        stitcher = cv2.Stitcher.create(cv2.Stitcher_PANORAMA)  # 我的是OpenCV4
     
        (status, pano) = stitcher.stitch((img1, img2))
        if status != cv2.Stitcher_OK:
            print("不能拼接图片, error code = %d" % status)
            sys.exit(-1)
        print("拼接成功.")
        cv2.imshow('pano', pano)
        # cv2.imwrite("pano.jpg", pano)
        cv2.waitKey(0)

    拼接结果

    原图

    代码(多个图像自动拼接)

    import os
    import sys
    import cv2
    import win32ui
     
     
    # ? python基于Stitcher图像拼接
     
     
    def imgstitcher(imgs):  # 传入图像数据 列表[] 实现图像拼接
        stitcher = cv2.Stitcher.create(cv2.Stitcher_PANORAMA)
        _result, pano = stitcher.stitch(imgs)
     
        if _result != cv2.Stitcher_OK:
            print("不能拼接图片, error code = %d" % _result)
            sys.exit(-1)
     
        output = 'result' + '.png'
        cv2.imwrite(output, pano)
        print("拼接成功. %s 已保存!" % output)
     
     
    if __name__ == "__main__":
        # imgPath为图片所在的文件夹相对路径
        imgPath = 'C:/Users/Guaguan/Desktop/img'
        
        imgList = os.listdir(imgPath)
        imgs = []
        for imgName in imgList:
            pathImg = os.path.join(imgPath, imgName)
            img = cv2.imread(pathImg)
            if img is None:
                print("图片不能读取:" + imgName)
                sys.exit(-1)
            imgs.append(img)
     
        imgstitcher(imgs)    # 拼接
     
        cv2.waitKey(0)
        cv2.destroyAllWindows()

    结果

    到此这篇关于python调用stitcher类自动实现多个图像拼接融合的文章就介绍到这了,更多相关python图像拼接融合内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

    您可能感兴趣的文章:
    • python 图像增强算法实现详解
    • python 基于opencv实现图像增强
    • 用Python给图像算法做个简单应用界面
    • python+opencv图像分割实现分割不规则ROI区域方法汇总
    • python-opencv实现视频指定帧数间隔图像的保存功能
    • Python深度学习之图像标签标注软件labelme详解
    • python使用matplotlib显示图像失真的解决方案
    • python实现求纯色彩图像的边框
    • python数字图像处理之估计噪声参数
    • Python深度学习之使用Albumentations对图像做增强
    上一篇:详谈python中subprocess shell=False与shell=True的区别
    下一篇:Python中判断subprocess调起的shell命令是否结束
  • 相关文章
  • 

    © 2016-2020 巨人网络通讯 版权所有

    《增值电信业务经营许可证》 苏ICP备15040257号-8

    python调用stitcher类自动实现多个图像拼接融合功能 python,调用,stitcher,类,自动,