opencv_resize.py 656 B

123456789101112131415161718
  1. import os
  2. import cv2
  3. import numpy as np
  4. def main():
  5. data_dir_path ="C:\\Users\\User\\Desktop\\test"
  6. file_list = os.listdir(r'C:\Users\User\Desktop\test')
  7. count = 0
  8. for file_name in file_list:
  9. root, ext = os.path.splitext(file_name)
  10. if ext == '.png' or '.jpeg' or '.jpg':
  11. abs_name = data_dir_path + '/' + file_name
  12. image = cv2.imread(abs_name)
  13. #在下面寫要做的處理 在這邊是做修改圖片大小的處理
  14. img = cv2.resize(image, (10, 10)) #把圖片的大小改成150*150
  15. cv2.imwrite(abs_name, img)
  16. if __name__ == '__main__':
  17. main()