jtheoof / swappy

A Wayland native snapshot editing tool, inspired by Snappy on macOS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

OCR Support

geekodour opened this issue · 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.

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

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

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