python图形缝隙填充_Python,如何缝合图像哪些重叠区域?
我试着把有重叠区域的图像缝合在一起。
对图像进行排序,每个图像都有与前一个图像重叠的区域。例如:
问题是否来自右侧黑色的第5张图像?不知道为什么要加黑,以及如何避免。在
有人知道我如何修复代码,使其在添加越来越多的图像时不会扭曲图像?欢迎使用更好的代码示例。在
~~~~~~~编辑~~~~~~~
正如丹在评论中指出的那样,我在工作中使用了错误的工具(warpPerspective)。我真正要找的是找到两幅图像中匹配的关键点的方法,将其转换为每个图像中正确的Y,这样我就可以剪切图像,然后相应地缝合它们。在
所以现在的问题可能有点简单,如何获得匹配的关键点并将其转换为Y坐标。在
请忽略代码,因为它只是我开始的一个例子,在这一点上它只是误导。在
下面的代码示例输入一个目录路径,该目录包含图像[“0.png”,“1.png”,“2.png”,“3.png”]from PIL import Image
import numpy as np
import imutils
import cv2
# from panorama import Stitcher
import argparse
import imutils
import cv2
class Stitcher:
def __init__(self):
# determine if we are using OpenCV v3.X
self.isv3 = imutils.is_cv3()
def stitch(self, images, ratio=0.75, reprojThresh=4.0,
showMatches=False):
# unpack the images, then detect keypoints and extract
# local invariant descriptors from them
(imageB, imageA) = images
(kpsA, featuresA) = self.detectAndDescribe(imageA)
(kpsB, featuresB) = self.detectAndDescribe(imageB)
# match features between the two images
M = self.matchKeypoints(kpsA, kpsB,
featuresA, featuresB, ratio, reprojThresh)
# if the match is None, then there aren't enough matched
# keypoints to create a panorama
if M is None:
return None
# otherwise, apply a perspective warp to stitch the images
# together
(matches, H, status) = M
result = cv2.warpPerspective(imageA, H,
(imageA.shape[1] + imageB.shape[1], imageA.shape[0]))
result[0:imageB.shape[0], 0:imageB.shape[1]] = imageB
# check to see if the keypoint matches should be visualized
if showMatches:
vis = self.drawMatches(imageA, imageB, kpsA, kpsB, matches,
status)
# return a tuple of the stitched image and the
# visualization
return (result, vis)
# return the stitched image
return result
def detectAndDescribe(self, image):
# convert the image to grayscale
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# check to see if we are using OpenCV 3.X
if self.isv3:
# detect and extract features from the image
descriptor = cv2.xfeatures2d.SIFT_create()
(kps, features) = descriptor.detectAndCompute(image, None)
# otherwise, we are using OpenCV 2.4.X
else:
# detect keypoints in the image
detector = cv2.FeatureDetector_create("SIFT")
kps = detector.detect(gray)
# extract features from the image
extractor = cv2.DescriptorExtractor_create("SIFT")
(kps, features) = extractor.compute(gray, kps)
# convert the keypoints from KeyPoint objects to NumPy
# arrays
kps = np.float32([kp.pt for kp in kps])
# return a tuple of keypoints and features
return (kps, features)
def matchKeypoints(self, kpsA, kpsB, featuresA, featuresB,
ratio, reprojThresh):
# compute the raw matches and initialize the list of actual
# matches
matcher = cv2.DescriptorMatcher_create("BruteForce")
rawMatches = matcher.knnMatch(featuresA, featuresB, 2)
matches = []
# loop over the raw matches
for m in rawMatches:
# ensure the distance is within a certain ratio of each
# other (i.e. Lowe's ratio test)
if len(m) == 2 and m[0].distance < m[1].distance * ratio:
matches.append((m[0].trainIdx, m[0].queryIdx))
# computing a homography requires at least 4 matches
if len(matches) > 4:
# construct the two sets of points
ptsA = np.float32([kpsA[i] for (_, i) in matches])
ptsB = np.float32([kpsB[i] for (i, _) in matches])
# compute the homography between the two sets of points
(H, status) = cv2.findHomography(ptsA, ptsB, cv2.RANSAC,
reprojThresh)
# return the matches along with the homograpy matrix
# and status of each matched point
return (matches, H, status)
# otherwise, no homograpy could be computed
return None
def drawMatches(self, imageA, imageB, kpsA, kpsB, matches, status):
# initialize the output visualization image
(hA, wA) = imageA.shape[:2]
(hB, wB) = imageB.shape[:2]
vis = np.zeros((max(hA, hB), wA + wB, 3), dtype="uint8")
vis[0:hA, 0:wA] = imageA
vis[0:hB, wA:] = imageB
# loop over the matches
for ((trainIdx, queryIdx), s) in zip(matches, status):
# only process the match if the keypoint was successfully
# matched
if s == 1:
# draw the match
ptA = (int(kpsA[queryIdx][0]), int(kpsA[queryIdx][1]))
ptB = (int(kpsB[trainIdx][0]) + wA, int(kpsB[trainIdx][1]))
cv2.line(vis, ptA, ptB, (0, 255, 0), 1)
# return the visualization
return vis
if __name__ == '__main__':
images_folder = sys.argv[1]
images = ["0.png", "1.png", "2.png", "3.png"]
imageA = cv2.imread(images_folder+images[0])
imageB = cv2.imread(images_folder+images[1])
# stitch the images together to create a panorama
stitcher = Stitcher()
(result, vis) = stitcher.stitch([imageA, imageB], showMatches=True)
count = 0
imgRGB=cv2.cvtColor(result, cv2.COLOR_BGR2RGB)
img = Image.fromarray(imgRGB)
current_stiched_image = images_folder + "lol10{}.png".format(count)
img.save(current_stiched_image)
for image in images[2:]:
count+=1
print("image: {}".format(image))
print("count: {}".format(count))
print("current_stiched_image: {}".format(current_stiched_image))
imageA1 = cv2.imread(current_stiched_image)
imageB1 = cv2.imread(images_folder + image)
(result, vis) = stitcher.stitch([imageA1, imageB1], showMatches=True)
imgRGB=cv2.cvtColor(result, cv2.COLOR_BGR2RGB)
img = Image.fromarray(imgRGB)
current_stiched_image = images_folder + "lol10{}.png".format(count)
print("new current_stiched_image: {}".format(current_stiched_image))
img.save(current_stiched_image)
python图形缝隙填充_Python,如何缝合图像哪些重叠区域?相关推荐
- python画图颜色填充_python画图的两种方法
python如何画图?这里给大家介绍两款python绘图的库:turtle和Matplotlib. 相关推荐:<python视频> 1 安装turtle Python2安装命令:pip i ...
- python画图颜色填充_Python使用Turtle图形函数画图 颜色填充!(学习笔记)
turtle:海龟先生的意思. Python老是用动物的名字! 首先要引入呀! 不引入当然是不可以用的呀! turtle.forward(100):效果图 鼠标前进100步! 后退的话,鼠标就又回来啦 ...
- linux python 图形界面开发_python在linux制作图形界面(snack)
snack是一个用于在linux制作图形界面(GUI)的模块,该模块由c编写,而且redhat的系统都自带这个模块. 1.获取模块 虽然redhat系统会自带这个模块,但是直接去import snac ...
- python 图片识别服装_Python与服装图像1
1. 相机畸变原因 解析:径向畸变(进大远小):切向畸变(透镜与成像平面不平行). 2. 单反相机 解析:单反数码相机指的是单镜头反光数码相机,即Digital(数码).Single(单独).Lens ...
- python图形绘制星空图_Python数据可视化教程:基于Plotly的动态可视化绘图
1. plotly 介绍 Plotly是一个非常著名且强大的开源数据可视化框架,它通过构建基于浏览器显示的web形式的可交互图表来展示信息,可创建多达数十种精美的图表和地图, 下面我们以jupyter ...
- python图形验证码识别_Python验证码识别:利用pytesser识别简单图形验证码
一.探讨 识别图形验证码可以说是做爬虫的必修课,涉及到计算机图形学,机器学习,机器视觉,人工智能等等高深领域-- 简单地说,计算机图形学的主要研究内容就是研究如何在计算机中表示图形.以及利用计算机进行 ...
- python 视频 灰度 伽玛_Python 图像处理实战 | 图像的灰度非线性变换之对数变换、伽马变换...
作者 | 杨秀璋 来源 | CSDN博客 责编 | 夕颜 头图 | 付费下载自视觉中国 出品 | CSDN(ID:CSDNnews) 本篇文章主要讲解非线性变换,使用自定义方法对图像进行灰度化处理,包 ...
- python如何移动图片_python之详细图像仿射变换讲解(图像平移、旋转、缩放、翻转),一文就够了,赶紧码住...
仿射变换简介 什么是放射变换 图像上的仿射变换, 其实就是图片中的一个像素点,通过某种变换,移动到另外一个地方. 从数学上来讲, 就是一个向量空间进行一次线形变换并加上平移向量, 从而变换到另外一个向 ...
- python opencv 读取图片_Python opencv 读取图像
对于 matlab 起家做数字图像处理的人来讲都非常适应matlab对图像处理的操作和思路,尤其是它可以非常方便直观的看到图像的RGB值. 由于最近在研究深度学习的计算机视觉方面的东西,于是完全自学接 ...
最新文章
- python十大标准_python对标准类型的分类
- 致远OA任意文件下载漏洞(CNVD-2020-62422)
- 连接编码器_编码器与PLC的接线
- MAC报错:-bash: mysqlbinlog : command not found
- mysql孤立锁_SQL Server解决孤立用户浅析
- asp.net 网站模板怎么用,就是16aspx上面下下来的模板,里面有个sln文件,其他全是文件夹的东西...
- 使用nginx+lua脚本读写redis缓存
- linux上的一些命令
- 常用排序算法(八)桶排序
- 博客园添加背景音乐,给你的博文加点料
- vdbench的作用_vdbench
- Linux操作系统(3.2.14find)
- 彩虹的七种颜色CMYK和RGB的值是什么
- FilterSecurityInterceptor详解
- 法国奢侈品牌VILEBREQUIN限时精品店登陆北京老佛爷百货
- [每日一氵] windows cmake 安装
- 服务器数据抓包(原来微信图片真的可以抓包看的)
- 微信开发如何屏蔽投诉按钮(附代码)
- html在ie浏览器中中文为什么是乱码
- 信号频率(Frequency),幅值(Amplitude),周期(Period),相位(Phase)所代表的含义与关系
热门文章
- Python使用re模块进行正则匹配日期和时间
- 奇瑞s61鸿蒙,数码提前曝光,奇瑞新能源 S61 将搭载华为鸿蒙车机系统
- charles都踩过哪些坑_那些年我学Java踩过的坑
- MATLAB 1\n\n
- html5 canvas 加载图片
- 【ES6】对象的拓展
- 图像分割--PixelNet: Representation of the pixels, by the pixels, and for the pixels
- 云环境上如何使用tensorboard
- 【Kaidi安装问题】install_mkl.sh报错,没有数字签名
- anaconda: import numpy报错:ImportError: DLL load failed: 找不到指定的模块。