资源简介
可以将图像集按输入的顺序进行全景图的拼接,但未实现拼缝处理。
使用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中matplotlib库实现绘制(随机
- 复旦大学人工智能N-Queens答案
- 100个经典Python
- python操作同花顺客户端下单程序
- opemv4-0v7725.rar
- FaceClustering.zip
- python 利用OpenCV 图像黑白化
- PythonTCP编程
- 《python常见图形代码可视化大全整理
- 代码大米计数PYTHON
- 在我的世界Minecraft 中用Python搭建剑球
- python图片爬取.rar
- 人工免疫算法python
- Python scrapy爬取豆瓣电影top250
- Python员工信息管理系统
- cohesive_COH2D4 for Quad.py
- 新浪微博爬虫代码+结果
- Python-RNNoiseRNN音频噪声抑制学习
- Python-Keras实现实时语义分割的深层神
- Python-通过百度语音API实现文本转语音
- Python-Binance虚拟货币交易机器人
- Python-2019年百度的三元组抽取比赛一个
- Python-微信公众号历史文章爬取api
- Python-手势识别使用在TensorFlow中卷积神
- Python-python识别字符验证码
- Python-利用pandas将excel中数据抽取以三
- Python-基于pygame和tkinter本地音乐播放器
- HTMLTestRunner.py python3.6
- Python+Django+MySQL实现基于Web版的增删改
- python 使用while循环输出*组成的菱形
评论
共有 条评论