Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.85 KB | None | 0 0
  1. import pytesseract
  2. import cv2
  3. import numpy as np
  4. from PIL import Image, ImageGrab
  5. from matplotlib import pyplot as plt
  6.  
  7. x = 645
  8. y = 575
  9. x_offset = 1220
  10. y_offser = 180
  11. replacements = (('1', 'l'), ('0', 'o'))
  12.  
  13. while True:
  14.     img = ImageGrab.grab(bbox=(x, y, x + x_offset, y + y_offser)).convert('L')
  15.     img = np.array(img)
  16.  
  17.     img = cv2.GaussianBlur(img, (5, 5), 0)
  18.     img = cv2.threshold(img, 120, 255, cv2.THRESH_BINARY)[1]
  19.     cv2.imshow('window', img)
  20.    
  21.     text = pytesseract.image_to_string(img).replace(" ", "").lower()
  22.  
  23.     for old, new in replacements:
  24.         text = text.replace(old, new)
  25.        
  26.     if text is not "":
  27.         print(text)
  28.        
  29.     if "champion" in text:
  30.         print("Winner winner")
  31.         cv2.waitKey(0)
  32.         break
  33.        
  34.     if cv2.waitKey(250) & 0xFF == ord('q'):
  35.         cv2.destroyAllWindows()
  36.         break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement