资源简介
可以将图像集按输入的顺序进行全景图的拼接,但未实现拼缝处理。
使用python语言编写。
代码片段和文件信息
import numpy as np
import cv2
import time
def getSURFFeatures(image):
gray = cv2.cvtColor(image cv2.COLOR_BGR2GRAY)
surf = cv2.xfeatures2d.SURF_create()
kp des = surf.detectAndCompute(gray None)
return kp des
def match(image1 image2 direction=None):
print(“Direction : “ direction)
kp1 des1 = getSURFFeatures(image1)
kp2 des2 = getSURFFeatures(image2)
FLANN_INDEX_KDTREE = 0
index_params = dict(algorithm=FLANN_INDEX_KDTREE trees=5)
search_params = dict(checks=50)
flann = cv2.FlannbasedMatcher(index_params search_params)
matches = flann.knnMatch(des2 des1 k=2)
good = []
for m n in matches:
if m.distance < 0.7 * n.distance:
good.append(m)
if len(good) > 10:
src_pts = np.float32([kp2[m.queryIdx].pt for m in good]).reshape(-1 1 2)
dst_pts = np.float32([kp1[m.trainIdx].pt for m in good]).reshape(-1 1 2)
H s = cv2.findHomography(src_pts dst_pts cv2.RANSAC 4)
return H
return None
def getPointsCoordinate(image H):
[x1 y1 z1] = np.dot(H np.array([0 0 1])) # [0 0]
x1 = x1 / z1
y1 = y1 / z1
[x2 y2 z2] = np.dot(H np.array([image.shape[1] 0 1])) # [width 0]
x2 = x2 / z2
y2 = y2 / z2
[x3 y3 z3] = np.dot(H np.array([0 image.shape[0] 1])) # [0 height]
x3 = x3 / z3
y3 = y3 / z3
[x4 y4 z4] = np.dot(H np.array([image.shape[1] image.shape[0] 1])) # [width height]
x4 = x4 / z4
y4 = y4 / z4
return x1 x2 x3 x4 y1 y2 y3 y4
def calculate_newSize(image1 image2 H): # 变换图,不变图
x1 x2 x3 x4 y1 y2 y3 y4 = getPointsCoordinate(image1 H)
Xmin = min([x1 x2 x3 x4 0])
Xmax = max([x1 x2 x3 x4 image2.shape[1]])
Xsize = int(Xmax - Xmin)
print(Xmin Xmax Xsize)
Ymin = min([y1 y2 y3 y4 0])
Ymax = max([y1 y2 y3 y4 image2.shape[0]])
Ysize = int(Ymax - Ymin)
print(Ymin Ymax Ysize)
size = (Xsize Ysize)
offsetx = -int(Xmin)
offsety = -int(Ymin)
print(x1 x2 x3 x4 y1 y2 y3 y4)
print(offsetx offsety)
pts1 = np.float32([[0 0] [image1.shape[1] 0] [0 image1.shape[0]] [image1.shape[1] image1.shape[0]]])
pts2 = np.float32([[x1+offsetx y1+offsety] [x2+offsetx y2+offsety] [x3+offsetx y3+offsety] [x4+offsetx y4+offsety]])
M = cv2.getPerspectiveTransform(pts1 pts2)
print(‘M:‘ M)
r
相关资源
- 二级考试python试题12套(包括选择题和
- pywin32_python3.6_64位
- python+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
- python疫情卡UN管控
- python 连连看小游戏源码
- 基于PyQt5的视频播放器设计
- 一个简单的python爬虫
- csv文件行列转换python实现代码
- Python操作Mysql教程手册
- Python Machine Learning Case Studies
- python获取硬件信息
评论
共有 条评论