-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.py
More file actions
65 lines (46 loc) · 1.99 KB
/
test.py
File metadata and controls
65 lines (46 loc) · 1.99 KB
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
# Import create_data.create_data from data_producer/create_data.py to actually use this package.
# This file is used to simulate differential motion. The user inputs a pathway using mouse input
# and the program will generate a video of the pathway with a moving square that follows the path
# and a constant moving background. The program will also generate a reference video of the same
# path with just the outline of the moving square for comparison later.
# go to data_producer folder to adjust the parameters of the produced video (size, length, etc...)
from data_producer.diff_data_producer import *
from data_producer.path_producer import *
import numpy as np
import yaml
from pathlib import Path
import skvideo.io
# -----------------------
# --- Params / Setup ----
# -----------------------
fn = Path(r"data_producer/data_producer_params.yaml")
PARAMS_DIR = fn
with open(PARAMS_DIR) as f:
params = yaml.safe_load(f)
save_dir = params["save_dir"]
ref_save_dir = params["ref_save_dir"]
fps = params["fps"]
height = params["height"]
width = params["width"]
frames = params["frames"]
col_width = params["col_width"]
object_radius = params["object_radius"]
fill = params["fill"] # either True or int
seconds = np.ceil(frames / fps).astype(int)
canvas = np.zeros(shape=(frames, height, width), dtype=np.int32)
ref_canvas = np.zeros(shape=(frames, height, width), dtype=np.int32)
# -----------------------
# -- Paths / Creation ---
# -----------------------
# change to a path creation function of your choice if preferred
x, y = manually_create_path(width, height, frames)
canvas = create_moving_background(canvas, fps, seconds)
canvas = apply_object_to_path(canvas, (x, y), object_radius)
ref_canvas = apply_object_to_path(ref_canvas, (x, y), object_radius, fill=fill)
# RENDER
result = encode_to_video(canvas, fps, save_dir)
ref_result = encode_to_video(ref_canvas, fps, ref_save_dir)
if result:
print("Video saved successfully!")
else:
print("Error saving video.")