title: Image Overlay Python OpenCV
body: <p>I am trying to overlay an image onto another image, similar to a watermark. It works on a test logo, but when I try it with the actual logo, I get the error:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;C:/Users/dv/PycharmProjects/Image/main.py&quot;, line 28, in &lt;module&gt;
      result = cv2.addWeighted(roi, 1, logo, 0.3, 0)
  cv2.error: OpenCV(4.5.2) C:\Users\runneradmin\AppData\Local\Temp\pip-req-build-_8k9tw8n\opencv\modules\core\src\arithm.cpp:650: error: (-209:Sizes of input arguments do not match) The operation is neither 'array op array' (where arrays have the same size and the same number of channels), nor 'array op scalar', nor 'scalar op array' in function 'cv::arithm_op'
  </code></pre>
  <p>The size looks the same, so I'm not sure what it's referring to.
  For example, if I run the code using this logo,</p>
  <p><img src="https://i.stack.imgur.com/GlCX3.png" alt="logo" /></p>
  <p>Onto the image:</p>
  <p><img src="https://i.stack.imgur.com/w4bcq.jpg" alt="image" /></p>
  <p>It shows up fine:</p>
  <p><img src="https://i.stack.imgur.com/ueg90.jpg" alt="output" /></p>
  <p>But when I use this logo:</p>
  <p><img src="https://i.stack.imgur.com/B1eqg.png" alt="error logo" /></p>
  <p>It gave the above error.</p>
  <p>Code:</p>
  <pre><code>import cv2
  import numpy as np
  import glob
  import os
  
  logo = cv2.imread(&quot;mylogo.png&quot;)
  h_logo, w_logo, _ = logo.shape
  
  images_path = glob.glob(&quot;images/*.*&quot;)
  
  print(&quot;Adding watermark&quot;)
  for img_path in images_path:
      img = cv2.imread(img_path)
      h_img, w_img, _ = img.shape
  
      # Get the center of the original. It's the location where we will place the watermark
      center_y = int(h_img / 2)
      center_x = int(w_img / 2)
      top_y = center_y - int(h_logo / 2)
      left_x = center_x - int(w_logo / 2)
      bottom_y = top_y + h_logo
      right_x = left_x + w_logo
  
      # Get ROI
      roi = img[top_y: bottom_y, left_x: right_x]
  
      # Add the Logo to the Roi
      result = cv2.addWeighted(roi, 1, logo, 0.3, 0)
  
      # Replace the ROI on the image
      img[top_y: bottom_y, left_x: right_x] = result
  
      # Get filename and save the image
      filename = os.path.basename(img_path)
      cv2.imwrite(&quot;images/watermarked_&quot; + filename, img)
  
  
  print(&quot;Watermark added to all the images&quot;)
  </code></pre>