extract_specific_modulo.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import os
  2. import argparse
  3. import glob
  4. def main():
  5. parser = argparse.ArgumentParser(description="Extract specific samples indices")
  6. parser.add_argument('--folder', type=str, help='folder with all rawls files', required=True)
  7. parser.add_argument('--modulo', type=int, help='every image to take', required=True)
  8. parser.add_argument('--output', type=str, help='folder with all png files', required=True)
  9. args = parser.parse_args()
  10. p_folder = args.folder
  11. p_output = args.output
  12. p_modulo = args.modulo
  13. images_path = glob.glob(f"{p_folder}/**/**/*.rawls")
  14. for i, img in enumerate(sorted(images_path)):
  15. if ((i + 1) % p_modulo) == 0:
  16. output_path = img.replace(p_folder, p_output)
  17. output_folder, _ = os.path.split(output_path)
  18. if not os.path.exists(output_folder):
  19. os.makedirs(output_folder)
  20. if not os.path.exists(output_path):
  21. os.system(f'cp {img} {output_path}')
  22. print(f'Copy of {img}')
  23. else:
  24. print(f'{output_path} already exists')
  25. if __name__ == "__main__":
  26. main()