-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgtest.py
67 lines (53 loc) · 1.83 KB
/
gtest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import tkinter
# import Image
from dlib_68_ref import refShape
# width of the animation window
animation_window_width = 800
# height of the animation window
animation_window_height = 800
# delay between successive frames in seconds
animation_refresh_seconds = 2
# The main window of the animation
def create_animation_window():
window = tkinter.Tk()
window.title("Render Face")
window.geometry(f'{animation_window_width}x{animation_window_height}')
return window
# Create a canvas for animation and add it to main window
def create_animation_canvas(window):
canvas = tkinter.Canvas(window)
canvas.configure(bg="white")
canvas.pack(fill="both", expand=True)
return canvas
# Draw the face and save to file
# or actively stream the data to this screen
def draw_face(window, canvas, shape):
canvas.delete("all")
# Draw Right eye
canvas.create_polygon(shape[36:42],fill="white", outline="black")
window.update()
# Draw nose
canvas.create_line(shape[27:31])
canvas.create_line(shape[31:36])
window.update()
# Draw Left Eye
canvas.create_polygon(shape[42:48],fill="white", outline="black")
window.update()
# Draw eyebrows
canvas.create_line(shape[17:22])
canvas.create_line(shape[22:27])
# Draw lips
canvas.create_polygon(shape[48:60],fill="white", outline="black")
canvas.create_polygon(shape[60:68],fill="white", outline="black")
window.update()
# Draw Jaw
canvas.create_line(shape[0:17])
window.update()
# # Save Image
# ps = canvas.postscript(colormode='color')
# img = Image.open(io.BytesIO(ps.encode('utf-8')))
# img.save('/tmp/images/test.jpg')
# Testing
# animation_window = create_animation_window()
# animation_canvas = create_animation_canvas(animation_window)
# draw_face(animation_window, animation_canvas, refShape)