Tuesday, 10 March 2020

take a screenshot with python , convert image into text and save it as a file




try:
    from PIL import Image
except ImportError:
    import Image
import pytesseract
import sys, os
import subprocess
import pyautogui


pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'

img1 = pyautogui.screenshot(region=(372,198,1118,682))
img1.save("screenshot1.jpg")


saved_stdout = sys.stdout
sys.stdout = open('file.txt', 'w')
print (pytesseract.image_to_string(Image.open('screenshot1.jpg')))
sys.stdout.close()
sys.stdout = saved_stdout

No comments:

Post a Comment

Git

1 git add ↳ It lets you add changes from the working directory into the staging area 2 git commit ↳ It lets you save a snapshot of currently...