Question

I am trying to blend 2 image in my code below

Mat input = imread ("E:\\img1.jpg");
Mat image;
Mat img12=imread("D:\\vig.png",-1);  // load 'as is', don't convert to bgr !!
Mat ch[4]; 
split(img12,ch);
Mat im2 = ch[3];              // here's the vignette
im2 = 255 - im2; 
im2.convertTo(im2 , input.type());
resize(im2,image,Size(input.rows,input.cols));
blending_overlay(image , input , image);
imshow ("image",image);
waitKey();

different operation on img12 is because of it shape , code giving me the runtime error of

enter image description here

Was it helpful?

Solution

As @berak commented, you are not using cv::Size correctly, whose first parameter is width, and second height (not the other way around).

Change

resize(im2, image, Size(input.rows, input.cols));

to

resize(im2, image, Size(input.cols, input.rows));

Update: You further need to address image that is passed in to function blending_overlay. It has only one channel, but you're trying to access other channels from it:

float target = (float)img1.at<uchar>(i, 3*j+c)/255.0 ; // img1 = image here
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top