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

EncodingChannelsDtypeDescription
Rgb83U8Standard RGB color
Rgba84U8RGB with alpha
Bgr83U8BGR (OpenCV default)
Bgra84U8BGR with alpha
Mono81U8Grayscale 8-bit
Mono161U16Grayscale 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.

DtypeSizeUse Case
F324ML training/inference
F648High-precision computation
F162Memory-efficient inference
BF162Training on modern GPUs
U81Images
U162Depth sensors (mm)
U324Large indices
U648Counters, timestamps
I81Quantized inference
I162Audio, sensor data
I324General integer
I648Large signed values
Bool1Masks

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();
MethodReturnsDescription
.element_size()usizeBytes per element
TensorDtype::parse(s)OptionParse 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

Spotted an error on this page?