Skip to content

Commit

Permalink
training: Add new flag --workspace_dir to tesstraining_utils.sh
Browse files Browse the repository at this point in the history
By default, that script creates two new temporary directories with random
names in /tmp.

The new command line flag --workspace_dir PATH uses the given path as
a base directory for all temporary files.

That allows better reproducable training results (no random directory
names in log files).

Signed-off-by: Stefan Weil <[email protected]>
  • Loading branch information
Stefan Weil authored and stweil committed Jul 26, 2018
1 parent fbff323 commit b19e690
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/training/tesstrain_utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@

if [ "$(uname)" == "Darwin" ];then
FONTS_DIR="/Library/Fonts/"
FONT_CONFIG_CACHE=$(mktemp -d -t font_tmp.XXXXXXXXXX)
else
FONTS_DIR="/usr/share/fonts/"
FONT_CONFIG_CACHE=$(mktemp -d --tmpdir font_tmp.XXXXXXXXXX)
fi
OUTPUT_DIR="/tmp/tesstrain/tessdata"
OVERWRITE=0
Expand Down Expand Up @@ -148,6 +150,13 @@ parse_flags() {
--wordlist)
parse_value "WORDLIST_FILE" ${ARGV[$j]}
i=$j ;;
--workspace_dir)
rmdir "$FONT_CONFIG_CACHE"
rmdir "$WORKSPACE_DIR"
parse_value "WORKSPACE_DIR" ${ARGV[$j]}
FONT_CONFIG_CACHE=$WORKSPACE_DIR/fc-cache
mkdir -p $FONT_CONFIG_CACHE
i=$j ;;
*)
err_exit "Unrecognized argument ${ARGV[$i]}" ;;
esac
Expand Down Expand Up @@ -192,11 +201,7 @@ parse_flags() {

# Function initializes font config with a unique font cache dir.
initialize_fontconfig() {
if [[ "$OSTYPE" == "darwin"* ]]; then
export FONT_CONFIG_CACHE=$(mktemp -d -t font_tmp.XXXXXXXXXX)
else
export FONT_CONFIG_CACHE=$(mktemp -d --tmpdir font_tmp.XXXXXXXXXX)
fi
export FONT_CONFIG_CACHE
local sample_path=${FONT_CONFIG_CACHE}/sample_text.txt
echo "Text" >${sample_path}
run_command text2image --fonts_dir=${FONTS_DIR} \
Expand Down

0 comments on commit b19e690

Please sign in to comment.