# The use of OPENCV image stitching stitching

Source: Internet
Author: User
Tags error code

Image Mosaic Technology, now has a very wide range of applications, such as small robot monocular vision of the small, so that the robot in the application of a certain limitation, binocular vision can provide a broader vision, binocular vision is more commonly used in the left and right two cameras to obtain a wider view of the image through stitching to obtain a broader vision, Again like the more popular Vr,youtube also greatly uses the image splicing technology.
Image stitching is mainly divided into several main steps:
(1) Image correction: Because of the image geometric distortion caused by the attitude and scanning nonlinearity of the imaging device, the distortion of images can be produced due to the image system itself, the geometric correction of images, the distortion correction of images, Make the acquired image much closer to the real image;
(2) Image filtering: mean filter, median filter;
(3) Image registration: That is, image alignment, look for image edge coincident parts, commonly used image matching method has Harris algorithm, SIFT algorithm, etc.
(4) Set up the transformation model: according to the corresponding relationship between the template or image features, the parameters of the mathematical model are calculated, and then the mathematical transformation model of two images is established.
(5) Coordinate transformation: According to the mathematical transformation model, the stitching image is transformed into the coordinate system of the reference image, and the unified coordinate transformation is completed.
(6) Image fusion: The coincident region of the image to be spliced is fused to obtain the smooth and seamless panorama image of stitching reconstruction.
First introduce the image stitching example in OPENCV stitching:

```#include <iostream> #include <fstream> #include "opencv2/highgui/highgui.hpp" #include <opencv2\
Stitching\stitcher.hpp> using namespace std;

using namespace CV;
int main (void) {string Srcfile[3] = {"1.jpg", "2.jpg", "3.jpg"};
String dstfile = "Result.jpg";
Vector<mat> IMGs;
for (int i = 0; i<3; ++i) {Mat img = imread (srcfile[i]);
if (Img.empty ()) {cout << "Can ' t read image '" << srcfile[i] << "\ n";
System ("pause");
return-1;
} imgs.push_back (IMG);
} cout << "Please wait ..." << Endl;
Mat Pano;
Stitcher Stitcher = Stitcher::createdefault (false);
Stitcher::status Status = Stitcher.stitch (IMGs, Pano); if (Status! = Stitcher::ok) {cout << "Can ' t stitch images, error code=" << int (status) << E
Ndl
System ("pause");
return-1;
} imwrite (Dstfile, Pano); NAmedwindow ("Result");

Imshow ("Result", Pano);

Waitkey (0);
DestroyWindow ("Result");
System ("pause");
return 0; }```

First the For loop is read into the picture, and a data is added to the vector;

`Stitcher Stitcher::createdefault (bool try_use_gpu=false)`

Then use Createdefault to create the default parameters of image stitching;

`Status Stitcher::stitch (Inputarray images, Outputarray pano)`

Stitcher::stitch gives a picture of the synthesis;
Here is the result of the author's synthesis of the picture:

Image is a bit distorted (may be the problem when shooting), but stitching stitching effect is very good
There are fewer stitcher introduced in the API manuals provided by OPENCV,

Next try to implement it yourself in code

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.