包括图像载入、显示、保存、转换灰度图
原图:
实际代码:
import cv2
import os
img_list = []
input_path = "D:/pycharm/test/"
output_path = "D:/pycharm/test1/"
for item in os.listdir(input_path):
img_list.append(os.path.join(input_path,item))
print(list)
count = 0
for imagepath in img_list:
# print(imagepath)
image = cv2.imread(imagepath,cv2.IMREAD_GRAYSCALE)
print(output_path+'%d.jpg'%(count))
cv2.imwrite(output_path+'%d.jpg'%(count),image)
print("-----------执行中,保存第{}张----------".format(count+1))
count += 1
os.makedirs(os.path.dirname(output_path),exist_ok=True)
cv2.imshow('garyimg',image)
cv2.waitKey(0)
运行结果: