首页 > 编程知识 正文

python图像处理,python批量处理图片大小

时间:2023-05-05 16:50:07 阅读:12033 作者:2320

导入cv2

import numpy as np

导入操作系统

img_file_name='IMG_2271.jpg '

img=cv2.imread(img_file_name )。

width,height,dep=img.shape

k=浮动(宽度/浮动(高度) ) ) )。

img=cv2.resize(img,(400,int ) k*400 )、interpolation=cv2.INTER_CUBIC ) )。

width,height,dep=img.shape

txt_file_name='77.txt '

try:

操作系统. remove (txt _ file _ name ) )。

except Exception,e:

打印e

txt=open(txt_file_name,' w ' ) )。

txt.write(str ) width ) ' ' str (height ) )

txt.write () (r ) )。

foriinrange (高) :

forjinrange(width ) :

TXT.write(str(img[j,I,0] ) ' str (img [ j,I,1] ) ' str (j,I,2] ) )

txt.write () (r ) )。

txt.close (

博客内容是网友的个人帖子,只表达了博客的个人见解。 有侵害的情况请联系工作人员删除。

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