简体   繁体   English

Opencv4Android,拼接两个图像

[英]Opencv4Android,stitching two images

I have to stitch two images and I use openCV4Android .I read docs and some threads in about stitching images,for example: Panorama – Image Stitching in OpenCV , Homography between images using OpenCV for Android , Stitch multiple images , Error matching with ORB in Android and others.At first,it seems easy.But the result is strange!Below,you can see two images that I used for test and result: 我必须缝合两个图像,然后使用openCV4Android 。我阅读了有关缝合图像的文档和一些主题,例如: Panorama – OpenCV中的图像缝合, 使用OpenCV for Android的图像之间的同形缝合多个图像Android中与ORB的错误匹配起初看起来很简单。但是结果很奇怪!下面,您可以看到两个用于测试和结果的图像:

Here is "image1": 这是“ image1”:

在此处输入图片说明

This is "image2": 这是“ image2”:

在此处输入图片说明

You can see drawed features: 您可以看到绘制的特征:

在此处输入图片说明

And this is result of warping image1 : 这是image1扭曲的结果:

在此处输入图片说明

What I did wrong?Or it may be I did not understand good? 我做错了什么?或者可能是我听不懂?

Quick answer: 快速回答:

I would say that you don't have enough overlap between your images. 我会说您的图像之间没有足够的重叠。 If you look at your matches (what you call "drawed features"), most of them are wrong. 如果您查看匹配项(您将其称为“绘制特征”),则大多数错误。 As a first test, try to stitch two images that have, say, 80% overlap. 作为第一个测试,请尝试拼接两个具有80%重叠的图像。

More details: 更多细节:

Big picture: 大图:

When you stitch two images, you assume that there exists an affine transform (your "homography") that will project features from one image onto the other one. 拼接两个图像时,假定存在一个仿射变换(您的“单应性”),可以将要素从一个图像投影到另一个图像上。 When you know this transform, then you know the relative position of your images and you can "put them together". 当您知道此变换后,便知道图像的相对位置,可以将它们“放在一起”。 If the homography transform that you find is bad, then the stitching will be bad as well. 如果您发现的单应变换不正确,那么缝合也将不正确。

How do we find the homography transform, then? 那么,我们如何找到单应变换?

  • First of all, you detect features (with your FeatureDetector ) on both images. 首先,您可以通过FeatureDetector检测两个图像上的特征。
  • Then, you describe them (with your DescriptorExtractor ). 然后,您使用DescriptorExtractor描述它们。 Basically this creates a representation of your features, so that you can compare two features and see how similar they are. 基本上,这将创建您的要素的表示形式,以便您可以比较两个要素并查看它们之间的相似程度。
  • You match (using your DescriptorMatcher ) features from the first image to the features from the second image. 您(使用DescriptorMatcher )将第一张图像中的特征与第二张图像中的特征进行匹配。 It means that for each feature in the first image, you try to find the most similar one in the second image. 这意味着对于第一张图像中的每个功能,您都尝试在第二张图像中找到最相似的功能。 Those are your "drawed features". 这些是您的“绘制特征”。
  • From those matches, you use an algorithm called "RANSAC" to find the homography transform corresponding to your data. 从这些匹配中,您可以使用称为“ RANSAC”的算法来查找与您的数据相对应的单应性变换。 The idea is that you try to find a set of matches from all your "drawed features" that makes sense geometrically. 这个想法是,您尝试从所有“绘制的特征”中找到一组在几何上有意义的匹配项。

But why doesn't it work here? 但是为什么它在这里不起作用?

If you look at your "drawed features", you will see that only a few ones on the "Go" part of "Google" and some in the boorkmarks correspond, when the others are wrong. 如果您查看“绘制的功能”,您会看到“ Google”的“执行”部分中只有少数几个与布洛克标记中的一些相对应,而其他则有误。 It means that most of your matches are bad, and then it makes it possible to find a homography that works for this data, but that is wrong. 这意味着您的大多数匹配都不正确,然后可以找到适用于此数据的单应性,但这是错误的。

In order to have a better homography, you would need much more "good" matches. 为了获得更好的单应性,您将需要更多的“好”匹配。 Consequently, you probably need to have more overlap between your images. 因此,您可能需要在图像之间有更多的重叠。

NOTE: try your code with the images used in " Panorama – Image Stitching in OpenCV " 注意:尝试将代码与“ 全景– OpenCV中的图像拼接 ”中使用的图像一起使用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM