title: Overlay a given image above a list of images
body: <p>I want to overlay a given image above a list of images and copy all images that fit to one folder what is the best programation language should I use?
  Here is example of images I want to overlay the red hat and copy all the images with red hat to ine folder
  here is image :<br />
  <a href="https://i.stack.imgur.com/it1Wo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/it1Wo.png" alt="image " /></a>
  I tried with Python many exmaple but it didn't work</p>
  <p>I tired this I found it in this website but it still didn't work:</p>
  <pre><code>import cv2
  import numpy as np
  from matplotlib import pyplot as plt
  from PIL import Image
  import os, errno
  
  
  
  threshold = 0.8 #set threshold
  resultsDirectory = 'results'
  sourceDirectory = os.fsencode(r'C:\Users\Amir\Desktop\Nouveau dossier (2)\rrr')
  templateDirectory = os.fsencode(r'C:\Users\Amir\Desktop\Nouveau dossier (2)\3.png')
  detectedCount = 0
  
  
  for file in os.listdir(sourceDirectory):
      filename = os.fsdecode(file)
      if filename.endswith(&quot;.jpg&quot;) or filename.endswith(&quot;.png&quot;): 
  
          print (filename)
  
          img_rgb = cv2.imread(r'C:\Users\Amir\Desktop\Nouveau dossier (2)\rrr'+filename)
          img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
  
          for templateFile in os.listdir(templateDirectory):
              templateFilename = os.fsdecode(templateFile)
  
              if filename.endswith(&quot;.jpg&quot;) or filename.endswith(&quot;.png&quot;):
                  template = cv2.imread(r'C:\Users\Amir\Desktop\Nouveau dossier (2)\3.png'+templateFilename,0)
                  w, h = template.shape[::-1]
                  res = cv2.matchTemplate(img_gray,template,cv2.TM_CCOEFF_NORMED)
                  loc = np.where( res &gt;= threshold)
  
                  if (len(loc[0])):
                      detectedCount = detectedCount + 1
                      for pt in zip(*loc[::-1]):
                          cv2.rectangle(img_rgb, pt, (pt[0] + w, pt[1] + h), (0,0,255), 2)
                      cv2.imwrite(resultsDirectory+'/res_'+filename+'.png',img_rgb)
                      print ('/res_'+filename+'.png'+' saved')
                      # break
  
          print ('detected positive ' + str(detectedCount))
          continue
      else:
          continue
  </code></pre>