Skip to content

Commit ed38325

Browse files
committed
Updated frame saving and camera mode setting.
1 parent 3525ad5 commit ed38325

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

drone_base/config/video.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class VideoConfig:
22
"""Configuration class for the drone video stream with validation"""
33

4-
def __init__(self, width: int = 640, height: int = 360, cam_mode: str | None = None):
4+
def __init__(self, width: int = 640, height: int = 360, cam_mode: str | None = None, save_extension: str = "png"):
55
"""
66
Sets the width and height of the video stream. Computes the center of the frame.
77
@@ -12,12 +12,15 @@ def __init__(self, width: int = 640, height: int = 360, cam_mode: str | None = N
1212
"""
1313
if width <= 0 or height <= 0:
1414
raise ValueError("Video width and height must be greater than zero.")
15+
if save_extension not in ("png", "jpg", "jpeg"):
16+
raise ValueError(f"Save extension must be 'png' or 'jpg' or 'jpeg'. Provided {save_extension}")
1517

1618
self.width: int = width
1719
self.height: int = height
1820
self.frame_center_x, self.frame_center_y = self.__compute_frame_center()
1921
self.frame_area = self.__compute_frame_area()
2022
self.max_queue_size = 30
23+
self.save_extension = save_extension
2124

2225
if cam_mode not in ("photo", "recording", None):
2326
raise ValueError(

drone_base/stream/base_streaming_controller.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,22 @@
2222
class BaseStreamingController(ABC):
2323
"""Base class for all streaming controllers with common functionality."""
2424

25-
def __init__(
25+
def __init__( # noqa: PLR0913
2626
self,
2727
ip: DroneIp,
2828
processor_class: type[BaseVideoProcessor],
2929
speed: int = 35,
3030
log_path: str | Path | None = None,
3131
results_path: str | Path | None = None,
32+
video_config: VideoConfig | None = None,
3233
):
3334
self.start_time = date_time_now_to_file_name()
3435
if log_path is not None:
3536
log_path = Path(log_path) / self.start_time
3637
if results_path is not None:
3738
results_path = Path(results_path) / self.start_time
38-
self.video_config = VideoConfig(width=640, height=360, cam_mode="photo")
39+
40+
self.video_config = video_config if video_config is not None else VideoConfig()
3941

4042
self.drone = olympe.Drone(ip)
4143
self.drone_commander = DroneCommander(self.drone, logger_dir=log_path)

drone_base/stream/base_video_processor.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ def __init__(
3434
self.is_frame_saved = frame_save_dir is not None
3535
if self.is_frame_saved:
3636
save_path = Path(frame_save_dir) / "frames"
37-
self.frame_saver = BufferedFrameSaver(output_dir=save_path, logger_dir=logger_dir)
37+
self.frame_saver = BufferedFrameSaver(
38+
output_dir=save_path, logger_dir=logger_dir, save_extension=video_config.save_extension
39+
)
3840

3941
if logger_dir is not None:
4042
logger_dir = Path(logger_dir) / f"{self.__class__.__name__}.log"

drone_base/stream/saving/frame_saver.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77

88

99
class BufferedFrameSaver:
10-
def __init__(self, output_dir: str | Path, logger_dir: str | Path | None = None):
10+
def __init__(self, output_dir: str | Path, logger_dir: str | Path | None = None, save_extension: str = "png"):
1111
self.output_dir = Path(output_dir)
12+
self.save_extension = save_extension
1213
self.output_dir.mkdir(parents=True, exist_ok=True)
1314
self.frames: list[tuple[np.ndarray, float]] = []
1415

@@ -25,7 +26,7 @@ def save_all(self):
2526
self.logger.info("Saving all frames to disk")
2627
for index, (frame, timestamp) in enumerate(self.frames):
2728
timestamp_ms = int(timestamp * 1000)
28-
output_path = self.output_dir / f"frame_{index:06d}_{timestamp_ms}.png"
29+
output_path = self.output_dir / f"frame_{index:06d}_{timestamp_ms}.{self.save_extension}"
2930
cv2.imwrite(str(output_path), frame)
3031
if index % 100 == 0:
3132
self.logger.info("Saved %s/%s frames", f"{index:06d}", len(self.frames))

0 commit comments

Comments
 (0)