Ask Your Question

addweighted for mix of two image

asked 2013-12-10 17:05:34 -0600

amin.karimi gravatar image

updated 2013-12-10 17:17:18 -0600

i want to mix a part of any image with original image and i write this program but my program produce only result of mixing of two parts but i want to see may original image with a part that is mixed with a part of another image why?please help me , my original image is "khaste.jpg"

    Mat image;
Mat im;
im=imread("kari o behrooz.jpg",CV_LOAD_IMAGE_COLOR);
Rect roi=Rect(150,200,40,60);
Mat image_roi=image(roi);
Mat im_roi=im(roi);


namedWindow("k",1 );
return (0);


edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2013-12-10 22:58:59 -0600

Hi there,

if you take a look at the documentation of addWeighted you will see that the last parameter is the output array that will have the same size as the input arrays. This means that by doing


the method addWeighted will deallocate image (because it is not of the same size as the image_roi) and allocate a new array with the same size as image_roi (40x60) and put there the result. Try instead this:


It should do what you want.

I hope this helps.

edit flag offensive delete link more


yes martin , thanks alot

amin.karimi gravatar imageamin.karimi ( 2013-12-11 00:21:11 -0600 )edit

Please accept the answer as correct.

Guanta gravatar imageGuanta ( 2013-12-11 08:33:16 -0600 )edit

martin said true , i should use image_roi as last argument in addweighted

amin.karimi gravatar imageamin.karimi ( 2013-12-11 10:20:55 -0600 )edit

well, then you can mark his answer as correct (the check below the number)

Guanta gravatar imageGuanta ( 2013-12-11 11:39:23 -0600 )edit

answered 2014-05-26 02:48:31 -0600

Farrakh Javed gravatar image

This is not working for different size images.

edit flag offensive delete link more



It wont work for different size images, according to Documentationsrc2 should be of the same size and channel number as src1, the solution for different sized image may be use ROI on larger image. Also from next time please use post a comment section instead of answer section.

Haris gravatar imageHaris ( 2014-05-26 04:06:04 -0600 )edit
Login/Signup to Answer

Question Tools


Asked: 2013-12-10 17:05:34 -0600

Seen: 1,711 times

Last updated: May 26 '14