#!/bin/bash # test script to apply filters to all files in a directory # author: Rostislav Lán # activate virtual environment source .venv/bin/activate #----------------------------Settings------------------------------# # place all image files to one folder input_path=res/test/ZK10R/p* exec_path=src/main.py # 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 # name of configuration file config_file=config/config-test.json # name of preset in conf. file #presets=("strong" "test-weak" "test-repeat" "test-strong") presets=("test-very-strong") generate_stl=false #----------------------------Application---------------------------# # function to apply filter to all files in directory apply_filter() { for file in ${file_arr[@]} do if test -f "$file" 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 ((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 else python3 $exec_path $in $out $dpi -c $config_file $1 || break fi else echo "File $file does not exist" fi done } # for pattern matching in filenames match1=. match2=/ i=0 j=0 file_arr=() # get all filenames in all directories for file in $input_path/* do file_arr=("${file_arr[@]}" "$file") done # apply all given presets to all the files for preset in ${presets[@]} do 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"