SHARE
TWEET

Untitled

a guest Oct 2nd, 2017 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # -*- coding:utf-8 -*-
  2.  
  3. #from PIL import ImageGrab
  4.  
  5. import platform
  6. import time
  7. import mss
  8. import numpy as np
  9. import cv2
  10.  
  11. template = cv2.imread("C:/Users/Sparr/Pictures/Screenshots/Screenshot (16).png")
  12. template2 = cv2.imread("C:/Users/Sparr/Pictures/Screenshots/Screenshot (17).png", 0)
  13. method = cv2.TM_CCOEFF
  14.  
  15. with mss.mss() as sct:
  16.  
  17.     print("Looking for QR code")
  18.     # Grab the whole screen, and convert it to a numpy array to allow matricies to be applied
  19.     monitor = sct.monitors[1]
  20.     img = np.array(sct.grab(monitor))
  21.     #print("display screenshot")
  22.     #cv2.imshow("test 0", img)
  23.     #img = cv2.rectangle(img,(0,100),(500,128),(0,100,10000),30)
  24.     # Make sure the display shown is in RGB
  25.     img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
  26.     #print("display rgb screenshot")
  27.     #cv2.imshow("test 1", img)
  28.  
  29.     res = cv2.matchTemplate(img, template, method)
  30.  
  31.     for i in res:
  32.         #print(str(i))
  33.  
  34.         w, h = template2.shape[::-1]
  35.         threshold = 0.7
  36.         loc = np.where( res >= threshold)
  37.         img = cv2.rectangle(img,(0,100),(500,128),(0,100,10000),3)
  38.         #cv2.rectangle(img, 'x location', 'y location', 'x length', 'y length', 'green or cyan 0 or 1000', 'opacity', 'color', 'fill')
  39.  
  40.     #cv2.imwrite('res.png',img)
  41.  
  42.  
  43.     #print(frame)
  44.     #print(template)
  45.     #print(img)
  46.    
  47.     # Lets show the img and call it "test"
  48.     print("display processsed image")
  49.     while(True):
  50.         cv2.imshow("test", img)
  51.        
  52.         # Press q to stop this program
  53.         if cv2.waitKey(25) & 0xFF == ord('q'):
  54.        
  55.             # Clean exit
  56.             cv2.destroyAllWindows()
  57.            
  58.             # Exists the program
  59.             break
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top