【python】更改图像格式:jpg2png

2021-12-31  本文已影响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)
上一篇下一篇

猜你喜欢

热点阅读