python调用stitcher类自动实现多个图像拼接融合功能
作者:Helloworld-睖 时间:2022-11-30 05:11:40
使用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()
结果
来源:https://blog.csdn.net/qq_36623595/article/details/116018818
标签:python,图像拼接融合,stitcher类
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
基于PHP实现一个简单的在线聊天功能
2024-05-03 15:52:38
![](https://img.aspxhome.com/file/2023/2/129402_0s.png)
只截取ip前6位的asp代码
2009-05-29 18:30:00
Python超简单分析评论提取关键词制作精美词云流程
2021-07-27 22:00:41
![](https://img.aspxhome.com/file/2023/3/67833_0s.png)
基于JavaScript实现鼠标向下滑动加载div的代码
2023-08-11 16:19:22
IE地址栏显示网站图标制作方法
2007-10-13 11:08:00
记录密码的asp代码
2009-11-02 10:50:00
python实现简单爬虫功能的示例
2022-02-12 01:39:06
![](https://img.aspxhome.com/file/2023/7/133617_0s.png)
python 多线程threading程序详情
2021-03-23 10:07:34
读取input:file的路径并显示本地图片的方法
2024-04-17 10:38:30
23条科学设计你网站的方法
2008-03-23 14:12:00
利用Golang解析json数据的方法示例
2024-04-27 15:36:04
Python ndarray 数组的变形详情
2023-05-13 14:58:47
![](https://img.aspxhome.com/file/2023/9/86239_0s.png)
实现一个获取元素样式的函数getStyle
2009-02-10 10:37:00
pytorch模型部署 pth转onnx的方法
2022-07-05 03:49:04
sqlserver 数据库学习笔记
2024-01-14 21:54:33
Pytorch生成随机数Tensor的方法汇总
2022-11-03 19:39:18
分页技术原理与实现之分页的意义及方法(一)
2024-01-26 14:29:16
![](https://img.aspxhome.com/file/2023/5/83375_0s.jpg)
SQLSERVER数据库中的5173错误解决方法
2024-01-23 16:25:58
![](https://img.aspxhome.com/file/2023/6/116276_0s.jpg)
PHP addAttribute()函数讲解
2023-06-06 09:03:45
![](https://img.aspxhome.com/file/2023/2/55412_0s.png)
浅谈监听单选框radio改变事件(和layui中单选按钮改变事件)
2024-04-23 09:09:59