python处理图片大小_python 读取图片,调整大小,并将RGB信息写入txt

import cv2

import numpy as np

import os

img_file_name="IMG_2271.JPG"

img = cv2.imread(img_file_name)

width,height,dep=img.shape

k=float(width)/float(height)

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

width,height,dep=img.shape

txt_file_name="77.txt"

try:

os.remove(txt_file_name)

except Exception,e:

print e

txt=open(txt_file_name,"w")

txt.write(str(width)+" "+str(height))

txt.write("\r")

for i in range(height):

for j in range(width):

txt.write(str(img[j,i,0])+" "+str(img[j,i,1])+" "+str(img[j,i,2]))

txt.write("\r")

txt.close()

*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。

你可能感兴趣的:(python处理图片大小)