def save(img_path ,label_path, savepath, num):
f = open(img_path,'rb')
la_f = open(label_path,'rb')
la_f.read(8)
f.read(16)
dict = {}
for n in range(num):
image = []
for i in range(28*28):
image.append(ord(f.read(1)))
image = np.array(image).reshape(28,28)
name = classes[ord(la_f.read(1))]
filepath = os.path.join(savepath, name)
if not os.path.isdir(filepath):
os.makedirs(filepath)
if name not in dict:
dict[name] = 1
else:
dict[name] += 1
png = str(dict[name])+'.png'
save_path = os.path.join(filepath, png)
cv2.imwrite(save_path, image)
la_f.close()
f.close()