main3.py 693 B

123456789101112131415161718192021222324
  1. import cv2
  2. import os
  3. from glob import glob
  4. def edge(filename):
  5. img = cv2.imread(filename, cv2.IMREAD_GRAYSCALE)
  6. img_edge = cv2.adaptiveThreshold(img, 255,
  7. cv2.ADAPTIVE_THRESH_MEAN_C,
  8. cv2.THRESH_BINARY,
  9. blockSize=5,
  10. C=10)
  11. save_filename = '%s.jpeg' % (os.path.basename(filename).split('.')[0])
  12. cv2.imwrite('edges/' + save_filename, img_edge)
  13. if __name__ == "__main__":
  14. if not os.path.exists('edges'):
  15. os.makedirs('edges')
  16. file_list = glob('images/*.jpeg')
  17. for filename in file_list:
  18. edge(filename)