Added parsing utility for stl files, updated test script.

master
Rostislav Lán 2 years ago
parent bd087c2503
commit c484011200

@ -0,0 +1,59 @@
"""! @file main.py
@brief Utility for parsing STL file header
@author xlanro00
"""
# Import basic libraries
import argparse as ap
import sys
from os.path import exists
def main():
""" Main function
Parses stl file header to get info about generated fingerprint.
"""
# Parse arguments
parser = ap.ArgumentParser(description='Command line utility for parsing fingerprint STL file header')
parser.add_argument('file', type=str, help='STL file')
args = parser.parse_args()
# Check if file exists
if not exists(args.file):
sys.stderr.write('Error: File does not exist')
sys.exit(1)
with open(args.file, "rb") as f:
header = f.read(80).decode('UTF-8')
#print(header, file=sys.stderr)
header = header.split('\n')[0]
header_arr = header.split('\\')
input_file = header_arr[0]
dpi = header_arr[1]
if exists(header_arr[2]):
config = header_arr[2]
preset = header_arr[3]
else:
filters = header_arr[2]
mode = header_arr[-1]
if (mode == "P"):
height_base = header_arr[-2]
height_line = header_arr[-3]
print(input_file, dpi, config, preset, mode,
height_base, height_line, sep='\n')
elif (mode == "C"):
curv_rate_y = header_arr[-2]
curv_rate_x = header_arr[-3]
height_base = header_arr[-4]
height_line = header_arr[-5]
print(input_file, dpi, config, preset, mode,
height_base, height_line, curv_rate_x, curv_rate_y, sep='\n')
elif (mode == "M"):
pass
sys.exit(1)
main()

@ -2,52 +2,80 @@
# test script to apply filters to all files in a directory
# author: Rostislav Lán
# activate virtual environment
# activate virtual environment when using this script
# this is necessary to run the script using the correct python and libraries versions
source .venv/bin/activate
#----------------------------Settings------------------------------#
#----------------------------Configuration------------------------------#
# place all image files to one folder
input_path=res/test/ZK10R/p*
exec_path=src/main.py
input_path=res/test/test-skript
# this is very important, run this on directories containing files with the same dpi!!!!!!!!!!!!!!!!!!
# !!!!!!!!!!!!!!!!!!
# this is very important, run this on directories containing files with the same dpi
dpi=500
# !!!!!!!!!!!!!!!!!!
# reccomend png, it's supported by opencv
format=png
# recommend png, it's supported by opencv
format=jpg
# name of configuration file
config_file=config/config-test.json
config_file=conf/conf.json
# name of preset in conf. file
#presets=("strong" "test-weak" "test-repeat" "test-strong")
presets=("test-very-strong")
presets=("ridge" "weak")
# generate stl files and set generation mode {"planar", "curved", "mapped"}
generate_stl=true
generate_stl_mode="planar"
generate_stl=false
# in 1/10 of milimeters
height_line=2
height_base=3
curv_x=1.5
curv_y=4
#----------------------------Application---------------------------#
# function to apply filter to all files in directory
apply_filter() {
for file in ${file_arr[@]}
for in in ${file_arr[@]}
do
if test -f "$file"
# check that the file exists
if test -f "$in"
then
in=$file
out="${in%%${match1}*}_$preset${match1}$format"
# check if file already has one of the filter names in it
#if [[ " ${presets[*]} " =~ " ${preset} " ]]; then
# ((j++))
# continue
#fi
# append preset name to filename for easier identification, if not generating stl (that would result in very long names)
if $generate_stl; then
out="${in%%${match1}*}${match1}$format"
else
out="${in%%${match1}*}_$preset${match1}$format"
fi
# skip stl files and files with preset name in them
if [[ $in == *".stl"* ]] || [[ $in == *_* ]]; then
((j++))
continue
fi
((i++))
echo "File no. $i: $in"
if [[ "$generate_stl" = true ]]; then
echo "Generating STL"
echo $in
python3 $exec_path $in $out $dpi -c $config_file $1 --stl "${in%%${match1}*}_$preset${match1}stl" 3 10 -p || break
echo -e "|\n|----------------------- File no. $i: $in ------------------------------|\n"
if $generate_stl; then
((i++))
if [[ "$generate_stl_mode" = "planar" ]]; then
python3 $exec_path $in $out $dpi -c $config_file $1 --stl p $height_line $height_base || break
elif [[ "$generate_stl" = "curved" ]]; then
python3 $exec_path $in $out $dpi -c $config_file $1 --stl c $height_line $height_base $curv_x $curv_y || break
elif [[ "$generate_stl" = "mapped" ]]; then
pass
python3 $exec_path $in $out $dpi -c $config_file $1 --stl m $height_line $height_base $fp_file|| break
else
echo "Invalid stl generation mode"
break
fi
else
python3 $exec_path $in $out $dpi -c $config_file $1 || break
fi
@ -59,26 +87,27 @@ apply_filter() {
}
# for pattern matching in filenames
exec_path=src/main.py
match1=.
match2=/
i=0
j=0
file_arr=()
# get all filenames in all directories
# get all filenames in all subdirectories
for file in $input_path/*
do
file_arr=("${file_arr[@]}" "$file")
done
# apply all given presets to all the files
# apply all given filter presets to all the discovered files
for preset in ${presets[@]}
do
echo -e "\n|-----------------------Filter "$preset"------------------------------|\n"
echo -e "\n|----------------------- Filter "$preset" ------------------------------|\n|"
j=0
apply_filter $preset $j
if [ ! "$j" -eq "0" ]; then
echo -e "Skipped $j files"
fi
done
echo "Processed $i files"
echo -e "\n|--------------------------- Done ----------------------------------|\n"
echo "Skipped $j files"
echo "Generated $i files"
Loading…
Cancel
Save