-
Notifications
You must be signed in to change notification settings - Fork 0
/
ocrshot
executable file
·46 lines (32 loc) · 1.4 KB
/
ocrshot
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env bash
## OCRSHOT
## Simple bash script that allows you to copy-and-paste text via Optical Character Recognition
### After calling 'ocrshot', your cursor will be used to select an area of your screen to screenshot
### After this screenshot is taken, it's run through Tesseract to read the text inside it
### And that text, finally, is copied to your clipboard (ctrl+v to paste)
### Calling 'ocrshot -i' will do the same thing but also invert the colors of the screenshot before pushing it to Tesseract.
### This is best if you use a dark theme
### (A dark background with light text should be inverted to a light background with dark text for Tesseract)
#### Depends:
#### gnome-screenshot
#### xclip
#### tesseract
#### imagemagick
##### IMO, this is useful for copying-and-pasting text from videos or photos, as well as from Google Docs et al services which go through great lengths to prevent ctrl+c ctrl+v
##### Also IMO, it's most useful when tied to a quick&easy keyboard shortcut
inverting=false
temporary_file_name=$(mktemp).png
while getopts i flag
do
case "${flag}" in
i) inverting=true;;
*) ;;
esac
done
gnome-screenshot -a -f "$temporary_file_name"
if [[ $inverting == true ]]; then
convert "$temporary_file_name" -negate "$temporary_file_name"
fi
ocr_output=$(tesseract -c page_separator='' "$temporary_file_name" -)
echo -n "$ocr_output" | xclip -sel clip
rm "$temporary_file_name"