import os
import cv2
import numpy as np


# 读入中文命名图片
def cv_imread(in_path):
    cv_img = cv2.imdecode(np.fromfile(in_path, dtype=np.uint8), -1)  # -1表示cv2.IMREAD_UNCHANGED
    return cv_img


# 写入中文命名图片
def cv_imwrite(out_path, img_np):
    cv2.imencode('.png', img_np)[1].tofile(out_path)


in_dir = 'C:/Users/Shuai/Desktop/railway/station/'
out_dir = 'C:/Users/Shuai/Desktop/railway/station2/'

# 例子:中文名jpg转png图片
for img_name in os.listdir(in_dir):
    img = cv_imread(in_dir + img_name)
    new_name = img_name.replace('.jpg', '.png')
    cv_imwrite(out_dir + new_name, img)
    print(new_name)

 

相关文章:

  • 2021-11-05
  • 2022-12-23
  • 2021-12-18
  • 2021-05-20
  • 2021-06-18
  • 2021-09-03
  • 2022-12-23
猜你喜欢
  • 2021-05-17
  • 2022-02-09
  • 2021-09-12
  • 2021-12-15
  • 2021-07-11
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案