Package: screenshot-ocr
screenshot-ocrExtract text from screenshots.OverviewThis 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,
tryleaf-focus.Install and SetupThere are three things to set up to get a working installation:Python and this packageTesseract for OCRAccess to the Google Docs spreadsheetPython and this packageHave a look at theRealPython guide to install Pythonand check the version of Python that is installed.Try usingpipxto installscreenshot-ocr.Create and activate a Python virtual environment (venv).
ThePython Packaging Guide shows how to create a venv.For example:# create the venvpython-mvenvscreenshot-ocr-venv# activate the venvsourcescreenshot-ocr-venv/bin/activate# update the package installation toolspython-mpipinstall--upgradepipsetuptoolswheelInstall this package (screenshot-ocr) from PyPI using pip.For example:# install this packagepipinstallscreenshot-ocrShow thescreenshot-ocrhelp and version to check it is installed.For example:# show the command line helpscreenshot-ocr--help# or, without the venv activatedscreenshot-ocr-venv/bin/screenshot-ocr--help
screenshot-ocr-venv/Scripts/screenshot-ocr--help# show the versionscreenshot-ocr--versionTesseract for OCRTesseract 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:sudoaptinstalltesseract-ocrAccess to the Google Docs spreadsheetThis 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 acredentials.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 acredentials.jsonIf 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.UsageAll 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 filesscreenshot-ocr"<google-docs-spreadsheet-id>"# use the defaults, except for the ocr binary and data file pathsscreenshot-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 filesscreenshot-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>"