summaryrefslogtreecommitdiffstats
path: root/public/.local/bin/screenshot_ocr.sh
diff options
context:
space:
mode:
authorMitsuo Tokumori <[email protected]>2024-09-11 04:25:38 +0900
committerMitsuo Tokumori <[email protected]>2024-09-11 04:25:38 +0900
commit37ff7062874b72bafa99afe661f42653565ed511 (patch)
tree60372bf7fdb94c9034c7d1cc5a17cd7df526c4fc /public/.local/bin/screenshot_ocr.sh
parentdca319b8d9d221f1aaf3a00ee457d202096c66ac (diff)
downloaddotfiles-37ff7062874b72bafa99afe661f42653565ed511.tar.gz
dotfiles-37ff7062874b72bafa99afe661f42653565ed511.tar.bz2
dotfiles-37ff7062874b72bafa99afe661f42653565ed511.zip
RESTRUCTURE. Replicate relative paths in public/
Diffstat (limited to 'public/.local/bin/screenshot_ocr.sh')
-rwxr-xr-xpublic/.local/bin/screenshot_ocr.sh29
1 files changed, 29 insertions, 0 deletions
diff --git a/public/.local/bin/screenshot_ocr.sh b/public/.local/bin/screenshot_ocr.sh
new file mode 100755
index 0000000..d88accf
--- /dev/null
+++ b/public/.local/bin/screenshot_ocr.sh
@@ -0,0 +1,29 @@
+#!/bin/bash
+
+# Select a region of the screen and perform OCR to it. Save text in clipboard.
+
+savepath="/tmp/screenshot_ocr.sh.d"
+filename="$HOSTNAME-$(date -Iseconds | tr -d ':-').png"
+# German: deu, Spanish: spa, Japanese vertical: jpn_vert
+tesseract_options="-l eng+jpn"
+
+_init() {
+ if [ ! -d "$savepath" ]; then
+ mkdir -p "$savepath"
+ fi
+ cd "$savepath"
+}
+
+_init
+# Screenshot region of screen
+shotgun -g $(hacksaw) "$filename"
+# Exit if previous command was unsuccessful
+test $? -ne 0 && exit
+# Try to scan codes from the image
+zbarimg $filename | xclip -selection "clipboard"
+# Perform OCR and save to clipboard
+tesseract $tesseract_options $filename - | xclip -selection "clipboard"
+rm $filename
+
+# TODO: clean japanese output. If text is 80% japanese characters, then it
+# should not contain spaces around the characters.