Recently, I'm interested in image processing using OpenCV, but I'm new to it.
I do some simple image processing on a lot of images, and finally I want to watermark each image with a logo which is a small png
image.
There are a lot of codes which blend two images. Here is an example which I used to blend two images:
int main( int argc, char** argv )
{
double alpha = 0.5; double beta; double input;
Mat src1, src2, dst;
// main image with real size.(Large)
src1 = imread("a.jpg");
// logo which will be used as a watermark.(small size)
src2 = imread("logo.png");
namedWindow("Linear Blend", 1);
beta = ( 1.0 - alpha );
addWeighted( src1, alpha, src2, beta, 0.0, dst);
imshow( "Linear Blend", dst );
waitKey(0);
return 0;
}
Here, both images should be the same type and the same size, while my logo image is a small image which I want to blend to the main image in a corner (actually at an arbitrary point).
Can anyone help me to do that? (Maybe, one solution is to create a matrix from the logo which is the same size of the main image so every point outside of the logo should be zero and then finally blend two images which have equal size.)
my final code is like this:
int main( int argc, char** argv )
{
double alpha = 0.5; double beta; double input;
Mat src1, src2, src2_copy, dst;
src1 = imread("a.jpg");
src2 = imread("logo.png");
resize(src2, src2_copy, src2.size() / 2, 0.5, 0.5);
int x = 100;
int y = 100;
int w = src2_copy.size().width;
int h = src2_copy.size().height;
cv::Rect pos = cv::Rect(x, y, w, h);
dst = src1.clone();
namedWindow("Linear Blend", 1);
beta = ( 1.0 - alpha );
addWeighted(src1(pos), alpha, src2_copy, beta, 0.0, dst);
imshow("Linear ", dst);
waitKey(0);
return 0;
}