payloadcomputerdroneprojekt.image_analysis package#
Submodules#
payloadcomputerdroneprojekt.image_analysis.data_handler module#
- class payloadcomputerdroneprojekt.image_analysis.data_handler.DataHandler(path: str)[source]#
Bases:
object
Handles loading, saving, and processing of DataItem objects for image analysis.
- Parameters:
path (str) – Directory path where data files are stored.
- get_filterd_items(distance_threshold: float) Dict[str, Dict[str, List[Dict[str, Any]]]] [source]#
Filters and clusters detected objects by color and shape, then computes their mean positions.
- get_filtered_storage() str [source]#
Returns the path to the filtered data storage file.
- Returns:
Path to filtered data file.
- Return type:
- payloadcomputerdroneprojekt.image_analysis.data_handler.get_mean(sorted_list: Dict[str, Dict[str, Dict[int, List[Dict[str, Any]]]]]) Dict[str, Dict[str, List[Dict[str, Any]]]] [source]#
Computes the mean latitude and longitude for each cluster of objects.
payloadcomputerdroneprojekt.image_analysis.data_item module#
- class payloadcomputerdroneprojekt.image_analysis.data_item.DataItem(path: str)[source]#
Bases:
object
Represents a data item for image analysis, storing image paths, metadata, and detected objects.
- Parameters:
path (str) – Directory path where images will be saved.
- add_computed_image(image: ndarray) None [source]#
Save and register the computed (processed) image.
- Parameters:
image (np.ndarray) – Computed image as a numpy array.
- add_height(height: float) None [source]#
Add the height at which the image was taken.
- Parameters:
height (float) – Height value.
- add_image(image, name: str) None [source]#
Save and register an image with a specific name.
- Parameters:
image (np.ndarray) – Image as a numpy array.
name (str) – Name for the saved image.
- add_image_position(latlonalt: ndarray) None [source]#
Add the image’s GPS position (latitude, longitude, altitude).
- Parameters:
latlonalt (np.ndarray) – Array containing latitude, longitude, and altitude.
- add_objects(objects: List[Dict[str, Any]]) None [source]#
Add detected objects to the data item and assign unique IDs to each.
- Parameters:
objects (List[Dict[str, Any]]) – List of detected object dictionaries.
- add_quality(quality: float) None [source]#
Add a quality metric to the data item.
- Parameters:
quality (float) – Quality value (e.g., confidence score).
payloadcomputerdroneprojekt.image_analysis.ia_class module#
- class payloadcomputerdroneprojekt.image_analysis.ia_class.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.
payloadcomputerdroneprojekt.image_analysis.math_helper module#
- payloadcomputerdroneprojekt.image_analysis.math_helper.compute_local(pixel_x, pixel_y, rotation_angles, image_size, field_of_view)[source]#
Computes the local 3D direction vector for a given pixel in the image, considering camera rotation.
- Parameters:
- Returns:
Local 3D direction vector.
- Return type:
np.ndarray
- payloadcomputerdroneprojekt.image_analysis.math_helper.compute_pixel_vec(pixel_x, pixel_y, image_size, field_of_view)[source]#
Computes the normalized direction vector from the camera center to a pixel in the image.
- payloadcomputerdroneprojekt.image_analysis.math_helper.compute_rotation_angle(top_left, bottom_left)[source]#
Computes the rotation angle (in degrees) between two points.
- payloadcomputerdroneprojekt.image_analysis.math_helper.find_relative_position(points: list)[source]#
Finds the relative positions of three points such that two vectors are orthogonal and the cross product is positive.
- payloadcomputerdroneprojekt.image_analysis.math_helper.find_shortest_longest_sides(points: list)[source]#
Finds the shortest and longest sides of a quadrilateral defined by four points.