gray.py 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. import cv2
  2. import os
  3. import glob
  4. # 根目录路径
  5. root_path = r'C:\Users\KDAN\Desktop\work\exchange\font_style_classification\Fonts_img_Dataset\windows_1\chinese'
  6. save_path = r'C:\Users\KDAN\Desktop\work\exchange\font_style_classification\Fonts_img_Dataset\windows_1\chinese_gray'
  7. list_path = os.listdir(root_path)
  8. for k, names in enumerate(list_path):
  9. print(k, names)
  10. # if names.endswith('.txt'):
  11. # continue
  12. # if not os.path.exists(save_path + '\\' + names):
  13. # os.makedirs(save_path + '\\' + names)
  14. bmp_path = glob.glob(r'C:\Users\KDAN\Desktop\work\exchange\font_style_classification\Fonts_img_Dataset\windows_1\chinese\{}\*jpg'.format(names))
  15. for i, path_bmp in enumerate(bmp_path):
  16. if path_bmp.endswith('.txt'):
  17. continue
  18. # print(path_bmp)
  19. a = os.path.split(path_bmp)
  20. name = os.path.basename(a[0])
  21. # print(name)
  22. img = cv2.imread(path_bmp)
  23. gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
  24. # cv2.imshow('figure', gray)
  25. # cv2.waitKey(0)
  26. cv2.imwrite('C:/Users/KDAN/Desktop/work/exchange/font_style_classification/Fonts_img_Dataset/windows_1/chinese_gray/{}/{}_{}.jpg'.format(names, name, i), gray)