You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.2KB

  1. #!/bin/bash
  2. usage () {
  3. echo "$0: [-n] <source directory> <target directory>"
  4. echo
  5. echo "Convert filenames to appropriate format for training"
  6. echo
  7. echo "-n Dry run"
  8. exit 1
  9. }
  10. DRY_RUN=0
  11. while getopts "nh" arg; do
  12. case $arg in
  13. h)
  14. usage
  15. ;;
  16. n)
  17. DRY_RUN=1
  18. ;;
  19. esac
  20. done
  21. shift $((OPTIND-1))
  22. if [[ "$#" != "2" ]]
  23. then
  24. echo "error: Missing directory parameters."
  25. echo "See -h for help"
  26. exit 1
  27. fi
  28. IN=$1;shift
  29. OUT=$1;shift
  30. mkdir -p $OUT/{images,labels}
  31. for dir in $(for dir in $IN/*; do basename "$dir"; done)
  32. do
  33. for file in $IN/$dir/*.orig.jpg
  34. do
  35. if [[ "$DRY_RUN" == "1" ]]
  36. then
  37. echo cp -a --reflink=auto $file $OUT/images/"$dir"_"$(basename $file|sed 's/\.orig\././')"
  38. else
  39. cp -a --reflink=auto $file $OUT/images/"$dir"_"$(basename $file|sed 's/\.orig\././')"
  40. fi
  41. done
  42. for file in $IN/$dir/*.coloured.jpg
  43. do
  44. if [[ "$DRY_RUN" == "1" ]]
  45. then
  46. echo cp -a --reflink=auto $file $OUT/labels/"$dir"_"$(basename $file|sed 's/\.coloured\././')"
  47. else
  48. cp -a --reflink=auto $file $OUT/labels/"$dir"_"$(basename $file|sed 's/\.coloured\././')"
  49. fi
  50. done
  51. done