title: More efficient way to put an image on top of another - OpenCV Python3
body: <p>I have written a function that takes two images of equal size and returns a combined image of the same size such such that all <strong>black pixels</strong> (where the BGR value is [0, 0, 0]) of the first image will be replaced by <strong>pixels of the second image.</strong></p>
  
  <p>My code looks like this:</p>
  
  <pre><code>def combine(img1, img2):
      retImage = np.zeros((img1.shape[0], img1.shape[1], 3), dtype=np.uint8)
      for x in range(img1.shape[0]):
          for y in range(img1.shape[1]):
              if (0 not in img1[x][y]):
                  retImage[x][y] = img1[x][y]
              else:
                  retImage[x][y] = img2[x][y]
      return retImage
  </code></pre>
  
  <p>Obviously this is very slow, especially since I'm processing several 4k images in sequence. Is there a more efficient way to do this (preferably using OpenCV functions, like thresholding/masks)?</p>