Advertisement
aRTIKa

aboba

Oct 2nd, 2022
835
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.26 KB | None | 0 0
  1. import time
  2. import keyboard
  3. import cv2
  4. import mss
  5. import numpy
  6. import pytesseract
  7. time.sleep(5)
  8. with mss.mss() as sct:
  9.     # Part of the screen to capture
  10.     monitor = {"top": 490, "left": 300, "width": 800, "height": 130}
  11.  
  12.     while "Screen capturing":
  13.  
  14.  
  15.         # Get raw pixels from the screen, save it to a Numpy array
  16.         img = numpy.array(sct.grab(monitor))
  17.  
  18.         # Display the picture
  19.         cv2.imshow("OpenCV/Numpy normal", img)
  20.         #keyboard.write(s[0:2])
  21.         # Display the picture in grayscale
  22.         # cv2.imshow('OpenCV/Numpy grayscale',
  23.         #            cv2.cvtColor(img, cv2.COLOR_BGRA2GRAY))
  24.  
  25.  
  26.  
  27.         # Press "q" to quit
  28.         if cv2.waitKey(25) & 0xFF == ord("q"):
  29.             cv2.destroyAllWindows()
  30.             break
  31.         # Part of the screen to capture
  32.  
  33.  
  34.  
  35.  
  36.  
  37.     s = pytesseract.image_to_string(img, lang='rus')
  38.     print(s)
  39.     i = 0
  40.     while i < len(s):
  41.  
  42.         if s[i] == "\n":
  43.             keyboard.write(' ')
  44.             i += 1
  45.             continue
  46.         keyboard.write(s[i])
  47.         i += 1
  48.     print(s)
  49.         # Display the picture in grayscale
  50.         # cv2.imshow('OpenCV/Numpy grayscale',
  51.         #            cv2.cvtColor(img, cv2.COLOR_BGRA2GRAY))
  52.  
  53.         # Press "q" to quit
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement