基于深度学习Superpoint 的Python图像全景拼接

参考
https://github.com/kushalvyas/Python-Multiple-Image-Stitching
https://github.com/MagicLeapResearch/SuperPointPretrainedNetwork
https://github.com/syinari0123/SuperPoint-VO
用superpoint方法代替surf提取图像特征,进行Python版本的图像拼接。
匹配效果很好,只是python没有图像拼接的需要的光束平差法,融合,曝光补偿模块。而这些在C++早已集成好了,似乎没人用python造轮子了。因此,Python版本图像拼接效果并不好,本博客只是学习记录。
**

源代码及数据链接https://download.csdn.net/download/qq_33591712/11638762

https://download.csdn.net/download/qq_33591712/11592396

**
改动后的matchers.py如下:

import cv2
import numpy as np 
from sp_extractor import SuperPointFrontend
class matchers:
	def __init__(self):
		self.surf = cv2.xfeatures2d.SURF_create()
                self.detector = SuperPointFrontend(weights_path="superpoint_v1.pth",
                                           nms_dist=4,
                                           conf_thresh=0.015,
                                           nn_thresh=0.7,
                                           cuda=True)
		FLANN_INDEX_KDTREE = 0
		index_params = dict(algorithm=0, trees=5)
		search_params = dict(checks=50)
		self.flann = cv2.FlannBasedMatcher(index_params, search_params)

	def match(self, i1, i2, direction=None):
		imageSet1 = self.getSURFFeatures(i1)
		imageSet2 = self.getSURFFeatures(i2)
		print "Direction : ", direction
		
                matches = self.flann.knnMatch(
			np.asarray(imageSet2['des'],np.float32),
			np.asarray(imageSet1['des'],np.float32),
			k=2
			)
		good = []
		for i , (m, n) in enumerate(matches):
			if m.distance < 0.7*n.distance:
				good.append((m.trainIdx, m.queryIdx))

		if len(good) > 4:
			pointsCurrent = imageSet2['kp']
			pointsPrevious = imageSet1['kp']

			matchedPointsCurrent = np.float32(
				[pointsCurrent[i] for (__, i) in good]
			)
			matchedPointsPrev = np.float32(
				[pointsPrevious[i] for (i, __) in good]
				)

			H, s = cv2.findHomography(matchedPointsCurrent, matchedPointsPrev, cv2.RANSAC, 4)
			return H
		return None

	def getSURFFeatures(self, im):
		gray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
                pts, desc, heatmap = self.detector.run(gray)
		#kp, des = self.surf.detectAndCompute(gray, None)

  • 10
    点赞
  • 46
    收藏
    觉得还不错? 一键收藏
  • 14
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 14
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值