Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding:utf-8 -*-
- #from PIL import ImageGrab
- import platform
- import time
- import mss
- import numpy as np
- import cv2
- template = cv2.imread("C:/Users/Sparr/Pictures/Screenshots/Screenshot (16).png")
- template2 = cv2.imread("C:/Users/Sparr/Pictures/Screenshots/Screenshot (17).png", 0)
- method = cv2.TM_CCOEFF
- with mss.mss() as sct:
- print("Looking for QR code")
- # Grab the whole screen, and convert it to a numpy array to allow matricies to be applied
- monitor = sct.monitors[1]
- img = np.array(sct.grab(monitor))
- #print("display screenshot")
- #cv2.imshow("test 0", img)
- #img = cv2.rectangle(img,(0,100),(500,128),(0,100,10000),30)
- # Make sure the display shown is in RGB
- img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
- #print("display rgb screenshot")
- #cv2.imshow("test 1", img)
- res = cv2.matchTemplate(img, template, method)
- for i in res:
- #print(str(i))
- w, h = template2.shape[::-1]
- threshold = 0.7
- loc = np.where( res >= threshold)
- img = cv2.rectangle(img,(0,100),(500,128),(0,100,10000),3)
- #cv2.rectangle(img, 'x location', 'y location', 'x length', 'y length', 'green or cyan 0 or 1000', 'opacity', 'color', 'fill')
- #cv2.imwrite('res.png',img)
- #print(frame)
- #print(template)
- #print(img)
- # Lets show the img and call it "test"
- print("display processsed image")
- while(True):
- cv2.imshow("test", img)
- # Press q to stop this program
- if cv2.waitKey(25) & 0xFF == ord('q'):
- # Clean exit
- cv2.destroyAllWindows()
- # Exists the program
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement