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

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

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

本文實(shí)例為大家分享了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)    # 寫(xiě)入文件地址

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

相關(guān)文章

最新評(píng)論

丰顺县| 宁河县| 筠连县| 富源县| 正定县| 临城县| 崇文区| 古丈县| 石首市| 彭州市| 汉源县| 宜都市| 墨竹工卡县| 手游| 达拉特旗| 伊金霍洛旗| 正定县| 文昌市| 崇义县| 额尔古纳市| 德格县| 安顺市| 昔阳县| 巫溪县| 调兵山市| 河间市| 揭阳市| 且末县| 兰溪市| 绥宁县| 车致| 石棉县| 东海县| 昌邑市| 科尔| 平阴县| 堆龙德庆县| 重庆市| 宜川县| 屏东县| 花莲县|