Skip to content

Commit

Permalink
improper camera.py merging
Browse files Browse the repository at this point in the history
  • Loading branch information
stimpfli committed Jan 16, 2025
1 parent 8312cfa commit 96ffb41
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions flygym/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,9 @@ def __init__(
else:
self.output_path = None

self._last_render_time = -np.inf
self._eff_render_interval = self.play_speed / self.fps
self._frames: list[np.ndarray] = []
self._timestamp_per_frame: list[float] = []

def _add_camera(self, attachement, camera_parameters, attachement_name):
"""Add a camera to the model."""
Expand Down Expand Up @@ -268,7 +268,7 @@ def render(

def reset(self):
self._frames.clear()
self._last_render_time = -np.inf
self._timestamp_per_frame = []

def save_video(self, path: Union[str, Path], stabilization_time=0.02):
"""Save rendered video since the beginning or the last ``reset()``,
Expand All @@ -291,13 +291,12 @@ def save_video(self, path: Union[str, Path], stabilization_time=0.02):
"loop."
)

num_stab_frames = int(np.ceil(stabilization_time / self._eff_render_interval))

Path(path).parent.mkdir(parents=True, exist_ok=True)
logging.info(f"Saving video to {path}")
with imageio.get_writer(path, fps=self.fps) as writer:
for frame in self._frames[num_stab_frames:]:
writer.append_data(frame)
for frame, timestamp in zip(self._frames, self._timestamp_per_frame):
if timestamp >= stabilization_time:
writer.append_data(frame)

def update_camera(self, physics: mjcf.Physics, floor_height: float, obs: dict):
"""Update the camera position and rotation based on the fly position and orientation.
Expand Down

0 comments on commit 96ffb41

Please sign in to comment.