title: Mss grab to numpy to cv2MatchTemplate
body: <p>sorry in advance if the question as been requested .</p>
  <p>I want to take a screenshot with MSS ,
  send it to CV2 ( for template matching ) with NUMPY (and after do euclidian distance for fin the closest from a point ) .</p>
  <p>But i can't   :(</p>
  <p>I think is a problem of &quot;passing the numpy array to workable thing for cv2.MatchTemplate .</p>
  <p>( the template is little image , much more than the &quot;screen rect&quot; )</p>
  <p>I have try a lots of RGB to BRG and co , .....</p>
  <p>I dont seeM what is wrong</p>
  <p>( all commented line is for helping see where i am ) , a some other thing that i have try .</p>
  <p>The 3 parts of the screen grabed , showed by cv2.imshow are black ( do not displayed correctly )</p>
  <p><strong>if we use a png in replacement of screenshot with mss this code work perfectly</strong></p>
  <p>this is where i am :</p>
  <pre class="lang-py prettyprint-override"><code>import cv2
  import numpy as np
  import mss 
  import time
  import numpy as np
  from scipy.spatial.distance import cdist
  
  time.sleep(10)
  ################################################################################
  def screen_template_closest ()  :   
      with mss.mss() as sct:
                        
               # Part of the screen to capture 
               monitor = {&quot;top&quot;: 1059, &quot;left&quot;: 62, &quot;width&quot;: 285, &quot;height&quot;: 640}
        
               #Get raw pixels from the screen, save it to a Numpy array
               img = np.array(sct.grab(monitor))
               print(&quot;image shape&quot;,img.shape)
              
      # Display the picture
      cv2.imshow(&quot;OpenCV/Numpy normal&quot;, img)
      # Display the picture in grayscale
      cv2.imshow('OpenCV/Numpy grayscale',cv2.cvtColor(img, cv2.COLOR_BGRA2GRAY))
  
      img_gray = cv2.cvtColor(img, cv2.COLOR_BGRA2GRAY)
      template = cv2.imread('C:\\Users\\Faon\\projetadminEnv3\\test\\templates.PNG',0)
      w, h = template.shape[::-1]
      res = cv2.matchTemplate(img_gray,template,cv2.TM_CCOEFF_NORMED)
      threshold = 0.75
      #Counts the number of found matches, which are currently overlapping
      loc = np.where( res &gt;= threshold)
      
      coordsFinded = list()
      count = 0
      mask = np.zeros(img.shape[:2], np.uint8)
      
      for pt in zip(*loc[::-1]):
          if mask[pt[1] + h//2, pt[0] + w//2] != 255:
              mask[pt[1]:pt[1]+h, pt[0]:pt[0]+w] = 255
              count += 1
              cv2.rectangle(img, pt, (pt[0] + w, pt[1] + h), (0,255,0), 3)
              coordsFinded.append(pt)
              
      cv2.imshow('Matches',img)
      cv2.waitKey(0) &amp; 0xFF== ord('q')
  
      #closest distance from pta
      pta = np.array([[1036, 746]])   
      others1 = np.array(coordsFinded)
      print(&quot;others (all coords of finded images ) &quot;,others1)
      distances = cdist(pta, others1)
  
      winnerClose =  others1[distances.argmin()]
      print(&quot;the closest point is    : &quot;,winnerClose)      
  #######################################################################################
  
  print(screen_template_closest()) 
  
  </code></pre>
  <p>I will greatly appraciante any help .</p>