Camera API: Design an OOP Camera Control API for a Multi-Camera System
Question Details
Problem
Design an object-oriented API for controlling a multi-camera system. The API must support switching active cameras, adjusting settings (resolution, framerate, exposure), and streaming frames to registered consumers.
python
from abc import ABC, abstractmethod
class Camera(ABC):
@abstractmethod
def start(self) -> None: ...
@abstractmethod
def stop(self) -> None: ...
@abstractmethod
def capture_frame(self) -> bytes: ...
@abstractmethod
def set_resolution(self, width: int, height: int) -> None: ...
class CameraManager:
def register(self, cam_id: str, camera: Camera) -> None: ...
def activate(self, cam_id: str) -> None: ...
def stream(self, cam_id: str, consumer: callable, fps: int) -> None: ...
def switch(self, from_id: str, to_id: str, seamless: bool = False) -> None: ...
Scenario: A security system has 8 cameras. Design how you would allow a client to request a seamless switch with no dropped frames.
Follow-ups
- How does the abstract base class enforce the contract across camera hardware types?
- How would you implement frame buffering to guarantee no frames are dropped during a switch?
- What design pattern would you use to notify multiple consumers when a new frame is ready?
- How would you add authentication so only authorized clients can call
switch?
Full Details
Problem
Design an object-oriented API for controlling a multi-camera system. The API must support switching active cameras, adjusting settings (resolution, framerate, exposure), and streaming frames to registered consumers.
python
from abc import ABC, abstractmethod
class Camera(ABC):
@abstractmethod
def start(self) -> None: ...
@abstractmethod
def stop(self) -> None: ...
@abstractmethod
def capture_frame(self) -> bytes: ...
@abstractmethod
def set_resolution(self, width: int, height: int) -> None: ...
class CameraManager:
def register(self, cam_id: str, camera: Camera) -> None: ...
def activate(self, cam_id: str) -> None: ...
def stream(self, cam_id: str, consumer: callable, fps: int) -> None: ...
def switch(self, from_id: str, to_id: str, seamless: bool = False) -> None: ...
Scenario: A security system has 8 cameras. Design how you would allow a client to request a seamless switch with no dropped frames.
Follow-ups
- How does the abstract base class enforce the contract across camera hardware types?
- How would you implement frame buffering to guarantee no frames are dropped during a switch?
- What design pattern would you use to notify multiple consumers when a new frame is ready?
- How would you add authentication so only authorized clients can call
switch?
About This Question
This is a reported interview question from a verkada interview during the onsite round.
It covers the following topics: Coding, Pair Programming, Oop, Onsite .