mbodied.types.utils package

Submodules

mbodied.types.utils.bboxer module

mbodied.types.utils.bboxer.draw_bounding_box_with_label(image_path: str, bbox: tuple, label: str, color: str = 'red', width: int = 2) <module 'PIL.Image' from '/home/docs/checkouts/readthedocs.org/user_builds/mbodi-ai-mbodied-agents/envs/latest/lib/python3.12/site-packages/PIL/Image.py'>[source]

Draws a bounding box with a label and shading on an image.

Parameters:
  • image_path (str) – Path to the image file.

  • bbox (tuple) – Bounding box coordinates as (left, top, right, bottom).

  • label (str) – Label text for the bounding box.

  • color (str) – Color of the bounding box and label text. Default is red.

  • width (int) – Width of the bounding box lines. Default is 2.

Returns:

Image object with the bounding box and label drawn.

Return type:

Image

Example

image_with_bbox = draw_bounding_box_with_label(“path/to/image.jpg”, (50, 50, 150, 150), “Object”)

mbodied.types.utils.estimate_intrinsics module

mbodied.types.utils.estimate_intrinsics.estimate_intrinsic_parameters(unscaled_depth_map: ndarray, image: ndarray, seg_map: ndarray = None) dict[source]

Estimate intrinsic camera parameters given an unscaled depth map, image, and optionally a semantic segmentation map.

Parameters:
  • unscaled_depth_map (np.ndarray) – Unscaled depth map.

  • image (np.ndarray) – Image corresponding to the depth map.

  • seg_map (np.ndarray, optional) – Semantic segmentation map. Defaults to None.

Returns:

Estimated intrinsic parameters including focal lengths and principal point.

Return type:

dict

Example

>>> import cv2
>>> import numpy as np
>>> from mbodied.agents.sense.utils.estimate_intrinsics import estimate_intrinsic_parameters
>>> unscaled_depth_map = np.random.rand(480, 640)
>>> image = np.random.randint(0, 255, (480, 640, 3), dtype=np.uint8)
>>> estimate_intrinsic_parameters(unscaled_depth_map, image)
{'fx': 1.0, 'fy': 1.0, 'cx': 320.0, 'cy': 240.0}

mbodied.types.utils.geometry module

mbodied.types.utils.geometry.compute_view_params(camera_pos: ndarray, target_pos: ndarray, up_vector: ndarray = array([0, 0, 1])) tuple[source]

Compute view parameters (azimuth, distance, elevation, lookat) for a camera.

mbodied.types.utils.geometry.depth_image_to_pointcloud(depth_img: ndarray, cam_matrix: ndarray) ndarray[source]

Convert a scaled depth image to a point cloud.

mbodied.types.utils.geometry.downsample_pointcloud(pointcloud: ndarray, grid_size: float) ndarray[source]

Downsample a point cloud based on a specified grid size.

mbodied.types.utils.geometry.get_rotation_matrix_from_two_points(p_from: ndarray, p_to: ndarray) ndarray[source]

Generate a rotation matrix that aligns one point with another.

mbodied.types.utils.geometry.interpolate_constant_velocity_trajectory(traj_anchor: ndarray, velocity: float = 1.0, hz: int = 100, order: int = inf) tuple[source]

Interpolate a trajectory to achieve constant velocity.

mbodied.types.utils.geometry.is_line_connectable(p1: ndarray, p2: ndarray, obstacles: list) bool[source]

Check if a line between two points is connectable (does not intersect any obstacles).

mbodied.types.utils.geometry.is_point_feasible(point: ndarray, obstacles: list) bool[source]

Check if a point is feasible (not inside any obstacles).

mbodied.types.utils.geometry.is_point_in_polygon(point: ndarray, polygon: Polygon) bool[source]

Check if a point is inside a given polygon.

mbodied.types.utils.geometry.leveraged_squared_exponential_kernel(X1: ndarray, X2: ndarray, L1: ndarray, L2: ndarray, hyp: dict) ndarray[source]

Compute the leveraged SE kernel between two sets of points.

mbodied.types.utils.geometry.passthrough_filter(pcd: ndarray, axis: int, interval: list) ndarray[source]

Filter a point cloud along a specified axis within a given interval.

mbodied.types.utils.geometry.pose_to_transformation_matrix(position: ndarray, rotation: ndarray) ndarray[source]

Convert a pose (position and rotation) to a transformation matrix.

mbodied.types.utils.geometry.quintic_trajectory(start_pos: ndarray, start_vel: ndarray, start_acc: ndarray, end_pos: ndarray, end_vel: ndarray, end_acc: ndarray, duration: float, num_points: int, max_velocity: float, max_acceleration: float) tuple[source]

Generate a quintic trajectory with velocity and acceleration constraints.

mbodied.types.utils.geometry.remove_duplicates(pointcloud: ndarray, threshold: float = 0.05) ndarray[source]

Remove duplicate points from a point cloud within a given threshold.

mbodied.types.utils.geometry.remove_duplicates_with_reference(pointcloud: ndarray, reference_point: ndarray, threshold: float = 0.05) ndarray[source]

Remove duplicate points close to a specific reference point within a given threshold.

mbodied.types.utils.geometry.rodrigues_rotation(axis: ndarray, angle_rad: float) ndarray[source]

Compute the rotation matrix from an angular velocity vector.

mbodied.types.utils.geometry.rotation_matrix(deg: float) ndarray[source]

Generate a 2x2 rotation matrix for a given angle in degrees.

mbodied.types.utils.geometry.rotation_matrix_to_angular_velocity(R: ndarray) ndarray[source]

Convert a rotation matrix to an angular velocity vector.

mbodied.types.utils.geometry.rotation_matrix_to_quaternion(R: ndarray) ndarray[source]

Convert a rotation matrix to a quaternion.

mbodied.types.utils.geometry.rotation_matrix_to_rpy(R: ndarray, unit: str = 'rad') ndarray[source]

Convert a rotation matrix to roll, pitch, yaw angles (in radians or degrees).

mbodied.types.utils.geometry.rotation_to_transformation_matrix(R: ndarray) ndarray[source]

Convert a rotation matrix to a transformation matrix.

mbodied.types.utils.geometry.rpy_to_rotation_matrix(rpy_rad: ndarray) ndarray[source]

Convert roll, pitch, yaw angles (in radians) to a rotation matrix.

mbodied.types.utils.geometry.sample_points_in_3d(n_sample: int, x_range: list, y_range: list, z_range: list, min_dist: float, xy_margin: float = 0.0) ndarray[source]

Sample points in 3D space ensuring a minimum distance between them.

mbodied.types.utils.geometry.skew_symmetric_matrix(vector: ndarray) ndarray[source]

Generate a skew-symmetric matrix from a vector.

mbodied.types.utils.geometry.soft_squash(x: ndarray, x_min: float = -1, x_max: float = 1, margin: float = 0.1) ndarray[source]

Softly squash the values of an array within a specified range with margins.

mbodied.types.utils.geometry.soft_squash_multidim(x: ndarray, x_min: ndarray, x_max: ndarray, margin: float = 0.1) ndarray[source]

Apply soft squashing to a multi-dimensional array.

mbodied.types.utils.geometry.squared_exponential_kernel(X1: ndarray, X2: ndarray, hyp: dict) ndarray[source]

Compute the squared exponential (SE) kernel between two sets of points.

mbodied.types.utils.geometry.transformation_matrix_to_pose(T: ndarray) tuple[source]

Extract position and rotation matrix from a transformation matrix.

mbodied.types.utils.geometry.transformation_matrix_to_position(T: ndarray) ndarray[source]

Extract position from a transformation matrix.

mbodied.types.utils.geometry.transformation_matrix_to_rotation(T: ndarray) ndarray[source]

Extract rotation matrix from a transformation matrix.

mbodied.types.utils.geometry.trim_scale(x: ndarray, threshold: float) ndarray[source]

Scale down the input array if its maximum absolute value exceeds the threshold.

mbodied.types.utils.geometry.unit_vector(vector: ndarray) ndarray[source]

Return the unit vector of the input vector.

Module contents