Skip to content

Instantly share code, notes, and snippets.

@TBog
Last active February 23, 2022 11:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TBog/146ee49c774e59cc392f7f6ae4714c44 to your computer and use it in GitHub Desktop.
Save TBog/146ee49c774e59cc392f7f6ae4714c44 to your computer and use it in GitHub Desktop.
Screen region OCR

How can instantaneously extract text from a screen area using OCR tools?

  1. copy screen_region_ocr.sh file to your home folder
  2. chmod +x ~/screen_region_ocr.sh to make it executable
  3. copy screen_region_ocr.desktop to ~/.local/share/applications/ (change Exec path)

Dependencies: tesseract imagemagick spactacle xsel

You can now run Screen Region OCR from your application launcher, select a screen region then paste (Ctrl+V) the OCRed text where you need it

[Desktop Entry]
Version=0.1
Type=Application
Name=Screen Region OCR
Comment=OCR the selected screen region
Exec=~/screen_region_ocr.sh
Icon=text-x-generic.png
Terminal=false
Categories=Utility
#!/bin/bash
# Dependencies: tesseract imagemagick spactacle xsel
TMP_FILE=`mktemp`
trap "rm $TMP_FILE*" EXIT
# start capture
spectacle -rbno $TMP_FILE
# should increase detection rate
mogrify -modulate 100,0 -resize 400% $TMP_FILE
# show image after mogrify
#magick display $TMP_FILE.png
# ocr
tesseract $TMP_FILE $TMP_FILE -l eng+ron txt
# copy to clipboard
cat $TMP_FILE.txt | xsel -bi
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment