2

I want to align two images of different sizes using Opencv, Indeed the function cvAddWeighted enables us to combine or blend two images of identical sizes which is not my case ! so I need a help if somebody knows how to implement this function with considering the different sizes for images

thanks y.m

karlphillip
  • 92,053
  • 36
  • 243
  • 426
yasser
  • 21
  • 1
  • 2

3 Answers3

5

First, check Adding Two Images with Different Size.

Another way to do it would be to set the region of interested on the bigger image using the width/height of the smaller (cvSetImageROI() will do that), and then perform the blend with cvAddWeighted().

You can find some source code to do that here.

karlphillip
  • 92,053
  • 36
  • 243
  • 426
2

I'm guessing you have two images that need to be aligned. You'll also have the amount one image needs to be displaced by.

You can create a new image that can contain both the images after being displaced. This means, it would be the height of the original image+vertical displacement and its width would be width of original*2-horizontal displacement.

Then you can set ROIs on this image and copy images.

Utkarsh Sinha
  • 3,295
  • 4
  • 30
  • 46
  • 1
    +1 I am big fan of Aishack....I learnt so many thing from it...Can I get how to get rotation of head in 3d i jest need to know 3-angles... – Wazy Dec 07 '11 at 09:15
0

You write a Rect_from_Mat function which returns Rect(0, 0, img.rows, img.cols).

Then:

Rect roi = Rect_from_Mat(img1) & Rect_from_Mat(img2);

Mat img1_roi = img1(roi), img2_roi = img2(roi);
if(results_in_img1)
{
  addWeighted(img1_roi, alpha, img2_roi, beta, gamma, img1_roi);
  return img1;
}

Note that the 'addWeighted' line will (indirectly) overwrite img1's image data.

Barney Szabolcs
  • 11,846
  • 12
  • 66
  • 91