首页 > 编程知识 正文

python画图,python3

时间:2023-05-04 20:11:38 阅读:12037 作者:694

在本文的示例中,python共享了读取图像并调整文件大小的特定代码。 具体内容如下

# Author:NDK

#-* -编码: utf-8-* -

来自pil导入图像

导入操作系统

导入cv2

import numpy as np

导入全局

# old_dir='./test/'

#defread_image(CWD,新路径) :

# for roots,dirs,filesinOS.walk(CWD ) :

#是打印(dirs )

# for i in dirs:

#打印(I )是

#操作系统. chdir (cwdi ) )。

#forpicinglob.glob('*.png ' ) :

# _,image=pic.split('_ ' )

# img=image.split ('.' ) [0]

#打印(img )

#iflen(img )!=0:

#ifint(img ) % 2!=0:

#im=image.open(pic ) )

#im.save(newpathI'/'pic ) )。

#read_image('./num/','./new_img/' ) )

#forIinrange(10 ) :

root_path=r'/test/9/' #操作文件路径

打印(根_路径)是

# dir=root_path 'images' '/'

dir=root_path

计数=0

for root,dir,files in os.walk(dir ) :

for file in files:

src img=cv2.im read (root _ path '/' str (file ) )

img=image.open (root _ path '/' str (file ) )

打印(root _ pathstr (file ) )

希望更改newimg=img.resize ((50,50 ),Image.BILINEAR ) #的大小

CV2.imwrite(r'./img2/'str ) file ),newImg ) #写入文件地址

希望以上是正文的全部内容,对大家的学习有帮助。 另外,我希望你多支持我找教程网。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。