-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlegacytraining.sh
More file actions
90 lines (68 loc) · 2.45 KB
/
Copy pathlegacytraining.sh
File metadata and controls
90 lines (68 loc) · 2.45 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/bash
FONT="LEGO Hatting AM"
FONTS_DIR="/home/dk8prina/fonts"
TRAINING_DIR="/mnt/c/Users/dk8PriNa/LEGO/Image-test/src/output/synthetic_samplesv1v2Ver2"
TEXT_DIR="/mnt/c/Users/dk8PriNa/LEGO/Image-test/src/output/synthetic_samplesv1v2Ver2/training_text.txt"
TESSDATA="/usr/share/tesseract-ocr/5/tessdata"
OUTPUT_MODEL="Hattingam_legacyV1V2_Ver2"
RESOLUTION=300
NUM_IMAGES=100
cd "$TRAINING_DIR" || exit 1
# for ((i=50; i<NUM_IMAGES; i++)); do
# text2image \
# --text "$TEXT_DIR" \
# --outputbase "$TRAINING_DIR/A_${i}" \
# --font="$FONT" \
# --fonts_dir="$FONTS_DIR" \
# --ptsize $((20 + RANDOM % 20)) \
# --resolution $RESOLUTION \
# --fontconfig_tmpdir=/tmp
# cp "$TEXT_DIR" "$TRAINING_DIR/A_${i}.gt.txt"
# done
find "$TRAINING_DIR" -type f -name "*.tr" -size 0c -delete
echo "Generating .box and .tr files..."
find "$TRAINING_DIR" -type f -name "*.tif" | while read -r img; do
base=$(basename "$img" .tif)
dir=$(dirname "$img")
gt_file="$dir/$base.gt.txt"
if [[ -f "$gt_file" && -s "$img" ]]; then
echo "Processing $img"
tesseract "$img" "$dir/$base" --psm 6 box.train
else
echo "Skipping $img (missing $gt_file or empty image)"
fi
done
BOX_FILES=$(find "$TRAINING_DIR" -type f -name "*.box" -size +0c)
TR_FILES=$(find "$TRAINING_DIR" -type f -name "*.tr" -size +0c)
if [[ -z "$BOX_FILES" ]]; then
echo "Error: No valid .box files found! Training aborted."
exit 1
fi
echo "Getting unicharset"
unicharset_extractor $BOX_FILES
echo "Getting the font properties"
echo "$OUTPUT_MODEL 0 0 0 0 0" > font_properties
echo "Creating the shapeclustering file"
shapeclustering -F font_properties -U unicharset $TR_FILES
echo "Running mftraining"
mftraining -F font_properties -U unicharset -O unicharset $TR_FILES
if [[ -z "$TR_FILES" ]]; then
echo "Error: No valid .tr files found! Training aborted."
exit 1
fi
for tr in $TR_FILES; do
if ! grep -q "TrainingPage" "$tr"; then
echo "Invalid TR file: $tr"
fi
done
echo "Running cntraining"
cntraining $TR_FILES
echo "Renaming output files..."
mv inttemp "$OUTPUT_MODEL.inttemp"
mv normproto "$OUTPUT_MODEL.normproto"
mv pffmtable "$OUTPUT_MODEL.pffmtable"
mv shapetable "$OUTPUT_MODEL.shapetable"
mv unicharset "$OUTPUT_MODEL.unicharset"
echo "Combining into .traineddata..."
combine_tessdata "$OUTPUT_MODEL."
echo "✅ Legacy training completed! Model saved as $OUTPUT_MODEL.traineddata"