Skip to main content

Scan screenshots with Tesseract

Video


Example 1 (screenshots from BlueStacks using ADB)

import cv2

import pandas as pd

import numpy as np

from time import sleep

from tesseract_window_scanner import pd_add_tesseract, sub_color_in_image, \

    substitute_colors_with_equal_rgb_values, draw_tesseract_results, get_tesseractdf,keyboard,ScreenShots





def activate_stop():

    global stop

    stop = True



tesseractpath = r"C:\Program Files\Tesseract-OCR\tesseract.exe"

pd_add_tesseract(tesseractpath)

languages = "de+pt+deu"



sc2 = ScreenShots(

    hwnd=None, adb_path=r"C:\ProgramData\adb\adb.exe", adb_serial="localhost:5735"

)

quit_key = "q"

sc2.imshow_adb(sleep_time=0.05, quit_key=quit_key)

sleep(1)

sc2.enable_show_edited_images()

stop = False

keyboard.add_hotkey(quit_key, activate_stop)



showresults = True

while not stop:

    screenshot_window = sc2.imget_adb()



    # optional filter

    screenshot_window = sub_color_in_image(

        img=screenshot_window,

        conditions=(("r", ">", 200), "|", ("g", ">", 200), "|", ("b", ">", 200)),

        newcolor=(255, 255, 255),

    )

    df = get_tesseractdf(

        screenshot_window, lang=languages, drop_empty_strings=True, conf_thresh=60

    )

    tesserresults = draw_tesseract_results(

        dft=df, img=screenshot_window, conf_thresh=60

    )

    if showresults:

        sc2.show_edited_image(tesserresults)  # show the edited pic

    print(df[["text", "conf"]])

Example 2 (screenshots from BlueStacks using hwnd)

import cv2

import pandas as pd

import numpy as np

from time import sleep

from tesseract_window_scanner import pd_add_tesseract, sub_color_in_image, \

    substitute_colors_with_equal_rgb_values, draw_tesseract_results, get_tesseractdf,keyboard,ScreenShots



def activate_stop():

    global stop

    stop = True





tesseractpath = r"C:\Program Files\Tesseract-OCR\tesseract.exe"

languages = "de+pt+deu"

pd_add_tesseract(tesseractpath)

sc2 = ScreenShots()

sc2.find_window_with_regex("[bB]lue[sS]tacks.*")

quit_key = "e"

sc2.imshow_hwnd(sleep_time=0.05, quit_key=quit_key)

sleep(1)

sc2.enable_show_edited_images()

stop = False

keyboard.add_hotkey(quit_key, activate_stop)



showresults = True

while not stop:

    screenshot_window = sc2.imget_hwnd()



    # screenshot_window=sub_color_in_image(img=screenshot_window, conditions=(('r' ,'>', 200) ,'|' ,('g' ,'>', 200), '|', ('b' ,'>', 200)), newcolor=(255,255,255))

    df = get_tesseractdf(

        screenshot_window, lang=languages, drop_empty_strings=True, conf_thresh=60

    )

    tesserresults = draw_tesseract_results(

        dft=df, img=screenshot_window, conf_thresh=60

    )

    if showresults:

        sc2.show_edited_image(tesserresults)  # show the edited pic

    print(df[["text", "conf"]])

Example 3 (screenshots from BlueStacks using hwnd without showing the results)

import cv2

import pandas as pd

import numpy as np

from time import sleep

from tesseract_window_scanner import pd_add_tesseract, sub_color_in_image, \

    substitute_colors_with_equal_rgb_values, draw_tesseract_results, get_tesseractdf,keyboard,ScreenShots





def activate_stop():

    global stop

    stop = True    



tesseractpath = r"C:\Program Files\Tesseract-OCR\tesseract.exe"

languages = "de+pt+deu"

pd_add_tesseract(tesseractpath)

sc2 = ScreenShots()

sc2.find_window_with_regex("[bB]lue[sS]tacks.*")



quit_key = "x"

stop = False

keyboard.add_hotkey(quit_key, activate_stop)



while not stop:

    screenshot_window = sc2.imget_hwnd()



    screenshot_window = sub_color_in_image(

        img=screenshot_window,

        conditions=(("r", ">", 200), "|", ("g", ">", 200), "|", ("b", ">", 200)),

        newcolor=(255, 255, 255),

    )

    df = get_tesseractdf(

        screenshot_window, lang=languages, drop_empty_strings=True, conf_thresh=60

    )

    print(df[["text", "conf"]])

Metadata

Release files for tesseract-window-scanner 0.12

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tesseract-window-scanner 0.12
File Size Uploaded Provenance Actions
tesseract_window_scanner-0.12.tar.gz 6.2 kB Without provenance Details for tesseract_window_scanner-0.12.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for tesseract-window-scanner 0.12
File Interpreter ABI Platform Actions
tesseract_window_scanner-0.12-py3-none-any.whl Python 3 none any Details for tesseract_window_scanner-0.12-py3-none-any.whl

Total release size: 14.5 kB

Release files / tesseract_window_scanner-0.12.tar.gz

Download URL tesseract_window_scanner-0.12.tar.gz
Size 6.2 kB
Tags Source
SHA-256 checksum
How to use checksums
b8c6ce214514def8479ba54adf355dd0c9e33a47d0fa738b17ffc4ea1a4b4e43
BLAKE2b-256 checksum
How to use checksums
61f6ad31f84a685dc2a6c5ccff7473c11c5e776d1b12d03fd3c908942f2e8909
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release files / tesseract_window_scanner-0.12-py3-none-any.whl

Download URL tesseract_window_scanner-0.12-py3-none-any.whl
Size 8.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8b72c77eddf387c6c33a5abd9e6725c8bf877c758310993dccc1da00c1045501
BLAKE2b-256 checksum
How to use checksums
c921f0f706ea9b1df1897d914f146f98373eaa58a43b4c685d5fbc4f2b85bf1c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Security for tesseract-window-scanner 0.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.12 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page