最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python讀取圖片并修改格式與大小的方法

 更新時間:2018年07月24日 15:08:37   作者:alwaysPractice  
這篇文章主要為大家詳細(xì)介紹了python讀取圖片并修改格式與大小的方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了python讀取圖片并修改文件大小的具體代碼,供大家參考,具體內(nèi)容如下

# Author:NDK
# -*- coding:utf-8 -*-

from PIL import Image
import os
import cv2
import numpy as np
import glob
# old_dir = './test/'
# def read_image(cwd, newpath):
#   for roots, dirs, files in os.walk(cwd):
#     print(dirs)
#     for i in dirs:
#       print(i)
#       os.chdir(cwd + i)
#       for pic in glob.glob('*.png'):
#         _, image = pic.split('_')
#         img = image.split('.')[0]
#         print(img)
#         if len(img) != 0:
#           if int(img) % 2 != 0:
#             im = Image.open(pic)
#             im.save(newpath + i + '/' + pic)
# read_image('./num/','./new_img/')
# for i in range(10):
root_path = r"/test/9/"  #操作文件路徑
print(root_path)
# dir = root_path+"images"+"/"
dir = root_path
count = 0
for root,dir,files in os.walk(dir):
  for file in files:
    srcImg = cv2.imread(root_path+"/"+str(file))
    img = Image.open(root_path+"/"+str(file))
    print(root_path+str(file))
    newImg = img.resize((50, 50), Image.BILINEAR)  #想調(diào)整的大小
    cv2.imwrite(r'./img2/'+str(file),newImg)    # 寫入文件地址

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

舒城县| 彰化市| 马山县| 晋中市| 东光县| 个旧市| 磐石市| 盐津县| 南昌市| 定结县| 大英县| 庄浪县| 自治县| 奉新县| 小金县| 伊吾县| 依兰县| 大方县| 正镶白旗| 凯里市| 乐平市| 夏津县| 松潘县| 洛浦县| 丹凤县| 察隅县| 普兰县| 泽库县| 西昌市| 新建县| 清河县| 梧州市| 东宁县| 盘山县| 镇宁| 卓尼县| 青海省| 乐山市| 固镇县| 西乌| 西畴县|