Hacker News new | ask | show | jobs
by rjzzleep 1302 days ago
This looks like a nice app. I was looking for something like this a while back until I noticed that there are "one" liners that can you can setup for a hotkey:

    #!/usr/bin/env bash
    langs=(eng ara fas chi_sim chi_tra deu ell fin heb hun jpn kor nld rus tur)
    lang=$(printf '%s\n' "${langs[@]}" | dmenu "$@")
    maim -us | tesseract --dpi 145 -l eng+${lang} - - | xsel -bi
4 comments

Nice! Didn't know about maim. This looks better than what I currently use (found it somewhere on the internet).

  #!/bin/bash
  SRC_IMG=$(mktemp -u /tmp/ocr_XXXXXXXXX.png)
  scrot --select "$SRC_IMG" -q 100
  mogrify -modulate 100,0 -resize 400% "$SRC_IMG"
  tesseract "$SRC_IMG" "$SRC_IMG" &> /dev/null
  OCR_RESULT=$(cat "$SRC_IMG.txt")
  echo "$OCR_RESULT"
  notify-send "$OCR_RESULT"
  xsel -bi < "$SRC_IMG.txt"
I mean don't scrot and maim do the same? It can write to stdout as well. Is the resize really worth it?
Tesseract get's significanlty better results after resize; can probably get away with a 2x resize on a 4k monitor, but 4x is good for e.g. 1200p
Nice, that is great! I adapted this to work for me on wayland (sway):

grim -g "$(slurp)" - | tesseract --dpi 145 -l eng+${lang} - - | wl-copy

Using grim to take a screenshot, slurp to mark a region on your screen and wl-copy to copy to clipboard.

I wonder if it's possible to auto-detect the language. Meaning, instead of the priority list, it finds out the most probable language a script belongs to in the first sweep.
yeah, i have a script almost identical to this that i've been using with i3 for a long time