update_rawls.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import os, sys
  2. import argparse
  3. import subprocess
  4. def write_progress(progress):
  5. '''
  6. Display progress information as progress bar
  7. '''
  8. barWidth = 150
  9. output_str = "["
  10. pos = barWidth * progress
  11. for i in range(barWidth):
  12. if i < pos:
  13. output_str = output_str + "="
  14. elif i == pos:
  15. output_str = output_str + ">"
  16. else:
  17. output_str = output_str + " "
  18. output_str = output_str + "] " + str(int(progress * 100.0)) + " %\r"
  19. print(output_str)
  20. sys.stdout.write("\033[F")
  21. def main():
  22. parser = argparse.ArgumentParser(description="Update whole scene folder .rawls files to new .rawls version format")
  23. parser.add_argument('--folder', type=str, help='folder with all .rawls scenes sub folder', required=True)
  24. parser.add_argument('--output', type=str, help='output expected folder (can be the same)', required=True)
  25. args = parser.parse_args()
  26. p_folder = args.folder
  27. p_output = args.output
  28. # check if executable file is available
  29. executable_filepath = './build/main/rawls_update'
  30. if not os.path.exists(executable_filepath):
  31. print("Executable '{0}' does not exist or is not accessible as expected.".format(executable_filepath))
  32. scenes = sorted(os.listdir(p_folder))
  33. for scene in scenes:
  34. scene_path = os.path.join(p_folder, scene)
  35. # create output scene path if does not exist
  36. output_scene_path = os.path.join(p_output, scene)
  37. if not os.path.exists(output_scene_path):
  38. os.makedirs(output_scene_path)
  39. print('Convert .rawls for: {0}'.format(scene))
  40. images = sorted(os.listdir(scene_path))
  41. n_images = len(images)
  42. for i, img in enumerate(images):
  43. img_path = os.path.join(scene_path, img)
  44. out_img_path = os.path.join(output_scene_path, img)
  45. # create and launch command
  46. subprocess.call([executable_filepath, '--image', img_path, '--outfile', out_img_path])
  47. write_progress((i + 1 ) / float(n_images))
  48. print('\n')
  49. if __name__ == "__main__":
  50. main()