merge images opencv c 2b 2b

Solutions on MaxInterview for merge images opencv c 2b 2b by the best coders in the world

showing results for - "merge images opencv c 2b 2b"
Imran
13 Nov 2019
1#include <opencv2\opencv.hpp>
2using namespace cv;
3
4int main()
5{
6    // Load images
7    Mat3b img1 = imread("path_to_image_1");
8    Mat3b img2 = imread("path_to_image_2");
9
10    // Get dimension of final image
11    int rows = max(img1.rows, img2.rows);
12    int cols = img1.cols + img2.cols;
13
14    // Create a black image
15    Mat3b res(rows, cols, Vec3b(0,0,0));
16
17    // Copy images in correct position
18    img1.copyTo(res(Rect(0, 0, img1.cols, img1.rows)));
19    img2.copyTo(res(Rect(img1.cols, 0, img2.cols, img2.rows)));
20
21    // Show result
22    imshow("Img 1", img1);
23    imshow("Img 2", img2);
24    imshow("Result", res);
25    waitKey();
26
27    return 0;
28}
29