|
楼主 |
发表于 2022-1-13 19:45:39
|
显示全部楼层
批量灰度
- import cv2
- import os
- path = 'F:\cc'
- for lujing,liebiao,wenjian in os.walk(path):
- for i in wenjian:
- url = lujing+'\\'+i
- print(url)
- name = url.split('\\')[-1].split('.')[0]
- houzhui = url.split('.')[-1]
- newname = name + '-huidu' +'.' + houzhui
- print(f'{path}\\{newname}')
- img = cv2.imread(url) #读取图片
- gray_img = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) #灰度转换
- cv2.imwrite(f'{path}\\{newname}',gray_img) #保存图片
- cv2.destroyAllWindows() #释放内存
复制代码
|
|