title: Copy / blend images of different sizes using opencv
body: <p>I am trying to blend two images. It is easy if they have the same size, but if one of the images is smaller or larger cv::addWeighted fails. </p>
  
  <p>Image A (expected to be larger)
  Image B (expected to be smaller)</p>
  
  <p>I tried to create a ROI - tried to create a third image of the size of A and copy B inside - I can't seem to get it right. Please help.</p>
  
  <pre><code>double alpha = 0.7; // something
  int min_x = ( A.cols - B.cols)/2 );
  int min_y = ( A.rows - B.rows)/2 );
  int width, height;
  if(min_x &lt; 0) {
    min_x = 0; width = (*input_images).at(0).cols - 1;
  }
  else         width = (*input_images).at(1).cols - 1;
  if(min_y &lt; 0) {
    min_y = 0; height = (*input_images).at(0).rows - 1;
  }
  else         height = (*input_images).at(1).rows - 1;
  cv::Rect roi = cv::Rect(min_x, min_y, width, height);            
  cv::Mat larger_image(A);
  // not sure how to copy B into roi, or even if it is necessary... and keep the images the same size
  cv::addWeighted( larger_image, alpha, A, 1-alpha, 0.0, out_image, A.depth());
  </code></pre>
  
  <p>Even something like cvSetImageROI - may work but I can't find the c++ equivalent - may help - but I don't know how to use it to still keep the image content, only place another image inside ROI...</p>