把文件夹下所有tiff或jpg图片保存为png

import cv2 import os bace_path = 'D:/budding_and_label/' f_name = os.listdir(bace_path) print(f_name,"name") for n in f_name: if n not in "maps":#这个我实际用的时候需要的限制条件可以不用管 path = bace_path + n print(path,"path") img = cv2.imread(path) # cv2.namedWindow("Image") # cv2.imshow("Image", img) # cv2.waitKey(0) # cv2.destroyAllWindows() n = n.split(".")[0] cv2.imwrite('d:/budding_and_label2/'+n+".png", img, [int(cv2.IMWRITE_PNG_COMPRESSION), 0])

    推荐阅读