Opencv concatenates two images

Source: Internet
Author: User

The following are some knowledge points:

(1) path setting: Generally, you need to save the folder containing images to the project directory, that is, ensure that the folder and debug are under the same root directory;

(2) cvsetimageroi and cvcopy functions:

Cvsetimageroi (iplimage * DST, cvrect (left border, upper border, width, height )). This function is to open the cvrect rectangular frame area memory space in the image DST, and then cvcopy (iplimage * SRC, iplimage * DST) the function copies the source image SRC to the destination image DST.

 

ReferenceCode:

# Include <cv. h>
# Include

Int main (INT argc, char * argv [])
{
Iplimage * src1;
Iplimage * src2;
Iplimage * des;

Src1 = cvloadimage ("111.jpg", 0 );
Src2 = cvloadimage ("222.jpg", 0 );

Des = cvcreateimage (cvsize (1200,450), src1-> depth, src1-> nchannels );

 

//----------------------------------
// Load the original image to the Target Image
Cvsetimageroi (DES, cvrect (0, 0,600,450 ));
Cvcopy (src1, des );
Cvresetimageroi (DES );
Cvsetimageroi (DES, cvrect (600, 0,600,450 ));
Cvcopy (src2, des );
Cvresetimageroi (DES );

Cvnamedwindow ("image merging", 1 );
Cvshowimage ("image merging", des );
Cvwaitkey (0 );

Cvreleaseimage (& src1 );
Cvreleaseimage (& src2 );
Cvreleaseimage (& des );

Cvdestroywindow ("image merging ");
Return 0;
}

 

Running result:

Contact Us

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.