马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
from PIL import Image
codeLib = '''................................................................... '''
count = len(codeLib)
print(count)
def transform(image_file):
image_file.convert("L")
codePic = ''
for h in range(0,image_file.size[1]):
for w in range(0,image_file.size[0]):
gray = image_file.getpixel((w,h))
#print(gray)
gray1=int((gray[0]+gray[1]+gray[2])/3)
#print(gray1)
#映射
if gray1<150:
codePic=codePic+codeLib[0]
else:
codePic=codePic+codeLib[68]
#codePic = codePic + codeLib[int((count*gray1)/256)]
codePic=codePic+' '
codePic = codePic + '\n'
print(codePic)
return codePic
fp = open('3.jpg','rb')
image_file = Image.open(fp)
image_file =image_file.resize((int(image_file.size[0]*0.2),int(image_file.size[1]*0.2)))
text = transform(image_file)
tmp = open(r'C:\Users\acer\Desktop\Python案例\Alan.txt','w')
tmp.write(text)
tmp.close()
|