-
-
Save victorfei/230b8c61b4b7ca7e7ccb4bbb92896c63 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from PIL import Image | |
import numpy as np | |
files = [f for f in os.listdir("handwriting/numbers/")] | |
files = ["handwriting/numbers/" + f for f in files] | |
STANDARD_SIZE = (50, 50) | |
def get_image_data(filename): | |
img = Image.open(filename) | |
img = img.getdata() | |
img = img.resize(STANDARD_SIZE) | |
img = map(list, img) | |
img = np.array(img) | |
s = img.shape[0] * img.shape[1] | |
img_wide = img.reshape(1, s) | |
return img_wide[0] | |
data = [] | |
labels = [] | |
print "extracting features..." | |
for f in files: | |
data.append(get_image_data(f)) | |
labels.append(int(f.split(".")[0][-1])) | |
print "done." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment