10

I want to be able to take a screenshot on my mac, then send that to an OCR engine and get back the text it has identified.

Are there any existing software tools that do this for macOS?

8 Answers 8

9

I have used FastScripts to assign a keyboard shortcut to these commands:

screencapture -i /tmp/tesseract.png
tesseract /tmp/tesseract.png stdout|tr -d \\f|LC_CTYPE=UTF-8 pbcopy

brew install tesseract installs Tesseract. Tesseract prints to STDOUT when the name of the output file is specified as stdout. A form feed character is added to the end of the output.

For non-English text, you have to manually specify the language: for example -l deu for German. To list the available languages, run tesseract --list-langs.

Edit: In cases where Tesseract produces inaccurate results, I now use Google's Cloud Vision API instead. Demo: https://cloud.google.com/vision/docs/drag-and-drop.

curl -sH"Authorization:Bearer $(gcloud auth application-default print-access-token)" -HContent-Type:application/json\;charset=utf-8 https://vision.googleapis.com/v1/images:annotate -d@<(printf %s '{"requests":[{"image":{"content":"'"$(base64 input.png)"'"},"features":[{"type":"TEXT_DETECTION"}]}]}')|jq -r '.responses[0].fullTextAnnotation.text'

Edit 2: My free trial for the Google API expired, so I now use Yandex Translate to do OCR for images that Tesseract has trouble with: https://translate.yandex.com/ocr.

Edit 3: You can do this to also translate the text (https://cloud.google.com/translate/docs/basic/translating-text):

curl -HAuthorization:Bearer\ $(gcloud auth application-default print-access-token) -HContent-Type:application/json -d@<(jq -sR '{q:.,target:"de"}'<<<example) https://translation.googleapis.com/language/translate/v2|jq -r '.data.translations[0].translatedText'

3
  • 1
    When using tesseract, you can avoid temporary file by using clipboard as a buffer and pngpaste from homebrew. screencapture -ic && pngpaste - | tesseract stdin stdout | tr -d \\f | pbcopy Feb 8, 2021 at 22:31
  • 1
    Also, if you don't want to use FastScripts, Automator with a "no input" "Quick Action" works. Make sure to export PATH=/usr/local/bin:$PATH for homebrew installed commands to work. Then set up a keybind in macOS "Keyboard" > "Shortcuts" > "Services". Feb 8, 2021 at 22:37
  • 1
    Using Google Cloud Vision API worked very well. Just remember to give your terminal app "Screen Recording" permission if you're testing at the command line. See script github.com/huyz/trustytools/blob/master/mac/screencap-ocr.sh
    – huyz
    Oct 17, 2021 at 19:30
3

TextSniper is another app that does screenshot OCR. It recognizes any text from screenshot and copies editable text to clipboard. Does not require internet connection and is lighting fast. Another great feature of TextSniper is that it can turn recognized text to speech, really helpful for people who have difficulties reading text from screen.

2

I recently purchased Condense ($5 appstore), which does exactly what you describe.

1
  • 1
    Appears to be gone as of 2021.
    – Stan James
    May 2, 2021 at 12:01
2

OWLOCR is a great app that do exactly what you want and much more.

0

I do it with LEADTOOLS OCR. Haven't used it much. Easy to use. Just used it on a smaller image... a screenshot of a book with both pages in the shot... this made the text smaller, contributing to errors.

Not sure if it's still available. The copyright on LEADTOOLS OCR is 1991-2014, and it is Version 2.

Good luck!

0

Easy Screen OCR for Mac is a free program that you can have a try.

2
  • Not available anymore apparently... Jun 4, 2019 at 12:13
  • 1
    It is still available. Just charge a little bit of money.
    – user174021
    Jun 5, 2019 at 13:15
0

You could set screencapture to save to a specific folder, then use Folder Actions to have that trigger an AppleScript, which simply sends your picture to your OCR software, either an app or command line.

Of course, this would send every screenshot to the app, which may not be ideal.

EDIT: Monterey now includes the ability to extra from images, which can be automated in Shortcuts.

-3

Here is a command to do it that easily does it

screencapture -i /tmp/tesseract.png; tesseract -l eng /tmp/tesseract.png /tmp/text\ document; open -R /tmp/text\ document.txt

Download tesseract here

https://formulae.brew.sh/api/formula/tesseract.json

1
  • 1
    How does this improve on existing answer
    – mmmmmm
    Apr 22, 2021 at 10:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .