Skip to content
Snippets Groups Projects
Commit 257af9a8 authored by lhp33's avatar lhp33
Browse files

drawing function

parent 4419fe7f
No related branches found
No related tags found
No related merge requests found
from PIL import Image, ImageDraw
import PIL
from tkinter import *
import numpy as np
from PIL import ImageOps
#import tensorflow as tf
def save():
name = "num.jpg"
image.save(name)
parse()
def clear():
global image
global draw
canvas.delete("all")
image = PIL.Image.new("RGB", (280, 280), (255,255,255))
draw = ImageDraw.Draw(image)
def parse():
newimg = ImageOps.fit(image, (28,28), PIL.Image.NEAREST, 0 ,(.5, .5))
newimg.convert('L')
newimg.save("newNum.jpg")
bwData = np.asarray(newimg)
print(bwData / 255.0)
np.save("num", bwData)
# predict()
#def predict():
# newModel = tf.keras.models.load_model('MNIST_model.h5')
#print(newModel.summary())
def paint(event):
# Get mouse coordinates
x1, y1 = (event.x-2), (event.y-2)
x2, y2 = (event.x+2), (event.y+2)
# Draw object on canvas
canvas.create_oval(x1, y1, x2, y2, fill="black", width=5)
# Draw object on image
draw.line([x1, y1, x2, y2], fill="black", width=5)
#create gui object
root = Tk()
# create canvas on window
canvas = Canvas(root, width = 280, height = 280, bg = 'white')
canvas.pack(side=TOP)
# Bottom frame holds buttons
bottom = Frame(root)
bottom.pack(side=BOTTOM)
# Create save button
saveButton = Button(text="Save", command=save)
saveButton.pack(in_=bottom, side=LEFT)
# Create save button
clearButton = Button(text="Clear", command=clear)
clearButton.pack(in_=bottom, side=LEFT)
canvas.pack(expand=YES, fill=BOTH)
canvas.bind("<B1-Motion>", paint)
# Create new image
image = PIL.Image.new("RGB", (280, 280), (255,255,255))
draw = ImageDraw.Draw(image)
root.mainloop()
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment