python 视频转字符画 大佬们多多指教
from PIL import ImagecodeLib = '''...................................................................'''
count = len(codeLib)
print(count)
def transform(image_file):
image_file.convert("L")
codePic = ''
for h in range(0,image_file.size):
for w in range(0,image_file.size):
gray = image_file.getpixel((w,h))
#print(gray)
gray1=int((gray+gray+gray)/3)
#print(gray1)
#映射
if gray1<150:
codePic=codePic+codeLib
else:
codePic=codePic+codeLib
#codePic = codePic + codeLib
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.2),int(image_file.size*0.2)))
text = transform(image_file)
tmp = open(r'C:\Users\acer\Desktop\Python案例\Alan.txt','w')
tmp.write(text)
tmp.close()
页:
[1]