forked from linfan/opencv-text-detect
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtext-detect.sh
More file actions
executable file
·29 lines (25 loc) · 907 Bytes
/
text-detect.sh
File metadata and controls
executable file
·29 lines (25 loc) · 907 Bytes
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
#!/bin/bash
if [ "${1}" = "" ]; then
echo 'Usage: ./text-detect.sh <image-path>'
exit -1
fi
if [ "${2}" != "" ]; then
OUT_BASE_FOLDER="${2%%/}/" # remove ending '/' and put another '/'
fi
FILE_PATH=${1}
OUT_FOLDER=${OUT_BASE_FOLDER}`basename ${FILE_PATH%.*}`
IMAGE_FORMAT=${FILE_PATH##*.}
echo "Read image: ${FILE_PATH}"
echo "Write folder: ${OUT_FOLDER}"
rm -fr ${OUT_FOLDER}
python3 text_detect_wrap.py ${FILE_PATH} ${OUT_FOLDER}
for part in `ls ${OUT_FOLDER}/part-*.jpg`; do
num=${part##*-}
tesseract ${part} ${OUT_FOLDER}/result-${num} --oem 1 --psm 13
cat ${OUT_FOLDER}/result-${num}.txt >> ${OUT_FOLDER}/result.txt
done
cat ${OUT_FOLDER}/result.txt | sed -e 's/^[^a-zA-Z0-9]*//' -e 's/[^a-zA-Z0-9]*$//' > ${OUT_FOLDER}/result.trim.txt
echo "---- RESULT ----"
cat ${OUT_FOLDER}/result.trim.txt
echo "----------------"
cp ${FILE_PATH} ${OUT_FOLDER}/origin.${IMAGE_FORMAT}