OPENCV2 Learning Note 5-Manipulating images (Mask copy roi-image addition of different sizes)

Source: Internet
Author: User

Suppose we want to merge two images that are not the same size, because the Cv::add requires two images of the same size, so you can't use them directly, and you need to define areas of interest before you use them. As long as the area of interest of the larger image equals the size of the smaller image, add will work correctly.







int main ()
{
	Cv::mat img1 = Cv::imread ("boldt.jpg");
	Cv::mat logo = Cv::imread ("logo.bmp");
	Cv::mat Imgroi = IMG1 (Cv::rect (385,, Logo.cols, logo.rows));

	Cv::addweighted (Imgroi, 1.0, logo, 0.5, 0., imgroi);
	Cv::namedwindow ("with logo");
	Cv::imshow ("with logo", IMG1);
	Cv::waitkey (0);
}
Picture 1:









Logo Image:










Effect Diagram:










Because the logo image and the original image are added directly (and may be accompanied by pixel saturation), the visual effect is not very satisfactory. So it's better to set the pixel directly to the pixel value of the logo image.







#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/ highgui/highgui.hpp>
#include <vector>

int main ()
{
	Cv::mat img1 = Cv::imread ("boldt.jpg") ;
	Cv::mat logo = Cv::imread ("logo.bmp");
	Cv::mat mask = cv::imread ("Logo.bmp", 0);
	Cv::mat Imgroi = IMG1 (Cv::rect (385,, Logo.cols, logo.rows));
	Logo.copyto (Imgroi, mask);

	Cv::namedwindow ("with logo");
	Cv::imshow ("with logo", IMG1);
	Cv::waitkey (0);
}

Effect Diagram:








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.