Untitled
unknown
plain_text
2 years ago
1.3 kB
6
Indexable
import pyautogui import pytesseract import re import openpyxl import time # Set the resolution of the screen screen_resolution = (1920, 1080) # Set the letters to recognize letters_to_recognize = 'ABC' # Set the output Excel file name output_file = 'recognized_letters.xlsx' # Create a new Excel workbook and worksheet workbook = openpyxl.Workbook() worksheet = workbook.active worksheet.cell(row=1, column=1, value='Recognized Letters') # Initialize a counter for the number of recognized letters letter_count = 0 while True: # Start the screen capture image = pyautogui.screenshot() # Convert the image to grayscale and apply threshold image = image.convert('L') threshold = 200 image = image.point(lambda x: 0 if x < threshold else 255) # Recognize text using Tesseract OCR text = pytesseract.image_to_string(image) # Search for the desired letters in the recognized text recognized_letters = re.findall(f'[{letters_to_recognize}]', text) # Write the recognized letters to the worksheet for letter in recognized_letters: letter_count += 1 worksheet.cell(row=letter_count+1, column=1, value=letter) # Save the workbook to the output file workbook.save(output_file) # Wait for a specified interval before capturing the screen again time.sleep(1)
Editor is loading...