splitall 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/usr/bin/env bash
  2. set -e
  3. set -u
  4. colordetect='colordetect --hue 180 --min-value 80 --param2 20 --coordinates - --cut-left 30% --cut-right 30% --cut-top 10% --cut-bottom 10% --min-dist 10% --min-radius 1% --max-radius 6%'
  5. imagecut=imagecut
  6. [[ -f /etc/bookscanner/splitall.rc ]] && source /etc/bookscanner/splitall.rc
  7. usage() {
  8. echo "Usage: $0 DIRECTORY"
  9. echo "The 'first' file is the split-calibration. Every other file is split"
  10. }
  11. if [[ $# -ne 1 ]]; then
  12. usage >&2
  13. exit 2
  14. fi
  15. dir=$(readlink -f $1)
  16. shift 1
  17. calibrate() {
  18. if [[ ! -f "$dir/split.txt" ]]; then
  19. splitcalibration=$(ls -1 "$dir"| sort| head -n1)
  20. $colordetect "$dir/$splitcalibration" > "$dir/split.txt"
  21. fi
  22. }
  23. counter=0
  24. split() {
  25. [[ $# -eq 1 ]]
  26. imgtosplit="$1"
  27. [[ -f "$imgtosplit" ]]
  28. $imagecut "$dir/split.txt" "$imgtosplit" --outfile "$dir/split/$(printf %03d $counter).jpg"
  29. [[ -f "$dir/split/$(printf %03d $counter).L.jpg" ]]
  30. [[ -f "$dir/split/$(printf %03d $counter).R.jpg" ]]
  31. counter=$((counter+1))
  32. }
  33. calibrate
  34. mkdir "$dir/split/"
  35. ls -1 $dir/*.jpg | sort | tail -n +2 | while read fname; do
  36. split "$fname"
  37. done
  38. exit 0