Q:

Show two images overlapping each other in openCV

In Matlab there is a possibility to show two images overlapping each other, which is quite useful to show how two images are aligned with respect to each other.
For instance look to following code:
img1 = zeros(100,100);
img1(20:50, 10:40) = 255;
img2 = zeros(100, 100);
img2(35:65, 35:65) = 255;
imshowpair(img1, img2);

which creates following image:

Is there any built-in function or any way in openCV library to do so (in c++)? 

A:

You want to use addWeighted as documented here
Mat img1 = Mat(100,100,CV_8UC3,Scalar::all(0));
Mat img2 = Mat(100,100,CV_8UC3,Scalar::all(0));
rectangle(img1, Rect(20,10,50,40), Scalar(0,255,0), -1);
rectangle(img2, Rect(35,35,65,65), Scalar(255,0,255), -1);
Mat result;
addWeighted(img1, 0.5, img2, 0.5, 0.0, result);
imshow("SO question", result);
waitKey(10);

