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: