-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathocr-scan
executable file
·75 lines (67 loc) · 1.27 KB
/
ocr-scan
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/data/data/com.termux/files/usr/bin/bash
set -e -u
SCRIPTNAME=ocr-scan
show_usage () {
echo "Usage: $SCRIPTNAME [-e] [-s] [-f filename]"
echo "Recognizes text on an image to copy or share results"
echo ""
echo " -f Use specified file"
echo " -c Copy results to clipboard"
echo " -e Echo results"
echo " -s Share detected text"
echo ""
exit 0
}
FILE=''
COPY=false
ECHO=false
SHARE=false
DELETE=false
for i in "$@"
do
case $i in
-h|--help)
show_usage
exit 0
;;
-c|--copy)
COPY=true
;;
-e|--echo)
ECHO=true
;;
-s|--share)
SHARE=true
;;
*)
if [ -f "$i" ]; then
FILE=$i
fi
;;
esac
done
if [ "x$FILE" == "x" ]; then
DELETE=true
FILE='./ocr.jpg'
termux-camera-photo -c 0 $FILE
fi
tesseract "$FILE" ocr
OUTPUT=`cat ocr.txt`
rm ocr.txt
if [ "x$OUTPUT" != "x" ]; then
if [ $COPY == true ]; then
termux-clipboard-set "$OUTPUT"
termux-toast "Output copied to clipboard"
elif [ $SHARE == true ]; then
echo $OUTPUT | termux-share
elif [ $ECHO == true ]; then
echo $OUTPUT
else
termux-toast "$OUTPUT"
fi
else
echo "No text found"
fi
if [ $DELETE == true ]; then
rm -f $FILE
fi