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

augment.py 1.2 kB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import argparse
  2. import cv2
  3. import os
  4. from tqdm import tqdm
  5. def flip(root: str, file_name: str):
  6. img = cv2.imread(os.path.join(root, file_name))
  7. flipped = cv2.flip(img, 1) # 水平翻转
  8. cv2.imwrite(os.path.join(root, "flipped_"+file_name), flipped)
  9. def label_flip(root: str, file_name: str):
  10. img = cv2.imread(os.path.join(root, file_name), cv2.CV_16UC1)
  11. flipped = cv2.flip(img, 1)
  12. cv2.imwrite(os.path.join(root, "flipped_"+file_name), flipped)
  13. def check_head(path: str):
  14. if path.startswith("flipped_"):
  15. return False
  16. return True
  17. if __name__ == "__main__":
  18. parser = argparse.ArgumentParser()
  19. parser.add_argument('--input_path', type=str)
  20. parser.add_argument("--process", type=int)
  21. args = parser.parse_args()
  22. # image
  23. for root, dirs, files in os.walk(args.input_path + "/imgs"):
  24. for file in tqdm(files):
  25. if check_head(file):
  26. flip(root, file)
  27. # print(os.path.join(root, file))
  28. # labels
  29. for root, dirs, files in tqdm(os.walk(args.input_path + "/labels")):
  30. for file in tqdm(files):
  31. if check_head(file):
  32. label_flip(root, file)

第三届计图人工智能挑战赛——风格及语义引导的风景图片生成赛道项目,由jittor计图框架实现