资源简介

博客连接https://blog.csdn.net/qq_33591712/article/details/84947829#comments 用superpoint方法代替surf提取图像特征,进行Python版本的图像拼接。

资源截图

代码片段和文件信息

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)
                pts=np.delete(pts2axis=0)
                desc=np.delete(desc2axis=0)
                pts=np.transpose(pts)
                desc=np.transpose(desc)
                pts=pts.tolist()
                desc=desc.tolist()
                
                return {‘kp‘:pts ‘des‘:desc}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-11-11 19:38  Python-Multiple-Image-Stitching\
     目录           0  2019-01-06 21:34  Python-Multiple-Image-Stitching\.git\
     文件          23  2018-11-11 19:22  Python-Multiple-Image-Stitching\.git\HEAD
     目录           0  2018-11-11 19:22  Python-Multiple-Image-Stitching\.git\branches\
     文件         290  2018-11-11 19:22  Python-Multiple-Image-Stitching\.git\config
     文件          73  2018-11-11 19:22  Python-Multiple-Image-Stitching\.git\description
     目录           0  2018-11-11 19:22  Python-Multiple-Image-Stitching\.git\hooks\
     文件         478  2018-11-11 19:22  Python-Multiple-Image-Stitching\.git\hooks\applypatch-msg.sample
     文件         896  2018-11-11 19:22  Python-Multiple-Image-Stitching\.git\hooks\commit-msg.sample
     文件         189  2018-11-11 19:22  Python-Multiple-Image-Stitching\.git\hooks\post-update.sample
     文件         424  2018-11-11 19:22  Python-Multiple-Image-Stitching\.git\hooks\pre-applypatch.sample
     文件        1642  2018-11-11 19:22  Python-Multiple-Image-Stitching\.git\hooks\pre-commit.sample
     文件        1348  2018-11-11 19:22  Python-Multiple-Image-Stitching\.git\hooks\pre-push.sample
     文件        4898  2018-11-11 19:22  Python-Multiple-Image-Stitching\.git\hooks\pre-rebase.sample
     文件        1239  2018-11-11 19:22  Python-Multiple-Image-Stitching\.git\hooks\prepare-commit-msg.sample
     文件        3610  2018-11-11 19:22  Python-Multiple-Image-Stitching\.git\hooks\update.sample
     文件        2248  2018-11-13 21:33  Python-Multiple-Image-Stitching\.git\index
     目录           0  2018-11-11 19:22  Python-Multiple-Image-Stitching\.git\info\
     文件         240  2018-11-11 19:22  Python-Multiple-Image-Stitching\.git\info\exclude
     目录           0  2018-11-11 19:22  Python-Multiple-Image-Stitching\.git\logs\
     文件         219  2018-11-11 19:22  Python-Multiple-Image-Stitching\.git\logs\HEAD
     目录           0  2018-11-11 19:22  Python-Multiple-Image-Stitching\.git\logs\refs\
     目录           0  2018-11-11 19:22  Python-Multiple-Image-Stitching\.git\logs\refs\heads\
     文件         219  2018-11-11 19:22  Python-Multiple-Image-Stitching\.git\logs\refs\heads\master
     目录           0  2018-11-11 19:22  Python-Multiple-Image-Stitching\.git\logs\refs\remotes\
     目录           0  2018-11-11 19:22  Python-Multiple-Image-Stitching\.git\logs\refs\remotes\origin\
     文件         219  2018-11-11 19:22  Python-Multiple-Image-Stitching\.git\logs\refs\remotes\origin\HEAD
     目录           0  2018-11-11 19:22  Python-Multiple-Image-Stitching\.git\objects\
     目录           0  2018-11-11 19:22  Python-Multiple-Image-Stitching\.git\objects\04\
     文件         116  2018-11-11 19:22  Python-Multiple-Image-Stitching\.git\objects\04\1d5c6cc9c2654fcc4aa830906d89369079b882
     目录           0  2018-11-11 19:22  Python-Multiple-Image-Stitching\.git\objects\07\
............此处省略198个文件信息

评论

共有 条评论