Data Types & Encoding
High-level types for camera images, 3D point clouds, and depth maps. These types use zero-copy shared memory transport internally but expose ergonomic, domain-specific APIs.
// simplified
use horus::prelude::*; // Provides Image, PointCloud, DepthImage, TensorDtype, Device
Image
Represents a camera frame with pixel-level access and encoding metadata.
// simplified
// Create a 1080p RGB image
let image = Image::new(1920, 1080, ImageEncoding::Rgb8);
// Publish on a topic
let topic: Topic<Image> = Topic::new("camera.rgb")?;
topic.send(&image);
// Receive and access pixels
if let Some(img) = topic.recv() {
println!("{}x{}, encoding: {:?}", img.width(), img.height(), img.encoding());
let pixel = img.pixel(100, 200);
}
ImageEncoding
| Encoding | Channels | Dtype | Description |
|---|---|---|---|
Rgb8 | 3 | U8 | Standard RGB color |
Rgba8 | 4 | U8 | RGB with alpha |
Bgr8 | 3 | U8 | BGR (OpenCV default) |
Bgra8 | 4 | U8 | BGR with alpha |
Mono8 | 1 | U8 | Grayscale 8-bit |
Mono16 | 1 | U16 | Grayscale 16-bit |
PointCloud
Represents a 3D point cloud with per-point field access.
// simplified
// Build a point cloud from XYZ points
let points: Vec<[f32; 3]> = scan_points(); // your Vec<[f32; 3]>
let cloud = PointCloud::from_xyz(&points)?;
// Publish
let topic: Topic<PointCloud> = Topic::new("lidar.points")?;
topic.send(&cloud);
// Receive and inspect
if let Some(pc) = topic.recv() {
println!("{} points, {} fields/point", pc.point_count(), pc.fields_per_point());
}
DepthImage
Represents a depth map, typically from an RGBD or stereo camera.
// simplified
// Create a 640x480 depth image with millimeter-precision U16 values
let depth = DepthImage::millimeters(640, 480);
// Publish
let topic: Topic<DepthImage> = Topic::new("camera.depth")?;
topic.send(&depth);
// Receive and query depth
if let Some(d) = topic.recv() {
let depth_mm = d.get_depth(320, 240);
println!("Center depth: {} mm", depth_mm);
}
TensorDtype
Element data type used when constructing PointCloud, DepthImage, and other tensor-backed types.
| Dtype | Size | Use Case |
|---|---|---|
| F32 | 4 | ML training/inference |
| F64 | 8 | High-precision computation |
| F16 | 2 | Memory-efficient inference |
| BF16 | 2 | Training on modern GPUs |
| U8 | 1 | Images |
| U16 | 2 | Depth sensors (mm) |
| U32 | 4 | Large indices |
| U64 | 8 | Counters, timestamps |
| I8 | 1 | Quantized inference |
| I16 | 2 | Audio, sensor data |
| I32 | 4 | General integer |
| I64 | 8 | Large signed values |
| Bool | 1 | Masks |
TensorDtype Methods
// simplified
let dtype = TensorDtype::F32;
assert_eq!(dtype.element_size(), 4);
println!("{}", dtype); // "float32"
// Parse from string
let parsed = TensorDtype::parse("float32").unwrap();
| Method | Returns | Description |
|---|---|---|
.element_size() | usize | Bytes per element |
TensorDtype::parse(s) | Option | Parse from string ("float32", "uint8", "int16", etc.) |
Python Interop
Image, PointCloud, and DepthImage are available in Python with NumPy zero-copy access.
import horus
import numpy as np
# Subscribe to camera images
# Topic(msg_type, capacity=None, endpoint=None) — the type comes first; the
# channel name is passed as endpoint (the 2nd positional is an int capacity).
topic = horus.Topic(horus.Image, endpoint="camera.rgb")
img = topic.recv()
if img is not None:
print(f"{img.width}x{img.height}, encoding: {img.encoding}")
arr = img.to_numpy() # Zero-copy NumPy view
# Subscribe to point clouds
pc_topic = horus.Topic(horus.PointCloud, endpoint="lidar.points")
pc = pc_topic.recv()
if pc is not None:
points = pc.to_numpy() # (N, fields) NumPy array
print(f"{pc.point_count} points")
# Subscribe to depth images
depth_topic = horus.Topic(horus.DepthImage, endpoint="camera.depth")
depth = depth_topic.recv()
if depth is not None:
depth_arr = depth.to_numpy() # (H, W) NumPy array
See Also
- Tensor — Low-level tensor descriptor for ML pipelines
- Message Types — All HORUS message types
- Python Image, Python PointCloud, Python DepthImage