无需变形的计算机图像特征拼接问题求助
地图切片无变形拼接匹配错误问题
我在Python中搜索大量图像拼接相关内容,发现大多是针对全景图像的方案,需要通过变形、旋转来合并图像。但我要处理的是计算机生成的数字地图切片,属于二维图像,无需变形,可直接进行模板匹配,目标是拼接多张放大的地图切片生成一张完整大图。
现有实现代码
import os import numpy as np import cv2 def stitchImagesWithoutWarp(img1, img2): orb = cv2.ORB_create() kp1, des1 = orb.detectAndCompute(img1,None) kp2, des2 = orb.detectAndCompute(img2,None) bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True) matches = bf.match(des1,des2) matches = sorted(matches, key = lambda x:x.distance) good_matches = matches[:10] src_pts = np.float32([kp1[m.queryIdx].pt for m in good_matches]).reshape(-1,1,2) dst_pts = np.float32([kp2[m.trainIdx].pt for m in good_matches]).reshape(-1,1,2) start = (abs(int(dst_pts[0][0][0]-src_pts[0][0][0])), abs(int(dst_pts[0][0][1]-src_pts[0][0][1]))) h1, w1 = img1.shape[:2] h2, w2 = img2.shape[:2] vis = np.zeros((start[1]+h1,start[0]+w1,3), np.uint8) vis[start[1]:start[1]+h1, start[0]:start[0]+w1, :3] = img1 vis[:h2, :w2, :3] = img2 return vis imgList = [] for it in os.scandir("images"): imgList.append(cv2.imread(it.path)) vis = stitchImagesWithoutWarp(imgList[0],imgList[1]) for index in range(2,len(imgList)): cv2.imshow("result", vis) cv2.waitKey() vis = stitchImagesWithoutWarp(vis,imgList[index])
问题现象
- 前四张图像拼接成功,结果符合预期
- 拼接第五张图像时出现匹配错误,尽管已通过NORM_HAMMING距离筛选最优匹配
- 第五张是首个出现匹配点(变量
start)x轴为负的图像,该图像对应的匹配点坐标如下:- (7, 422)
- (786, 54)
- (394, 462)
- (-350, 383)
已尝试的解决方法
- 调整图像拼接顺序
- 尝试针对负匹配编写特殊处理代码,但担心会影响性能
- 交换拼接时的查询图与目标图顺序(调换
vis和新图像的参数位置),问题仍未解决
内容的提问来源于stack exchange,提问作者Guilherme Garcia da Rosa
相关产品推荐
相关产品推荐

