stitcher类实现多图自动拼接

 效果展示

第一组: 

    

 第二组: 

    

第三组: 

 

第四组: 

      

运行代码



import os
import sys
import cv2
import numpy as np
  
 
def Stitch(imgs,savePath):  
    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 = os.path.join(savePath,stitch.jpg)
    cv2.imencode('.jpg',pano)[1].tofile(output)
    print("拼接成功)
 
 
if __name__ == "__main__":
    # 待拼接图片路径
    imgPath = r'xxxx/imgs'
    #拼好图片保存路径
    savePath=r'xxxx/imgs'
    imgList = os.listdir(imgPath)
    imgs = []
    for imgName in imgList:
        pathImg = os.path.join(imgPath, imgName)
        img=cv2.imdecode(np.fromfile(pathImg,dtype=np.uint8),flags=cv2.IMREAD_COLOR)
        imgs.append(img)    
    Stitch(imgs,savePath) 
    cv2.waitKey(0)
    cv2.destroyAllWindows()

相关推荐

  1. LabVIEW实现张图像拼接

    2024-03-31 17:36:06       27 阅读
  2. GDB调试技巧实战--自动化画出关系

    2024-03-31 17:36:06       65 阅读
  3. 拼接sql字符串工具

    2024-03-31 17:36:06       26 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-31 17:36:06       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-31 17:36:06       106 阅读
  3. 在Django里面运行非项目文件

    2024-03-31 17:36:06       87 阅读
  4. Python语言-面向对象

    2024-03-31 17:36:06       96 阅读

热门阅读

  1. flink: 从pulsar中读取数据

    2024-03-31 17:36:06       38 阅读
  2. LLM-在CPU环境下如何运行ChatGLM-6B

    2024-03-31 17:36:06       45 阅读
  3. npm常用命令技巧

    2024-03-31 17:36:06       37 阅读
  4. 封装Redis工具类

    2024-03-31 17:36:06       42 阅读
  5. @RequestMapping和@GetMapping的区别

    2024-03-31 17:36:06       37 阅读
  6. 29. 两数相除 —— LeetCode (python)

    2024-03-31 17:36:06       39 阅读
  7. LeetCode刷题记录——day9

    2024-03-31 17:36:06       37 阅读