Utility functions for image and point cloud processing.
source ~/vector_venv/bin/activate
source /opt/ros/jazzy/setup.bash
colcon build --packages-select vector_perception_utilsfrom vector_perception_utils.image_utils import *
# Resize with aspect ratio
resized = resize_image(image, (512, 512), keep_aspect_ratio=True)
# Crop, draw, overlay
cropped = crop_to_bbox(image, (x1, y1, x2, y2))
img = draw_bbox(image, bbox, label="object")
img = apply_mask_overlay(image, mask, alpha=0.4)
# Normalize for neural networks
normalized = normalize_image(image) # ImageNet
# Compute IoU
iou = compute_iou(bbox1, bbox2)from vector_perception_utils.pointcloud_utils import *
# RGBD to pointcloud (Open3D)
points, colors = rgbd_to_pointcloud(
depth_image, rgb_image, intrinsics,
depth_scale=1000.0, # 1000.0=RealSense, 1.0=ZED
mask=segmentation_mask # Optional: only convert masked region
)
# 3D bbox from pointcloud
bbox_3d = pointcloud_to_bbox3d(points, header=ros_header)
# Create ROS2 PointCloud2 message
from std_msgs.msg import Header
pointcloud_msg = create_pointcloud2_msg(points, colors, header)
# Downsample
points_down, colors_down = voxel_downsample(points, voxel_size=0.05, colors=colors)
# Remove outliers
points_clean, colors_clean, inliers = remove_statistical_outliers(points, colors=colors)
points_clean, colors_clean, inliers = remove_radius_outliers(points, radius=0.05, colors=colors)
# Transform
points_transformed = transform_pointcloud(points, transform_4x4)from vector_perception_utils.detection_utils import *
# Create Detection2D from mask
detection_2d = create_detection2d_from_mask(header, mask, track_id, score)
# Convert to Detection3D
detection_3d = detection2d_to_detection3d(detection_2d, bbox_3d, track_id)
# Extract corners
corners = bbox_to_corners(bbox_3d) # (8, 3) array
# Compute volume
volume = compute_bbox_volume(bbox_3d) # cubic metersRealSense D435i:
- Encoding: uint16, Units: millimeters, depth_scale: 1000.0
- Topics:
/camera/color/image_raw,/camera/aligned_depth_to_color/image_raw
ZED Mini/2i:
- Encoding: float32, Units: meters, depth_scale: 1.0
- Topics:
/zed/zed_node/rgb/color/rect/image,/zed/zed_node/depth/depth_registered
Image Utils (9): resize_image, crop_to_bbox, normalize_image, denormalize_image, mask_to_bbox, draw_bbox, apply_mask_overlay, compute_iou
Point Cloud Utils (14): create_pointcloud, voxel_downsample, estimate_normals, remove_statistical_outliers, remove_radius_outliers, transform_pointcloud, crop_pointcloud_bbox, compute_centroid, rgbd_to_pointcloud, pointcloud_to_depth, pointcloud_to_bbox3d, create_pointcloud2_msg
Detection Utils (6): detection2d_to_detection3d, create_detection2d_from_mask, bbox_to_corners, compute_bbox_volume, overlay_detection2d