jtheoof / swappy

A Wayland native snapshot editing tool, inspired by Snappy on macOS
MIT License
1k stars 40 forks source link

OCR Support #145

Open geekodour opened 1 year ago

geekodour commented 1 year ago

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.

jtheoof commented 1 year ago

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

geekodour commented 1 year ago

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
tkna91 commented 11 months ago

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!'