图片前后比较,因为图片是晚上拍的,效果可能欠佳
from PIL import Image
img = Image.open("D:\PyCharm实例\zihuaxiang\IMG_20190513_215846-.png")
out = img.convert("L")
out.size
width, height = out.size
out = out.resize((int(width * 0.5),int(height * 0.5)))
width, height = out.size
print(width,height)
print(out.getpixel((100,100)))
print(out.getpixel((200,200)))
asciis = "@%#+=-. "
texts = " "
for row in range(height):
for col in range(width):
gray = out.getpixel((col,row))
texts += asciis[int(gray / 255 * 2)]
texts += "\n"
with open("D:/PyCharm实例/zihuaxiang/new2.txt","w") as file:
file.write(texts)
https://blog.csdn.net/weixin_43206161