栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python图像重命名 + resize

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python图像重命名 + resize

import os
import shutil
import cv2


image_path = "" #图像文件夹路径
out_path = "" #图像文件的输出路径

list_image = []
def get_image(image_path):
    pathDir = os.listdir(image_path)
    for allimage in pathDir:
        temp = allimage.split(".")
        list_image.append(temp[0])
    print(list_image)
    print(len(list_image))
    
    
    
 
get_image(image_path)
list_image.sort()
 
# 图像重命名后保存
# i = 0
# for image in list_image:
#
#     shutil.copy(os.path.join(image_path, image + '.JPG'), os.path.join(out_path, str(i).zfill(4) + '.jpg'))
#     i += 1

# 读取图像resize之后保存
i = 0
for image in list_image:
    img = cv2.imread(image_path + image + '.JPG')
    # cv2.imshow("image", img)
    # cv2.waitKey(0)
    img_2 = cv2.resize(img, (3840, 2160), interpolation=cv2.INTER_AREA)
    cv2.imwrite(out_path+ str(i).zfill(4) + '.jpg', img_2)
    # shutil.copy(os.path.join(image_path, image + '.JPG'), os.path.join(out_path, image + '.JPG'))
    i += 1
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/822549.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号