-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathtest_camera.py
55 lines (48 loc) · 1.47 KB
/
test_camera.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
import pytest
from pathlib import Path
import numpy as np
from numpy.testing import assert_allclose
from blendtorch import btt
BLENDDIR = Path(__file__).parent / "blender"
@pytest.mark.background
def test_projection():
launch_args = dict(
scene=BLENDDIR / "cam.blend",
script=BLENDDIR / "cam.blend.py",
num_instances=1,
named_sockets=["DATA"],
background=True,
)
ortho_xy_expected = np.array(
[
[480.0, 80],
[480.0, 80],
[480.0, 400],
[480.0, 400],
[160.0, 80],
[160.0, 80],
[160.0, 400],
[160.0, 400],
]
)
proj_xy_expected = np.array(
[
[468.148, 91.851],
[431.111, 128.888],
[468.148, 388.148],
[431.111, 351.111],
[171.851, 91.851],
[208.888, 128.888],
[171.851, 388.148],
[208.888, 351.111],
]
)
z_expected = np.array([6.0, 8, 6, 8, 6, 8, 6, 8])
with btt.BlenderLauncher(**launch_args) as bl:
addr = bl.launch_info.addresses["DATA"]
ds = btt.RemoteIterableDataset(addr, max_items=2)
item = next(iter(ds))
assert_allclose(item["ortho_xy"], ortho_xy_expected, atol=1e-2)
assert_allclose(item["ortho_z"], z_expected, atol=1e-2)
assert_allclose(item["proj_xy"], proj_xy_expected, atol=1e-2)
assert_allclose(item["proj_z"], z_expected, atol=1e-2)