Skip to content

Commit

Permalink
add comments and change empty to string to a valid iamge prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
maxlou05 committed Dec 22, 2024
1 parent 4533f3a commit b6de157
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 29 deletions.
11 changes: 6 additions & 5 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ queue_max_size: 10

video_input:
worker_period: 1.0 # seconds
camera_option: 0 # 0 is for opencv camera (from camera_factory.py)
camera_enum: 0 # enum values can be found in camera_factory.py
width: 1920
height: 1200
# camera_config: # For Picamera
# For camera_enum=0, use the CV camera config. For camera_enum=1, use the Picamera config
camera_config: # For CV camera (regular cameras, enum 0)
device_index: 0
# camera_config: # For Picamera (PiCamera NoIR, enum 1)
# exposure_time: 250 # microseconds
# analogue_gain: 64.0 # Sets ISO, 1.0 for normal, 64.0 for max, 0.0 for min
# contrast: 1.0 # Contrast, 1.0 for nomral, 32.0 for max, 0.0 for min
# lens_position: null # Focal length, 1/m (0 for infinity, null for auto focus)
camera_config: # For CV camera (regular cameras)
device_index: 0
save_prefix: "log_image" # Leave as empty string to not log any images

detect_target:
Expand All @@ -24,7 +25,7 @@ detect_target:
save_prefix: "log_comp"

flight_interface:
# port 5762 connects directly to the simulated auto pilot, which is more realistic
# Port 5762 connects directly to the simulated auto pilot, which is more realistic
# than connecting to port 14550, which is the ground station
address: "tcp:localhost:5762"
timeout: 30.0 # seconds
Expand Down
19 changes: 10 additions & 9 deletions main_2024.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,18 @@ def main() -> int:
QUEUE_MAX_SIZE = config["queue_max_size"]

VIDEO_INPUT_WORKER_PERIOD = config["video_input"]["worker_period"]
VIDEO_INPUT_OPTION = camera_factory.CameraOption(config["video_input"]["camera_option"])
VIDEO_INPUT_OPTION = camera_factory.CameraOption(config["video_input"]["camera_enum"])
VIDEO_INPUT_WIDTH = config["video_input"]["width"]
VIDEO_INPUT_HEIGHT = config["video_input"]["height"]
if VIDEO_INPUT_OPTION == camera_factory.CameraOption.OPENCV:
VIDEO_INPUT_CAMERA_CONFIG = camera_opencv.ConfigOpenCV(
**config["video_input"]["camera_config"]
)
elif VIDEO_INPUT_OPTION == camera_factory.CameraOption.PICAM2:
VIDEO_INPUT_CAMERA_CONFIG = camera_picamera2.ConfigPiCamera2(
**config["video_input"]["camera_config"]
)
match VIDEO_INPUT_OPTION:
case camera_factory.CameraOption.OPENCV:
VIDEO_INPUT_CAMERA_CONFIG = camera_opencv.ConfigOpenCV(
**config["video_input"]["camera_config"]
)
case camera_factory.CameraOption.PICAM2:
VIDEO_INPUT_CAMERA_CONFIG = camera_picamera2.ConfigPiCamera2(
**config["video_input"]["camera_config"]
)
VIDEO_INPUT_SAVE_PREFIX = config["video_input"]["save_prefix"]

DETECT_TARGET_WORKER_COUNT = config["detect_target"]["worker_count"]
Expand Down
14 changes: 7 additions & 7 deletions modules/video_input/video_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def create(
width: int,
height: int,
config: camera_opencv.ConfigOpenCV | camera_picamera2.ConfigPiCamera2,
save_prefix: str,
maybe_image_name: str | None,
local_logger: logger.Logger,
) -> "tuple[True, VideoInput] | tuple[False, None]":
"""
Expand All @@ -40,13 +40,13 @@ def create(
f"camera factory failed. Current configs were: {camera_option=}, {width=}, {height=}, {config=}. Please try a different set of configs."
)
return False, None
return True, VideoInput(cls.__create_key, camera, save_prefix, local_logger)
return True, VideoInput(cls.__create_key, camera, maybe_image_name, local_logger)

def __init__(
self,
class_private_create_key: object,
camera: base_camera.BaseCameraDevice,
save_prefix: str,
maybe_image_name: str | None,
local_logger: logger.Logger,
) -> None:
"""
Expand All @@ -55,7 +55,7 @@ def __init__(
assert class_private_create_key is VideoInput.__create_key, "Use create() method."

self.__device = camera
self.__save_prefix = save_prefix
self.__maybe_image_name = maybe_image_name
self.__logger = local_logger

def run(self) -> "tuple[True, image_and_time.ImageAndTime] | tuple[False, None]":
Expand All @@ -67,8 +67,8 @@ def run(self) -> "tuple[True, image_and_time.ImageAndTime] | tuple[False, None]"
self.__logger.warning("Failed to take image")
return False, None

# If __save_prefix is not empty string, then save image
if self.__save_prefix:
self.__logger.save_image(image, self.__save_prefix)
# If __maybe_image_name is not None, then save image
if self.__maybe_image_name is not None:
self.__logger.save_image(image, self.__maybe_image_name)

return image_and_time.ImageAndTime.create(image)
8 changes: 4 additions & 4 deletions modules/video_input/video_input_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@


def video_input_worker(
period: int,
period: float,
camera_option: camera_factory.CameraOption,
width: int,
height: int,
camera_config: camera_opencv.ConfigOpenCV | camera_picamera2.ConfigPiCamera2,
save_prefix: str,
maybe_image_name: str | None,
output_queue: queue_proxy_wrapper.QueueProxyWrapper,
controller: worker_controller.WorkerController,
) -> None:
"""
Worker process.
period is the minimum period between image captures.
period is the minimum period between image captures in seconds.
output_queue is the data queue.
controller is how the main process communicates to this worker process.
"""
Expand All @@ -44,7 +44,7 @@ def video_input_worker(
local_logger.info("Logger initialized")

result, input_device = video_input.VideoInput.create(
camera_option, width, height, camera_config, save_prefix, local_logger
camera_option, width, height, camera_config, maybe_image_name, local_logger
)
if not result:
local_logger.error("Worker failed to create class object")
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/test_video_input_hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
WIDTH = 1920
HEIGHT = 1200
CONFIG = camera_opencv.ConfigOpenCV(0)
SAVE_PREFIX = "" # Not saving any pictures
IAMGE_NAME = None # Not saving any pictures


def main() -> int:
Expand All @@ -30,7 +30,7 @@ def main() -> int:

# Setup
result, camera = video_input.VideoInput.create(
CAMERA, WIDTH, HEIGHT, CONFIG, SAVE_PREFIX, local_logger
CAMERA, WIDTH, HEIGHT, CONFIG, IAMGE_NAME, local_logger
)
assert result
assert camera is not None
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/test_video_input_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
WIDTH = 1920
HEIGHT = 1200
CONFIG = camera_opencv.ConfigOpenCV(0)
SAVE_PREFIX = "" # Not saving any pictures
IMAGE_NAME = None # Not saving any pictures


def main() -> int:
Expand All @@ -42,7 +42,7 @@ def main() -> int:
WIDTH,
HEIGHT,
CONFIG,
SAVE_PREFIX,
IMAGE_NAME,
out_queue,
controller,
),
Expand Down

0 comments on commit b6de157

Please sign in to comment.