您当前的位置:首页 > IT编程 > python
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:python调用stitcher类自动实现多个图像拼接融合功能

51自学网 2021-10-30 22:43:50
  python
这篇教程python调用stitcher类自动实现多个图像拼接融合功能写得很实用,希望能帮到您。

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

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

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

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

原图(可下载)

代码(两张图片拼接)

import sysimport 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 osimport sysimport cv2import 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图像拼接融合内容请搜索51zixue.net以前的文章或继续浏览下面的相关文章希望大家以后多多支持51zixue.net!


详谈python中subprocess shell=False与shell=True的区别
Python中判断subprocess调起的shell命令是否结束
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。