• 大小: 1.12MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-10-26
  • 语言: Python
  • 标签: 图像拼接  Python  

资源简介

Python3实现的多图拼接,需要OpenCV,亲测可用,有代码有图,在cmd上跑

资源截图

代码片段和文件信息

import cv2
import numpy as np 

class matchers:
def __init__(self):
self.surf = cv2.xfeatures2d.SURF_create()
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(
imageSet2[‘des‘]
imageSet1[‘des‘]
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].pt for (__ i) in good]

matchedPointsPrev = np.float32(
[pointsPrevious[i].pt 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)
kp des = self.surf.detectAndCompute(gray None)
return {‘kp‘:kp ‘des‘:des}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2016-11-12 06:14  Python-Multiple-Image-Stitching-master\
     目录           0  2016-11-12 06:14  Python-Multiple-Image-Stitching-master\code\
     文件        1194  2016-11-12 06:14  Python-Multiple-Image-Stitching-master\code\matchers.py
     文件        4147  2016-11-12 06:14  Python-Multiple-Image-Stitching-master\code\pano.py
     目录           0  2016-11-12 06:14  Python-Multiple-Image-Stitching-master\code\txtlists\
     文件          84  2016-11-12 06:14  Python-Multiple-Image-Stitching-master\code\txtlists\files1.txt
     文件          47  2016-11-12 06:14  Python-Multiple-Image-Stitching-master\code\txtlists\files2.txt
     文件          99  2016-11-12 06:14  Python-Multiple-Image-Stitching-master\code\txtlists\files2.txt~
     文件          59  2016-11-12 06:14  Python-Multiple-Image-Stitching-master\code\txtlists\files3.txt
     目录           0  2016-11-12 06:14  Python-Multiple-Image-Stitching-master\images\
     文件       47382  2016-11-12 06:14  Python-Multiple-Image-Stitching-master\images\1.jpg
     文件       78825  2016-11-12 06:14  Python-Multiple-Image-Stitching-master\images\1Hill.JPG
     文件       44167  2016-11-12 06:14  Python-Multiple-Image-Stitching-master\images\2.jpg
     文件       79971  2016-11-12 06:14  Python-Multiple-Image-Stitching-master\images\2Hill.JPG
     文件       40361  2016-11-12 06:14  Python-Multiple-Image-Stitching-master\images\3.jpg
     文件       79327  2016-11-12 06:14  Python-Multiple-Image-Stitching-master\images\3Hill.JPG
     文件       34014  2016-11-12 06:14  Python-Multiple-Image-Stitching-master\images\S1.jpg
     文件       38259  2016-11-12 06:14  Python-Multiple-Image-Stitching-master\images\S2.jpg
     文件       44614  2016-11-12 06:14  Python-Multiple-Image-Stitching-master\images\S3.jpg
     文件       41734  2016-11-12 06:14  Python-Multiple-Image-Stitching-master\images\S5.jpg
     文件       38498  2016-11-12 06:14  Python-Multiple-Image-Stitching-master\images\S6.jpg
     文件      100126  2016-11-12 06:14  Python-Multiple-Image-Stitching-master\images\wd1.jpg
     文件       97652  2016-11-12 06:14  Python-Multiple-Image-Stitching-master\images\wd2.jpg
     文件       15398  2016-11-12 06:14  Python-Multiple-Image-Stitching-master\images\wd3.jpg
     文件       58982  2016-11-12 06:14  Python-Multiple-Image-Stitching-master\lunchroom_ultimate.jpg
     文件        2006  2016-11-12 06:14  Python-Multiple-Image-Stitching-master\README.md
     文件      180331  2016-11-12 06:14  Python-Multiple-Image-Stitching-master\test.jpg
     文件       58838  2016-11-12 06:14  Python-Multiple-Image-Stitching-master\test1.jpg
     文件      116574  2016-11-12 06:14  Python-Multiple-Image-Stitching-master\test12.jpg
     文件       45634  2016-11-12 06:14  Python-Multiple-Image-Stitching-master\wd123.jpg

评论

共有 条评论