Python 学习笔记13 安装PIL及图像样本规整

Time:20181008

ENV:python3.6、

Author:New

1、

pip install pillow

文件加载失败

2、

pip3 install pillow 

文件继续加载失败

3、

easy_install pillow

文件加载成功、安装成功很奇怪的操作!!

 

pip 9.0.3 18.1
pillow 5.3.0  

 

4、代码演演示

form:https://blog.csdn.net/sunfellow2009/article/details/80887476

# coding=utf-8
import glob
import os
from PIL import Image

# print(glob.glob(r'D:\VideoPhotos\sign\*.jpg'))
# path = r'D:\VideoPhotos\sign'images = glob.glob(path + r"\*.jpg")
path = r'G:\\Python\\testproject1\\venv1\\neg'
images = glob.glob(path + r"\*.png")
for img in images:

# print(img)
    im = Image.open(img)
# print(im.format, im.size, im.mode)
    size = 390,60
# print(size)
    name = os.path.join(path, img)
    im.thumbnail(size)
    im.save(name, 'png')
# print(im.format, im.size, im.mode)

代码可能有些问题,样本规整完后,图像大小不是390*60,

另测试:

# coding=utf-8
import glob
import os
from PIL import Image

# print(glob.glob(r'D:\VideoPhotos\sign\*.jpg'))
# path = r'D:\VideoPhotos\sign'images = glob.glob(path + r"\*.jpg")
path = r'G:\\Python\\testproject1\\venv1\\neg1'
images = glob.glob(path + r"\*.jpg")
for img in images:

# print(img)
    im = Image.open(img)
    print(im.format, im.size, im.mode)
    size = 48,30
    # print(size)
    name = os.path.join(path, img)
    im.thumbnail(size)
    # im.save(name, 'png')
    im.save(name, 'JPEG')
    print(im.format, im.size, im.mode)
换了jpg格式图像可以准确完成样本规整。???
阅读更多
换一批

没有更多推荐了,返回首页