Skip to content

Instantly share code, notes, and snippets.

@dzhwinter
Created September 16, 2017 05:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dzhwinter/c0e1edfdfac329006f0ef1bb5cd7873d to your computer and use it in GitHub Desktop.
Save dzhwinter/c0e1edfdfac329006f0ef1bb5cd7873d to your computer and use it in GitHub Desktop.
flatten image
import sys
import cv2
import json
IMAGE_SIZE = 28
if len(sys.argv) < 2:
print "usage: python readimg.py filename"
exit(1)
filename = sys.argv[1]
# gray image, size = (28, 28)
img = cv2.imread(filename, 0)
img.resize((IMAGE_SIZE, IMAGE_SIZE))
img = img.flatten()
print json.dumps({"img": img.tolist()})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment