Skip to main content

OCR on screenshots with EasyOCR - Windows only

Project description

Don't install this module without reading the instructions!!

The best OCR engine

In my opinion, EasyOCR is the best OCR engine out there.

The results are much better than Tesseract's OCR, but it is much slower.

And, unfortunately, it is a bit tricky to install.

Example - Bluestacks [adb/hwnd]

  <a href="https://www.youtube.com/watch?v=hDRwmzbrvaY">

     <img src="https://img.youtube.com/vi/hDRwmzbrvaY/0.jpg" style="width:100%;">

  </a>
Step 1

If you have a GPU and Windows (by the way, this module is only for Windows), you should install torch and torchvision first to get a good speed up

*From https://github.com/JaidedAI/EasyOCR

Note 1: For Windows, please install torch and torchvision first by following the official instructions here https://pytorch.org. On the pytorch website, be sure to select the right CUDA version you have. If you intend to run on CPU mode only, select CUDA = None.*

Step 2
pip install easyocr_window_scanner
Step 3

EasyOCR installs the headless (light) version of opencv that doesn't even have cv2.imshow, so

EasyOCR2Df.scan_window_with_adb / EasyOCR2Df.scan_window_with_hwnd don't work!

To fix this problem, do this:

pip uninstall opencv-python

pip uninstall opencv-python-headless

pip install --upgrade --force-reinstall opencv-python==4.5.5.62
Step 4

You might get the following error when you import the module:

cv2.error: Unknown C++ exception from OpenCV code.

It seems to be a very common issue with EasyOCR

https://github.com/opencv/opencv-python/issues/602#issuecomment-1070290110

To fix this problem, you have to open:

"C:\Users\YOURUSERNAME\anaconda3\envs\YOURENV\Lib\site-packages\easyocr\craft_utils.py"

and change:

nLabels, labels, stats, centroids = cv2.connectedComponentsWithStats(text_score_comb.astype(np.uint8), connectivity=4)

to:

nLabels, labels, stats, centroids = cv2.connectedComponentsWithStats(text_score_comb.astype(np.uint8))

Step 5
#We are finally ready to go



from easyocr_window_scanner import EasyOCR2Df



#create an instance, you can pass any argument you would pass to the EasyOCR module

easyo = EasyOCR2Df(["en"])



#Taking screenshots using adb, and do OCR on the fly

easyo.scan_window_with_adb(adb_path=r"C:\ProgramData\adb\adb.exe",adb_serial='localhost:5555',quit_key='q')



#Taking screenshots using the windows handle, and do OCR on the fly

easyo.scan_window_with_hwnd(hwnd=None, regular_expression='[bB]lue[sS]tacks.*', quit_key="q")



#If you just want to have the OCR results as a DataFrame, use:

easyo.start_ocr_to_df(r'https://i.ytimg.com/vi/fa82Qpw6lyE/hqdefault.jpg').get_results_df()

Out[5]:

                               text      conf  ...  middle_x  middle_y

0     No stop signs, speedin' limit  0.842704  ...       148        90

1       Nobody's gonna slow me down  0.744984  ...       159       112

2       Like a wheel, gonna spin it  0.966272  ...       141       136

3     Nobody's gonna mess me 'round  0.994361  ...       165       157

4               Satan! Paid my dues  0.708869  ...       153       180

5         Playin' in a rockin' band  0.979712  ...       133       202

6                  Mama' Look at me  0.559171  ...       147       224

7  Tm on my way t0 the promise land  0.703882  ...       174       247

8                               Hey  0.999969  ...        53       179

9                               Hey  0.999027  ...        52       224

[10 rows x 14 columns]



#If you want to have the image of the OCR results without showing it, use:

easyo.start_ocr_to_df(r'https://i.ytimg.com/vi/fa82Qpw6lyE/hqdefault.jpg').draw_easyocr_results().get_results_picture()

Out[7]:

array([[[0, 0, 0],

        [0, 0, 0],

        [0, 0, 0],

        ...,

        [0, 0, 0],

        [0, 0, 0],

        [0, 0, 0]],

        ...

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

easyocr_window_scanner-0.10.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

easyocr_window_scanner-0.10-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file easyocr_window_scanner-0.10.tar.gz.

File metadata

  • Download URL: easyocr_window_scanner-0.10.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for easyocr_window_scanner-0.10.tar.gz
Algorithm Hash digest
SHA256 fd99050f3ac3a252a24cfdb482344a3d780e52fe8dd63f6f69bd356353fb212e
MD5 1798e9d405e440a80c8a159d47e8dfb1
BLAKE2b-256 9c5e0a7c07dd3274519810d9ccd1f7ff3f6654ce17a0c668da18d8a2d8654120

See more details on using hashes here.

File details

Details for the file easyocr_window_scanner-0.10-py3-none-any.whl.

File metadata

File hashes

Hashes for easyocr_window_scanner-0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 c430fa37f23c98a62a42a16aa4ece57db1b29ac4710dd8fc0985423b2b5c8ae7
MD5 f1419fcb8841a3d7f43084472d0cce95
BLAKE2b-256 4adb200d07bb23bf279446a6bbab512f913853a671ace7cdc6bd497d29c3bade

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page