Package: tesseract-window-scanner
Scan screenshots with TesseractVideoExample 1 (screenshots from BlueStacks using ADB)importcv2importpandasaspdimportnumpyasnpfromtimeimportsleepfromtesseract_window_scannerimportpd_add_tesseract,sub_color_in_image,\substitute_colors_with_equal_rgb_values,draw_tesseract_results,get_tesseractdf,keyboard,ScreenShotsdefactivate_stop():globalstopstop=Truetesseractpath=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=Falsekeyboard.add_hotkey(quit_key,activate_stop)showresults=Truewhilenotstop:screenshot_window=sc2.imget_adb()# optional filterscreenshot_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)ifshowresults:sc2.show_edited_image(tesserresults)# show the edited picprint(df[["text","conf"]])Example 2 (screenshots from BlueStacks using hwnd)importcv2importpandasaspdimportnumpyasnpfromtimeimportsleepfromtesseract_window_scannerimportpd_add_tesseract,sub_color_in_image,\substitute_colors_with_equal_rgb_values,draw_tesseract_results,get_tesseractdf,keyboard,ScreenShotsdefactivate_stop():globalstopstop=Truetesseractpath=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=Falsekeyboard.add_hotkey(quit_key,activate_stop)showresults=Truewhilenotstop: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)ifshowresults:sc2.show_edited_image(tesserresults)# show the edited picprint(df[["text","conf"]])Example 3 (screenshots from BlueStacks using hwnd without showing the results)importcv2importpandasaspdimportnumpyasnpfromtimeimportsleepfromtesseract_window_scannerimportpd_add_tesseract,sub_color_in_image,\substitute_colors_with_equal_rgb_values,draw_tesseract_results,get_tesseractdf,keyboard,ScreenShotsdefactivate_stop():globalstopstop=Truetesseractpath=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=Falsekeyboard.add_hotkey(quit_key,activate_stop)whilenotstop: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"]])