title: Combine 2 images with mask
body: <p>I am attempting to paint a logo over the top of a landscape image in OpenCV python. I have found answers that can 'blend'/watermark images but I don't want to make the logo transparent, I simply want to display the logo on top of the landscape image and keep the logo opacity (or lack thereof).</p>
  
  <p>I have tried both <code>cv2.add()</code> and <code>cv2.bitwise_and()</code> but these are not copying the logo across.</p>
  
  <pre><code>src = cv2.imread('../images/pan1.jpg')
  logo = cv2.imread('../images/logo.png')  # the background is black which is good because I dont want the black parts
  
  # Ensure the logo image is the same size as the landscape image
  logo_resized = np.zeros(src.shape, dtype="uint8")
  # Place the logo at the bottom right
  logo_resized[ src.shape[0] - logo.shape[0] : src.shape[0], src.shape[1] - logo.shape[1] : src.shape[1]] = logo
  
  # Convert the logo to single channel
  logo_gray = cv2.cvtColor(logo_resized, cv2.COLOR_BGR2GRAY)
  # Create a mask of the logo image
  ret, mask = cv2.threshold(logo_gray, 1, 255, cv2.THRESH_BINARY)
  
  # Combine the landscape and the logo images but use a mask so the black parts of logo don't get copied across
  # combined = cv2.bitwise_and(logo_resized, logo_resized, mask=mask)
  combined = cv2.add(src, logo_resized, mask=mask)
  </code></pre>
  
  <p>My result:</p>
  
  <p><a href="https://i.stack.imgur.com/19jym.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/19jym.jpg" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/5l4Bq.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/5l4Bq.jpg" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/M4nKr.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/M4nKr.jpg" alt="enter image description here"></a></p>