-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_normals.py
59 lines (40 loc) · 1.47 KB
/
plot_normals.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
import pygame as pg
import os
from skimage import io
import time
import json
images = [pg.image.load(f"keyframes/{filename}") for filename in sorted(os.listdir("keyframes"), key=len)]
#images = [io.imread(f"keyframes/{filename}") for filename in os.listdir("keyframes")]
with open("data.json", "r") as file:
data = json.loads(file.read())
normals = list(data["normals"].values())
midpoints = list(data["midpoints"].values())
scale_factor = 0.5
pg.init()
display = pg.display.set_mode([int(n * scale_factor) for n in images[0].get_rect().size])
index = 0
# scale images
images = [pg.transform.scale(image, [int(n * scale_factor) for n in image.get_rect().size]) for image in images]
running = True
while running:
for event in pg.event.get():
if event.type == pg.QUIT:
running = False
if event.type == pg.KEYDOWN:
if event.key == pg.K_LEFT:
index -= 1
if event.key == pg.K_RIGHT:
index += 1
# make sure image index is within the range
index = max(0, min(index, len(images) - 1))
pg.display.set_caption(f"{index}/{len(images) - 1}")
midpoint = [int(n * scale_factor * 0.44) for n in midpoints[index][0:2]]
length_factor = 50
normal = [
midpoint[0] + -normals[index][0] * length_factor,
midpoint[1] + -normals[index][1] * length_factor
]
display.blit(images[index], (0, 0))
pg.draw.circle(display, (255, 0, 0), midpoint, 4)
pg.draw.line(display, (0, 255, 0), midpoint, normal, 2)
pg.display.update()