简体   繁体   中英

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:

Here is "image1":

在此处输入图片说明

This is "image2":

在此处输入图片说明

You can see drawed features:

在此处输入图片说明

And this is result of warping 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.

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.
  • Then, you describe them (with your 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. 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. 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. 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 "

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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