screenshot-ocr
Extract text from screenshots.
Overview
This command line program will process images in a directory, move processed images to another directory, and enter the extracted text into cells in a Google Docs spreadsheet.
Initially created to extract text from screenshots of online trivia. This made it easier to put the question into a spreadsheet, so that people who were unable to watch the stream could participate.
If you're looking for a more generic program to extract structured text from pdfs and images, try leaf-focus.
Install and Setup
There are three things to set up to get a working installation:
- Python and this package
- Tesseract for OCR
- Access to the Google Docs spreadsheet
Python and this package
-
Have a look at the RealPython guide to install Python and check the version of Python that is installed.
-
Try using pipx to install
screenshot-ocr. -
Create and activate a Python virtual environment (
venv). The Python Packaging Guide shows how to create a venv.
For example:
# create the venv
python -m venv screenshot-ocr-venv
# activate the venv
source screenshot-ocr-venv/bin/activate
# update the package installation tools
python -m pip install --upgrade pip setuptools wheel
- Install this package (
screenshot-ocr) from PyPI using pip.
For example:
# install this package
pip install screenshot-ocr
- Show the
screenshot-ocrhelp and version to check it is installed.
For example:
# show the command line help
screenshot-ocr --help
# or, without the venv activated
screenshot-ocr-venv/bin/screenshot-ocr --help
screenshot-ocr-venv/Scripts/screenshot-ocr --help
# show the version
screenshot-ocr --version
Tesseract for OCR
Tesseract OCR is used for Optical Character Recognition.
It must be installed separately. Install tesseract.
On Debian and Ubuntu and similar Linux distributions, there might be an apt package available.
For example:
sudo apt install tesseract-ocr
Access to the Google Docs spreadsheet
This app uses the Google OAuth Installed App Flow to gain access to the spreadsheet.
Follow the guide to set up your access.
You'll need to provide a credentials.json (client_secrets.json) file.
You can download this from the Google Cloud -> APIs and Services -> Credentials page.
Under "OAuth 2.0 Client IDs",
for a "Desktop" type client,
use the "Download OAuth client" action,
then "Download JSON" to get a credentials.json
If there is no valid token, you'll be prompted to log in with your Google account through your browser, and asked to authorise the app's access to Google Docs spreadsheets.
If this process succeeds, this program will create a token file that will be used for subsequent access.
Usage
All optional arguments have reasonable defaults. Try using the defaults first.
If you run into issues, you can also specify the paths to the required files.
# use all the defaults: ocr tool and data files,
# input dir, output dir, credentials and token files
screenshot-ocr "<google-docs-spreadsheet-id>"
# use the defaults, except for the ocr binary and data file paths
screenshot-ocr "<google-docs-spreadsheet-id>" \
--tesseract-exe "<path-to-file>" \
--tesseract-data "<path-to-dir>"
# specify everything: ocr binary and data files,
# input dir, output dir, credentials and token files
screenshot-ocr "<google-docs-spreadsheet-id>" \
--input-dir "<path-to-dir>" \
--output-dir "<path-to-dir>" \
--tesseract-exe "<path-to-file>" \
--tesseract-data "<path-to-dir>" \
--google-credentials "<path-to-file>" \
--google-token "<path-to-file>"
Metadata
Release files for screenshot-ocr 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| screenshot-ocr-0.3.0.tar.gz | 20.5 kB | Without provenance | Details for screenshot-ocr-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| screenshot_ocr-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for screenshot_ocr-0.3.0-py3-none-any.whl |
Total release size: 38.3 kB
Release files / screenshot-ocr-0.3.0.tar.gz
| Download URL | screenshot-ocr-0.3.0.tar.gz |
|---|---|
| Size | 20.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8452bb01eb41fb7084216314e21900a8f9bb1339d027b02323a2c812e61b70ee
|
|
BLAKE2b-256 checksum How to use checksums |
bf3284b92267f938842292e3755e9ffdc3e7ffeea6659cbb078c99f76647eba0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.7
|
Release files / screenshot_ocr-0.3.0-py3-none-any.whl
| Download URL | screenshot_ocr-0.3.0-py3-none-any.whl |
|---|---|
| Size | 17.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
12a8c045586324dca6a808d97282524bade4c8ba036a98c6a5991953e68bb6aa
|
|
BLAKE2b-256 checksum How to use checksums |
598a2523a42b83c575750c2cd270ed63e72309e53c5dc6cc46d807a07e311794
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.7
|
Security for screenshot-ocr 0.3.0
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.