import os
from PIL import Image
def init(fileList,n):
for i in range(2,n):
img=Image.open("G:\\detect\\"+str(fileList[i]))
new_img=img.resize((32,32))
w,h=new_img.size
with open("G:\\detect\\chepai"+str(i)+".txt", "w") as f:
for c in range(h):
for j in range(w):
f.write(str(int((255-(new_img.getpixel((j,c))))/255)))
if j==w-1:
f.write("\n")
f.close()
if __name__=="__main__":
fileList=os.listdir("G:\\detect")
n=len(fileList)
init(fileList,n)
可用作识别手写数字数据集。
来源:CSDN
作者:Legolas~
链接:https://blog.csdn.net/qq_38883271/article/details/103643499