Camera Data¶
In addition to lidar, the Ouster SDK’s frame-based API can represent data from
cameras. The camera API mirrors the lidar API closely, so if you are already
familiar with LidarFrame and
FrameSet, working with camera data will feel familiar.
There are three core types:
CameraInfo— metadata describing a camera: its image size, extrinsics, and an optionalCameraModel. This is the camera counterpart toLidarInfo.CameraModel— the camera’s pinhole intrinsics (fx,fy,cx,cy).CameraFrame— a single frame of camera data with named image fields (for exampleLEFT_RGBorRANGE). This is the camera counterpart toLidarFrame.
Before you fuse imagery with range data into a point cloud, read Projecting camera data into a point cloud below. Two constraints there — rectified imagery and radial range units — are not checked at runtime, and violating either produces a wrong cloud that still looks plausible.
Similarities with the LidarFrame API¶
CameraFrame and LidarFrame share a common Frame base class, and
CameraInfo and LidarInfo share a common SensorInfo base class. As a
result:
Frames expose the same interface:
w/h, named fields accessed withadd_field/field, per-frame timestamps, andbody_to_worldposes.A single
FrameSetcan hold both lidar and camera frames, so one source may combine multiple sensors of either kind.The same tools apply to both. You iterate frames from any source, collate frames across sensors, and project range images into 3D points with the same
XYZLut.
Integrating a camera¶
The SDK defines the camera data model but does not talk to any particular
camera. Reading frames from a specific camera and populating CameraInfo and
CameraFrame — and, if you wish, saving them — is up to you.
Projecting camera data into a point cloud¶
Fusing a camera’s RANGE field with its imagery to produce a point cloud
requires a calibrated, rectified camera and range in the right units. The three
constraints below are what the SDK assumes; only the first is enforced.
Warning
Without a CameraModel, imagery can be visualized but not
projected. CameraInfo.model is optional, and leaving it unset is a
legitimate way to record a camera whose intrinsics you do not know: images
render, frames collate, and timestamps and poses round-trip normally.
An XYZLut constructed from such a CameraInfo is empty, and applying
it to a frame raises, rather than guessing a focal length and returning a
cloud that is wrong by an unknown scale factor.
Warning
Only rectified imagery is supported. CameraModel carries pinhole
intrinsics and no distortion coefficients, and the projection path applies
no undistortion. Setting a CameraModel is therefore an assertion that
the imagery it describes is already rectified. If your camera reports both a
raw and a rectified calibration, use the rectified one, and rectify the
images before handing them to the SDK. Feeding distorted imagery through
projection produces a quietly warped cloud with no error or warning.
Warning
RANGE must be radial millimeters, not planar depth. RANGE is the
distance from the camera origin to the point, matching the lidar
convention. Many depth cameras instead report planar depth — the distance
along the optical axis — and the two agree only at the image center. Storing
planar depth as RANGE produces a cloud that looks reasonable but is
increasingly wrong toward the image edges. Convert first:
# depth_mm is planar depth (distance along the optical axis) in
# millimeters, shaped (h, w). RANGE is the distance from the camera
# origin, so each pixel is scaled by the length of its unit ray.
height, width = depth_mm.shape
u, v = np.meshgrid(np.arange(width), np.arange(height))
x = (u - model.cx) / model.fx
y = (v - model.cy) / model.fy
range_mm = depth_mm * np.sqrt(1.0 + x * x + y * y)
return np.round(range_mm).astype(np.uint32)
// depth_mm is planar depth (distance along the optical axis) in
// millimeters. RANGE is the distance from the camera origin, so each
// pixel is scaled by the length of its unit ray.
img_t<uint32_t> range_mm(depth_mm.rows(), depth_mm.cols());
for (Eigen::Index v = 0; v < depth_mm.rows(); ++v) {
for (Eigen::Index u = 0; u < depth_mm.cols(); ++u) {
const double x = (static_cast<double>(u) - model.cx) / model.fx;
const double y = (static_cast<double>(v) - model.cy) / model.fy;
const double scale = std::sqrt(1.0 + (x * x) + (y * y));
range_mm(v, u) = static_cast<uint32_t>((depth_mm(v, u) * scale) + 0.5);
}
}
Ouster Sensor Format¶
Camera data is written and replayed using the same OSF APIs as lidar data. The examples below mirror the lidar OSF examples.
Writing camera frames
import numpy as np
import ouster.sdk.core as core
import ouster.sdk.osf as osf
# Describe the camera (compare with LidarInfo for lidar).
info = core.CameraInfo()
info.width = 640
info.height = 480
# Optional: omit it and the imagery is viewable but not projectable.
info.model = core.CameraModel(fx=600.0, fy=600.0, cx=320.0, cy=240.0)
# Build a frame of camera data (compare with LidarFrame).
frame = core.CameraFrame()
frame.w = info.width
frame.h = info.height
frame.add_field("LEFT_RGB",
np.zeros((info.height, info.width, 3), dtype=np.uint8))
with osf.Writer("camera.osf") as writer:
writer.add_sensor(info) # register the camera stream
writer.save(0, frame, 100) # (stream index, frame, timestamp ns)
Reading camera frames
import ouster.sdk.core as core
from ouster.sdk import open_source
source = open_source("camera.osf")
for frame_set in source:
for frame in frame_set.valid_camera_frames():
# Per-frame timestamp and body_to_world pose both round-trip
# through OSF, just like a LidarFrame. A camera frame has no
# frame_id (that is a LidarFrame member); identify it by timestamp.
print(f"camera frame {frame.w}x{frame.h}, ts={frame.timestamp[0]}, "
f"fields={list(frame.fields)}")
source.close()
Frames of any type can also be printed directly with str(frame) (or
ouster::sdk::core::to_string(frame) in C++), which prints a LidarFrame
or CameraFrame according to the frame’s concrete type — handy when iterating
frame_set.valid_frames() over a mixed source.