Image Analysis#
- class payloadcomputerdroneprojekt.image_analysis.ImageAnalysis(config: dict, camera: AbstractCamera, comms: Communications)[source]#
Bases:
object
Handles image analysis for drone payload computer, including color and shape detection, object localization, and image quality assessment.
- Parameters:
config (dict) – Configuration dictionary for image analysis parameters.
camera (AbstractCamera) – Camera object implementing AbstractCamera.
comms (Communications) – Communications object for drone telemetry.
- add_lat_lon(obj: dict, rotation: List[float] | ndarray, height: float, image_size: Tuple[int, int], loc_to_global: Callable[[float, float], Any]) None [source]#
Add latitude and longitude to an object based on its local offset.
- compute_image(image: ndarray, item: DataItem | None = None, height: float = 1) Tuple[List[dict], ndarray] [source]#
Filter image for defined colors and detect objects.
- detect_obj(objects: List[dict], filtered_image: Dict[str, Any], height: float = 1) None [source]#
Detect objects in a filtered image and append to objects list.
- filter_color(image: ndarray, color: str, shape_mask: ndarray | None = None) ndarray [source]#
Filter the image for a specific color.
- Parameters:
image (np.array) – Input image.
color (str) – Color name (must be in defined colors).
shape_mask (np.array or None) – Optional shape mask to apply.
- Returns:
Filtered image.
- Return type:
np.array
- Raises:
IndexError – If color is not defined.
- filter_colors(image: ndarray) Tuple[List[Dict[str, Any]], ndarray] [source]#
Filter the image for each defined color and for the shape color.
- filter_shape_color(image: ndarray) ndarray [source]#
Filter the image for the shape color.
- Parameters:
image (np.array) – Input image.
- Returns:
Shape-filtered image.
- Return type:
np.array
- find_code(obj: dict, shape_image: ndarray, height: float = 1) bool [source]#
Find code elements (e.g., QR code-like) inside the object.
- get_closest_element(image: ndarray, color: str, shape: str | None, item: DataItem | None = None, height: float = 1) dict | None [source]#
Get the closest detected object of a given color and shape.
- async get_current_offset_closest(color: str, shape: str, yaw_zero: bool = True, indoor: bool = False) Tuple[List[float] | None, float | None, float | None] [source]#
Get the offset from the drone to the closest object of a given color and shape.
- get_filtered_objs() Dict[str, Dict[str, List[dict]]] [source]#
Get a dictionary of all filtered objects.
- get_local_offset(obj: dict, rotation: List[float] | ndarray, height: float, image_size: Tuple[int, int]) ndarray [source]#
Get the local offset of an object in the drone’s coordinate system.
- get_matching_objects(color: str, shape: str | None = None) List[dict] [source]#
Get all matching filtered objects for a color and optional shape.
- get_shape(obj: dict, shape_image: ndarray, height: float = 1) str | bool [source]#
Detect the shape inside the object boundaries.
- static quality_of_image(image: ndarray) float [source]#
Assess the quality of an image using Laplacian variance.
- Parameters:
image (np.array) – Image array.
- Returns:
Laplacian variance (higher is sharper).
- Return type:
- start_cam(images_per_second: float = 1.0) bool [source]#
Start capturing and saving images asynchronously.