美文网首页
【python】更改图像格式:jpg2png

【python】更改图像格式:jpg2png

作者: 小小杨树 | 来源:发表于2021-12-31 15:06 被阅读0次

    大家可以任意更换

    import os
    import cv2
    import sys
    import numpy as np
    
    path = "./image/"
    
    OldFormat = ".jpg"
    NewFormat = ".png"
    
    for filename in os.listdir(path):
        if os.path.splitext(filename)[1] == OldFormat:
            img = cv2.imread(path + filename)
            print(filename.replace(OldFormat, NewFormat))
            newfilename = filename.replace(OldFormat, NewFormat)
            cv2.imwrite(path + newfilename, img)
    

    相关文章

      网友评论

          本文标题:【python】更改图像格式:jpg2png

          本文链接:https://www.haomeiwen.com/subject/xrwgqrtx.html