OCR Image - Your Experiences with Text Recognition

Before you run the macro, check your Clipboard History Switcher, and verify that the image is in the clipboard as expected, and has not been replaced by some text or something else.

Then use the built in OCR Image macro (via the gear menu on the image entry in the Clipboard History Switcher).

Okay, this is interesting.

  1. I copy a part of the screen with Command-Shift-4 to the clipboard.
  2. I see this part when I switch to the Finder and use the “Show clipboard” command.
  3. But the Clipboard History Switcher remains empty. No image.

Then:

  1. When I open Preview and choose “New from clipboard” (or similar, I use the german localization), I can see the image.
  2. When I copy this image with Command-A and Command-C, it appears immediately in the Clipboard History Switcher and the OCR command behind the gear icon works as expected.

Is this useful?

It's fantastic to have OCR built into Keyboard Maestro 9, and it's using 'Tesseract', the open-source OCR engine I'd previously hacked into some of my shortcuts using shell commands.

I've got a pattern and whitelist that I'd previously used with Tesseract to OCR SMPTE timecodes, and I'd love to be able to use this as a custom language inside Keyboard Maestro's OCR step. Is there any way to do this? I did some searching and tried plopping them into ~/Library/Application\ Support/Keyboard\ Maestro/Tesseract\ Trained\ Data/Custom, but that doesn't seem to have had any effect. I've attached those customization files in case anyone wants to try to get them to work.

timecode_for_tesseract.zip (2.3 KB)

Hi,

Wow! I made a few tests in Japanese and it works very well. :slight_smile:

One problem, though, is that it works mainly for horizontal text.
I checked for a solution in Tesseract’s documentation, and it says that this option is available for vertical text recognition:
tesseract-ocr-jpn-vert

It would then be great to have the two choices in the macro menu:
tesseract-ocr-jpn for horizontal text
tesseract-ocr-jpn-vert for vertical text

1 Like

I can't seem to duplicate this, but I do think I saw that sort of behaviour when I was testing something earlier, so it is possible there is a bug somewhere with the clipboard switcher display.

1 Like

Just should be able to do it, but the file must be in aTesseract .traineddata file (and don't ask me what the format of that is or how you generate one, as I have no idea).

Currently the vert files are deliberately disabled, because frankly I don't understand them.

It may be that I can just enable them and they will just work for you.

If you can grab the Japanese_vert.traineddata file, rename it to something like JapaneseVert.traineddata and put it in the Custom folder, it might “just work” - if so, let me know and I'll see what I can do about enabling them going forward.

Peternlewis: f you can grab the Japanese_vert.traineddata file, rename it to something like JapaneseVert.traineddata and put it in the Custom folder

Hi. I tried, but it doesn’t work. I will keep searching/trying and tell you if I find a solution.

Works like a charm. Thanks.

FWIW I love the new OCR capability. So helpful for grabbing text from images etc. I have mine mapped to ⌘⌥⌃⇧4 to keep similar muscle memory as ⌘⇧4 for a grabbed screenshot.

1 Like

If I successfully make the traineddata file, how do I make it usable for KM9? Is there an install location? The location in this post doesn't exist on my system.

Thanks!

You can get to ~/Library in the Finder by holding down the shift (or option) key and selecting Library from the Go menu in the Finder.

~/Library/Application Support/Keyboard Maestro/Tesseract Trained Data/Custom
2 Likes

I am having same issue, frequently. The OCR Clipboard action is basically useless for me.

I have found the KM provided OCR engine to be excellent, yielding accurate results 99% of the time. I'm running Keyboard Maestro 9.0.5 on macOS 10.14.6 (Mojave).

I use this macro:

MACRO: OCR -- User-Selected Area

JMTX,

I have the same experience as you do. I use this feature on countless use cases. From Webcast conference note taking, to working around the VPN Citrix copy and paste limitations of my job, to quick and simple searches using the @ccstone macro that you modified. At first I didn't use it because I just didn't understand a use case for it. Now, I must have 10 different implementations for it. It's beautiful.

I agree that the OCR action works well. I should have clarified that the problem I was having, and still have, is that screenshotting using standard MacOS keyboard shortcuts is not sending the captured image to the clipboard for the OCR action to use. That must be a MacOS bug.

Thank you so much for the macro by @ccstone. And thank you @ccstone for making it. The command line script does send the screenshotted image to a clipboard usable by the OCR action. I don't understand why or how, but this works just as well as I could have hoped.

2 Likes

Hi from 2021 :),
Thank for for this macro, though, I'm having trouble with it.
For comparison I used iText (an app on the app store). The maestro macro is much lower quality. Other's who replied here are reporting good results. I'm wondering if I'm missing something?


OCR using the macro:

"We are storytelling
CTT Me TCR)
we acquire language to tell
HR Cem LAM IEE
inside us."

Eee asc

OCR using iText:

"We are storytelling creatures and as children we acquire language to tell those stories that we have inside us. "

-- Jerome Bruner


___ = RichShot2021-6-12at23.45.29

1 Like

Looks very interesting. for details, see iText - OCR Tool | Toolinbox
The free version allows 20 images/month. good enough for testing.

1 Like

Hi @leland, I myself use Snagit 2021 (Abbyy FineReader integrated) in combination with KM macros for this.

Video

The advantage is a very good text recognition and I can still access the screenshots later.
Since I often have to translate something into another language, I can transfer the captured text from the clipboard to the online translator DeepL.
The advantage here is that I can still add or correct the text to be translated.

1 Like

I am a big SnagIT user for many years, and have tried its OCR Grab Text a number of times.
For almost all of these use cases the KM OCR provided better results.
I am curious to see how iText OCR will perform.

1 Like