ubuntuusers.de

Google Lens For Ubuntu script läuft nicht richtig

Status: Gelöst | Ubuntu-Version: Ubuntu 22.04 (Jammy Jellyfish)
Antworten |

fenster

Anmeldungsdatum:
18. März 2022

Beiträge: 40

script läuft nicht richtig

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash

# Dependencies: tesseract-ocr, imagemagick, (grim, slurp[Sway]), spectacle[KDE], gnome-screenshot[GNOME], wl-clipboard, libnotify-bin

# Add more if you need other languages. Example: eng+ita
tesseract_lang=eng

SCR_IMG=$(mktemp)

notify() {
    notify-send "OCR Script" "$1"
}

take_screenshot() {
    case "$XDG_CURRENT_DESKTOP" in
        KDE)
            spectacle --region --background --nonotify --output "$SCR_IMG"
            ;;
        GNOME)
            gnome-screenshot -a -f "$SCR_IMG"
            ;;
        *)
            grim -g "$(slurp)" "$SCR_IMG"
            ;;
    esac
}

trap 'rm -f "$SCR_IMG"*' EXIT

take_screenshot

notify "Processing image for text extraction..."

# Enhance the image for better OCR
mogrify -modulate 100,0 -resize 400% "$SCR_IMG"

# Performs the OCR on the screenshot
tesseract "$SCR_IMG" "$SCR_IMG" -l "$tesseract_lang" &> /dev/null

# Copy OCR result to clipboard
wl-copy < "${SCR_IMG}.txt"

notify "Text successfully copied to clipboard."


# https://gist.github.com/mnofresno/25d0cc6a45aa8644596705c78382304e

# https://gist.github.com/mnofresno/25d0cc6a45aa8644596705c78382304e?permalink_comment_id=5094040
aaa@aaa-System-Product-Name:/bin/lens$ ./lens
compositor doesn't support zwlr_layer_shell_v1
invalid geometry
mogrify-im6.q16: no decode delegate for this image format `YZRXCOQZVJ' @ error/constitute.c/ReadImage/580.
aaa@aaa-System-Product-Name:/bin/lens$ 

Moderiert von rklm:

Ins passende Forum

haveaproblem

Anmeldungsdatum:
2. Januar 2015

Beiträge: 1164

Unter Ubuntu ist der XDG_CURRENT_DESKTOP ubuntu:GNOME und nicht GNOME, also die Zeile 19 anpassen.

Und gnome-screenshot kann den entpsrechenden Screenshot unter 24.04 nicht mal speichern, weil es davon ausgeht das mktemp eine korrekte Endung ausgibt, Zeile 9 muss also auch zu

SCR_IMG="${mktemp}.png"

angepasst werden.

Keine Ahnung, warum das in einem Script so ist, was explizit "for Ubuntu" erstellt ist. Das ganze ist auch nur mehr oder weniger gut funktionierendes OCR, hat also mit Google Lens nicht viel zu tun. Außer das OCR EIN Feature von Google Lens ist.

Hier nochmal das volle editierte laufende Script, für einfaches Copy + Paste

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash

# Dependencies: tesseract-ocr, imagemagick, (grim, slurp[Sway]), spectacle[KDE], gnome-screenshot[GNOME], wl-clipboard, libnotify-bin

# Add more if you need other languages. Example: eng+ita
tesseract_lang=eng

SCR_IMG="${mktemp}.png"

notify() {
    notify-send "OCR Script" "$1"
}

take_screenshot() {
    case "$XDG_CURRENT_DESKTOP" in
        KDE)
            spectacle --region --background --nonotify --output "$SCR_IMG"
            ;;
        GNOME)
            gnome-screenshot -a -f "$SCR_IMG"
            ;;
	ubuntu:GNOME)
            gnome-screenshot -a -f "$SCR_IMG"
            ;;
        *)
            grim -g "$(slurp)" "$SCR_IMG"
            ;;
    esac
}

trap 'rm -f "$SCR_IMG"*' EXIT

take_screenshot

notify "Processing image for text extraction..."

# Enhance the image for better OCR
mogrify -modulate 100,0 -resize 400% "$SCR_IMG"

# Performs the OCR on the screenshot
tesseract "$SCR_IMG" "$SCR_IMG" -l "$tesseract_lang" &> /dev/null

# Copy OCR result to clipboard
wl-copy < "${SCR_IMG}.txt"

notify "Text successfully copied to clipboard."


# https://gist.github.com/mnofresno/25d0cc6a45aa8644596705c78382304e

# https://gist.github.com/mnofresno/25d0cc6a45aa8644596705c78382304e?permalink_comment_id=5094040

rklm Team-Icon

Projektleitung

Anmeldungsdatum:
16. Oktober 2011

Beiträge: 13257

Ich würde oben auch noch ein set -e einfügen, um Folgefehler zu vermeiden. Zum Debuggen davor benutze ich gerne die Umgebungsvariable DEBUG, die set -x schaltet:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#!/bin/bash

# Dependencies: tesseract-ocr, imagemagick, (grim, slurp[Sway]), spectacle[KDE], gnome-screenshot[GNOME], wl-clipboard, libnotify-bin

[ -z "$DEBUG" ] || set -x

set -e

# Add more if you need other languages. Example: eng+ita
tesseract_lang=eng

SCR_IMG="${mktemp}.png"

notify() {
    notify-send "OCR Script" "$1"
}

...
Antworten |