Skip to content

Commit e140e24

Browse files
henzlerQwlouse
andauthored
Allow kubric to set principal point shift for blender camera. (#306)
Note that this cl, however, does not handle the support for principal points in kubric. PiperOrigin-RevId: 568999187 Co-authored-by: kubric-team <[email protected]>
1 parent f7e6b9f commit e140e24

File tree

9 files changed

+111
-28
lines changed

9 files changed

+111
-28
lines changed

challenges/point_tracking/dataset.py

+14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# Copyright 2023 The Kubric Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
115
"""Kubric dataset with point tracking."""
216

317
import functools

examples/shapenet.py

+14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# Copyright 2023 The Kubric Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
115
import os
216
import logging
317
import numpy as np

kubric/core/cameras.py

+48-24
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,13 @@
2121

2222

2323
class Camera(objects.Object3D):
24-
""" Base class for all types of cameras.
25-
26-
Args:
27-
min_render_distance (float): The minimum rendering distance for the camera `m`.
28-
`Default = 0.1`
29-
30-
max_render_distance (float): The maximum rendering distance for the camera `m`.
31-
`Default = 1000.0`
24+
"""Base class for all types of cameras.
3225
26+
Args:
27+
min_render_distance (float): The minimum rendering distance for the camera
28+
`m`. `Default = 0.1`
29+
max_render_distance (float): The maximum rendering distance for the camera
30+
`m`. `Default = 1000.0`
3331
"""
3432

3533
min_render_distance = tl.Float(0.1)
@@ -71,28 +69,54 @@ class UndefinedCamera(Camera, UndefinedAsset):
7169

7270

7371
class PerspectiveCamera(Camera):
74-
""" A :class:`Camera` that uses perspective projection.
72+
"""A :class:`Camera` that uses perspective projection.
7573
7674
Args:
77-
focal_length (float): The focal length of the camera lens in `mm`.
78-
`Default = 50`
79-
80-
sensor_width (float): Horizontal size of the camera sensor in `mm`.
81-
`Default = 36`
82-
75+
focal_length (float): The focal length of the camera lens in `mm`. `Default
76+
= 50`
77+
sensor_width (float): Horizontal size of the camera sensor in `mm`. `Default
78+
= 36`
79+
shift_x (float): Principal point horizontal offset defined as fraction of
80+
sensor width. `Default = 0.0`
81+
shift_y (float): Principal point vertical offset defined as fraction of
82+
sensor height. `Default = 0.0`
8383
"""
8484

8585
focal_length = tl.Float(50)
8686
sensor_width = tl.Float(36)
87-
88-
def __init__(self,
89-
focal_length: float = 50,
90-
sensor_width: float = 36,
91-
position=(0., 0., 0.),
92-
quaternion=None, up="Y", front="-Z", look_at=None, euler=None, **kwargs):
93-
super().__init__(focal_length=focal_length, sensor_width=sensor_width, position=position,
94-
quaternion=quaternion, up=up, front=front, look_at=look_at, euler=euler,
95-
**kwargs)
87+
# Changing shift_x and shift_y is currently not supported in kubric. However,
88+
# these values can be changed if only blender support is necessary as changing
89+
# these will impact the blender camera principal point offsets.
90+
shift_x = tl.Float(0.0)
91+
shift_y = tl.Float(0.0)
92+
93+
def __init__(
94+
self,
95+
focal_length: float = 50,
96+
sensor_width: float = 36,
97+
shift_x: float = 0.0,
98+
shift_y: float = 0.0,
99+
position=(0.0, 0.0, 0.0),
100+
quaternion=None,
101+
up="Y",
102+
front="-Z",
103+
look_at=None,
104+
euler=None,
105+
**kwargs
106+
):
107+
super().__init__(
108+
focal_length=focal_length,
109+
sensor_width=sensor_width,
110+
position=position,
111+
quaternion=quaternion,
112+
up=up,
113+
front=front,
114+
look_at=look_at,
115+
euler=euler,
116+
shift_x=shift_x,
117+
shift_y=shift_y,
118+
**kwargs
119+
)
96120

97121
@property
98122
def field_of_view(self) -> float:

kubric/datasets/movid.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright 2023 The Kubric Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+

kubric/renderer/blender.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@ def use_gpu(self, value: bool):
191191
if d.use]
192192
logger.info("Using the following GPU Device(s): %s", devices_used)
193193

194-
195194
def set_exr_output_path(self, path_prefix: Optional[PathLike]):
196195
"""Set the target path prefix for EXR output.
197196
@@ -348,7 +347,6 @@ def postprocess(
348347
return {key: np.stack(data_stack[key], axis=0)
349348
for key in data_stack}
350349

351-
352350
@staticmethod
353351
def clear_and_reset_blender_scene(verbose: bool = False, custom_scene: str = None):
354352
""" Resets Blender to an entirely empty scene (or a custom one)."""
@@ -549,6 +547,10 @@ def _add_asset(self, obj: core.PerspectiveCamera):
549547
obj.observe(KeyframeSetter(camera, "clip_start"), "min_render_distance", type="keyframe")
550548
obj.observe(AttributeSetter(camera, "clip_end"), "max_render_distance")
551549
obj.observe(KeyframeSetter(camera, "clip_end"), "max_render_distance", type="keyframe")
550+
obj.observe(AttributeSetter(camera, "shift_x"), "shift_x")
551+
obj.observe(KeyframeSetter(camera, "shift_x"), "shift_x", type="keyframe")
552+
obj.observe(AttributeSetter(camera, "shift_y"), "shift_y")
553+
obj.observe(KeyframeSetter(camera, "shift_y"), "shift_y", type="keyframe")
552554
return camera_obj
553555

554556
@add_asset.register(core.OrthographicCamera)

kubric/safeimport/bpy.py

+14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# Copyright 2023 The Kubric Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
115
"""Module to safely import blender's bpy and guide the user to a solution.
216
317
USAGE:

shapenet2kubric/shapenet_synsets.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env python3
21
# Copyright 2023 The Kubric Authors.
32
#
43
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,6 +12,7 @@
1312
# See the License for the specific language governing permissions and
1413
# limitations under the License.
1514

15+
#!/usr/bin/env python3
1616

1717
CATEGORY_NAMES = {
1818
"04250224": "sniper rifle",

shapenet2kubric/trimesh_utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env python3
21
# Copyright 2023 The Kubric Authors.
32
#
43
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,6 +12,7 @@
1312
# See the License for the specific language governing permissions and
1413
# limitations under the License.
1514

15+
#!/usr/bin/env python3
1616

1717
import json
1818
import sys

test/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+

0 commit comments

Comments
 (0)