goldendict-ng/website/docs/howto/ocr.md
shenleban tongying 65ebdf0e4c
doc: updates
* use repology.org to replace manually created linux package list [0]
* update debian/ubuntu dependencies (delete outdated fedora one)
* update all build doc to qt6
* add cmake flags info
* merge all build instructions into one
* add more ocr examples
* add links and fix dictionary formats info
* misc
2023-07-06 01:23:51 -04:00

3.1 KiB

Current Situation

GoldenDict offered a functionality to translate the word under cursor on Windows in the past, but the technique used there is old and does not work crossplatformly.

However, any OCR program that allow you to set "after capturing action" can be easily used in conjunction with GoldenDict.

A few examples are provided below, but there are many options:

Capture2Text

Capture2Text can call executable after capturing, and you can set the executable to GoldenDict.

Detailed usage document: Capture2Text

For example, change the Output action Call Executable to path_to_the_GD_executable\GoldenDict.exe "${capture}"

Then press Win+Q and select a region. After capturing a word, Capture2Text will forward the word to GoldenDict. If GoldenDict's scanpopup is enabled, it will show up.

image

The hotkeys can be configured:

image

Capture2Text can also obtain word near cursor without selecting a region via the "Forward Text Line Capture" by pressing Win+W

you may want to enable "First word only" so that only a single word would be captured

image

Use Capture2Text on Linux

Capture2Text does not have Linux version, but I have ported it to Linux https://github.com/xiaoyifang/Capture2Text thanks to Capture2Text Linux Port and sikmir.

2022-01-30 15-54-35屏幕截图

Shortcuts.app & Apple's OCR

Enable the Clipboard monitoring of GoldenDict, then create a "Shorcut" that will interactively take screnshot and change the clipboard.

image

You may also add additional capiblities like only getting the first word

image

Tesseract via command line

On Linux, you can combine command line screenshot then pass the output image to Tesseract then pass the text result to goldendict

Example with spectacle (KDE) and grim (wayland/wlroots)

#!/usr/bin/env bash

set -e

case $DESKTOP_SESSION in
    sway)
        grim -g "$(slurp)" /tmp/tmp.just_random_name.png
    ;;
    plasmawayland | plasma)
        spectacle --region --nonotify --background \
        --output /tmp/tmp.just_random_name.png
    ;;
    *)
        echo "Failed to know desktop type"
        exit 1
    ;;
esac

# note that tesseract will apppend .txt to output file
tesseract /tmp/tmp.just_random_name.png /tmp/tmp.just_random_name --oem 1  -l eng

goldendict "$(cat /tmp/tmp.just_random_name.txt)"

rm /tmp/tmp.just_random_name.png
rm /tmp/tmp.just_random_name.txt