I am trying to mix two images as shown here .
This is all my code.
#include <cv.h>
#include <highgui.h>
#include <iostream>
using namespace cv;
int main( int argc, char** argv )
{
double beta; double input;
Mat src1, src2, dst;
std::cout<<" Simple Linear Blender "<<std::endl;
std::cout<<"-----------------------"<<std::endl;
src1 = imread("face.jpg");
src2 = imread("necklace1.png");
if( !src1.data ) { printf("Error loading src1 \n"); return -1; }
if( !src2.data ) { printf("Error loading src2 \n"); return -1; }
double alpha = 0.1;
int min_x = ( (src1.cols - src2.cols)/2 );
int min_y = ( (src1.rows - src2.rows)/2 );
int width, height;
cv::Rect roi = cv::Rect(min_x, min_y, src2.cols, src2.rows);
cv::Mat out_image = src1.clone();
cv::Mat src1_roi= src1(roi);
cv::Mat out_image_roi = out_image(roi);
cv::addWeighted(src1_roi,alpha,src2,1-alpha,0.0,out_image_roi);
imshow( "Linear Blend", out_image );
waitKey(0);
return 0;
}
My input images

But the result is

I want this necklace to be transparent as before. How to do it?
I tried cvtColor( out_image_roi,out_image_roi, CV_BGR2BGRA );beforecv::addWeighted(src1_roi,alpha,src2,1-alpha,0.0,out_image_roi);
But then the way out is just a face image.
source
share