swappy icon indicating copy to clipboard operation
swappy copied to clipboard

OCR Support

Open geekodour opened this issue 2 years ago • 3 comments

First of all, thankyou for making this! I have been using grim, slurp and snappy with great success for the last year or so.

It's almost perfect but I always miss the functionality of extracting the text out of the image, which is possible with tools like https://shottr.cc/ on mac.

I was wondering if you'd want to extend swappy to have that sort of a feature or rather keep things simple? I have never worked with OCR directly but since this is a feature I'd like, I can probably work on it if there's interest.

geekodour avatar Apr 01 '23 13:04 geekodour

Thanks. I would rather keep things simple for now. but leaving this open and we'll see if there is interest.

jtheoof avatar Apr 02 '23 12:04 jtheoof

For anyone visiting this later,

Found an easy solution for my usecase, which does not involve swappy but does the trick unless you really want the output inside swappy. Just need to install tesseract for your distribution and good to go.

grim -g $(slurp) - | tesseract stdin stdout | wl-copy

geekodour avatar Apr 02 '23 14:04 geekodour

I wrote it in this way

ocr.sh

yad

#!/bin/bash
lang=${1:-eng}
img=$(mktemp -u --suffix=.png)
grim -g "$(slurp)" "$img" &&
tesseract -l "$lang" "$img" stdout |
yad --text-info --title="OCR - $lang" --editable --wrap --show-uri --width=500 --height=500 |
wl-copy

foot+nvim

#!/bin/bash
lang=${1:-eng}
img=$(mktemp -u --suffix=.png)
grim -g "$(slurp)" "$img" &&
tesseract -l "$lang" "$img" stdout > "$img.txt" &&
foot --app-id=ocr nvim "$img.txt" &&
wl-copy < "$img.txt" &&
notify-send -t 3000 'OCR Copied!'

tkna91 avatar Oct 21 '23 15:10 tkna91