extract_specific_modulo.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 img in sorted(images_path):
  15. img_index = int(img.split('-').split('.')[0])
  16. if ((img_index + 1) % p_modulo) == 0:
  17. output_path = img.replace(p_folder, p_output)
  18. output_folder, _ = os.path.split(output_path)
  19. if not os.path.exists(output_folder):
  20. os.makedirs(output_folder)
  21. if not os.path.exists(output_path):
  22. os.system(f'cp {img} {output_path}')
  23. print(f'Copy of {img}')
  24. else:
  25. print(f'{output_path} already exists')
  26. if __name__ == "__main__":
  27. main()