import cv2#循环灰度图片并保存def grayImg(): for x in range(1,38): #读取图片 img = cv2.imread("C://Users//lyl//Desktop//new_dahuoji//img2//{}.jpg".format(str(x))) GrayImage=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) #保存灰度后的新图片 cv2.imwrite("C://Users//lyl//Desktop//1//myProject//pictures//dataset2//dahuomiao//{}.jpg".format(str(x)),GrayImage)grayImg()