Skip to content

raisim::OpticalFlowCamera ​

final class · #include <raisim/sensors/OpticalFlowSensor.hpp>

Inherits: raisim::Sensor

Optical-flow camera: backward, causal optical flow between two captures of this camera (ground truth).

For the surface point seen at pixel p in this capture, the flow is p_prev - p in pixels, where p_prev is where that point projected in the previous capture of the same camera, through the same lens (Replicator / Isaac Lab motion vectors, BlenderProc backward flow). Pixel coordinates follow OpenCV: x (column) to the right, y (row) down. The flow image holds width * height * 2 floats (index = (row * width + col) * 2 + {0: dx, 1: dy}) and the mask image width * height bytes, both row-major with row 0 at the top. Mask bits:

  • kHit: the pixel sees a surface within [clipNear, clipFar];
  • kHasHistory: there is a previous capture and, for a surface, its body existed then;
  • kInFrame: p_prev is inside the image, on a pixel that has a ray (inside a fisheye's image circle), seen through the lens before its fold (and in front of a pinhole camera);
  • kVisible: the point was visible at the previous capture: its previous optical depth matches the previous depth image at p_prev within 1% + 1 cm. KITTI's "occ" validity is kHit | kHasHistory | kInFrame, "noc" also needs kVisible. Pixels without a surface hold the flow of the camera rotation alone (points at infinity), with kHit clear. Without history the flow is (0, 0).

Measurement sources: with MANUAL (the default) a renderer writes both images. With RAISIM, update() ray-casts the collision geometry of the world (the owning body excluded). It keeps the history of this camera: its pose, the poses of the bodies of the world (single bodies and articulated-system links, by stable object id and body index) and the optical depth image of the previous capture. Deformable and granular objects have no rigid history (kHasHistory clear on them). The first capture, resetHistory(), setProperties() and a world time before the previous capture start a new history. Bodies moved by setters (teleports) between captures appear to move; call resetHistory() after a reset. The TCP viewer does not render this camera.

With a positive latency or latencyJitter, captures reach getFlowArray() and getMaskArray() after the delay (see the Sensor class comment): writers fill getCaptureFlowArray() and getCaptureMaskArray() and call commitCapture(). The history is kept at acquisition: the flow of a capture is relative to the previous capture, whether or not that one was delivered yet. The jitter stream derives from the sensor identity, owner id and World environment seed.

Nested classes ​

  • struct BodyPose — Pose of one body at a capture, keyed by stable object id and body index.
  • struct OpticalFlowCameraProperties — Configuration of an OpticalFlowCamera. Change it with setProperties().

Constructors & destructor ​

OpticalFlowCamera ​

cpp
OpticalFlowCamera(
    const OpticalFlowCameraProperties &prop,
    class ArticulatedSystem *as,
    const Vec<3> &pos,
    const Mat<3, 3> &rot)

Create an optical-flow camera with zero images and no history. The measurement source is MANUAL.

Parameters

ParameterDescription
prop (in)Camera properties (validated; invalid values cause a fatal error).
as (in)Owning articulated system.
pos (in)Sensor position relative to the body (link) it is defined on.
rot (in)Sensor orientation relative to the body (link) it is defined on.

Public member functions ​

serializeProp ​

cpp
server::BoundedWriter serializeProp(server::BoundedWriter data) const final

Used by the server. Do not use it if you don't know what it does. It serializes the sensor properties

Parameters

ParameterDescription
data (in)where the property is written; throws server::SerializationError if it does not fit

Returns where the next data should be written

getProperties ​

cpp
const OpticalFlowCameraProperties &getProperties() const

Returns The camera properties.

setProperties ​

cpp
void setProperties(const OpticalFlowCameraProperties &prop)

Replace the camera properties transactionally. Invalid properties leave the camera unchanged. The images are reallocated and zeroed and the history is cleared.

Parameters

ParameterDescription
prop (in)New properties. name and full_name must match the current ones (fatal error otherwise).

getFlowArray ​

cpp
const std::vector<float> &getFlowArray() const

Flow image, width * height * 2 floats (see the class comment).

Returns The image.

cpp
std::vector<float> &getFlowArray()

Mutable access for MANUAL measurements (renderers); keep its size.

Returns The image.

getMaskArray ​

cpp
const std::vector<uint8_t> &getMaskArray() const

Validity mask, width * height bytes of kHit | kHasHistory | kInFrame | kVisible bits.

Returns The mask.

cpp
std::vector<uint8_t> &getMaskArray()

Mutable access for MANUAL measurements (renderers); keep its size.

Returns The mask.

setFlowArray ​

cpp
void setFlowArray(const std::vector<float> &flow)

Replace the delivered flow image directly, without latency. Fatal error unless it has width * height * 2 values.

Parameters

ParameterDescription
flow (in)New flow image.

setMaskArray ​

cpp
void setMaskArray(const std::vector<uint8_t> &mask)

Replace the delivered mask directly, without latency. Fatal error unless it has width * height values.

Parameters

ParameterDescription
mask (in)New mask.

getCaptureFlowArray ​

cpp
std::vector<float> &getCaptureFlowArray()

Flow image that receives the next capture (same size and layout as getFlowArray()). It is the delivered image itself without latency (zero copy) and a staging image otherwise; fill it and the capture mask (getCaptureMaskArray()) and call commitCapture().

Returns Writable capture image.

getCaptureMaskArray ​

cpp
std::vector<uint8_t> &getCaptureMaskArray()

Mask that receives the next capture (see getCaptureFlowArray()).

Returns Writable capture mask.

commitCapture ​

cpp
void commitCapture(double acquisitionTime)

Commit the capture written into the capture images as acquired at the given world time: acknowledges the sample like setUpdateTimeStamp() and, with a latency, queues the capture for delivery (see the Sensor class comment). Without latency it is delivered at once.

Parameters

ParameterDescription
acquisitionTime (in)World time of the capture (s); must be finite with a latency.

getDeliveryTimeStamp ​

cpp
double getDeliveryTimeStamp() const

Returns World time at which the delivered capture was delivered (its acquisition time without latency); negative before the first.

getDroppedCaptureCount ​

cpp
uint64_t getDroppedCaptureCount() const

Returns Captures dropped because the latency queue was full, since the properties last changed.

getPendingCaptureCount ​

cpp
size_t getPendingCaptureCount() const

Returns Captures waiting for delivery.

resetNoise ​

cpp
void resetNoise() noexcept

Restart the latency-jitter stream from the sensor identity, owner id and World environment seed.

resetHistory ​

cpp
void resetHistory()

Forget the previous capture: the next capture has no history (kHasHistory clear, zero flow).

hasHistory ​

cpp
bool hasHistory() const

Returns whether update() has a previous capture to compute the flow against.

getHistoryEpoch ​

cpp
uint64_t getHistoryEpoch() const

Returns A counter that resetHistory() advances (so do the constructor and setProperties()). Renderers that keep their own history (rayrai's Camera and SensorBatchRenderer) start a new one when it changed since their previous capture. It is not part of World checkpoints.

update ​

cpp
void update(class World &world) final

Ray-cast the images: refreshes the sensor pose from its attachment frame, casts one ray per pixel against the collision bodies of world (ignoring the owning body), computes the flow against the history and stores this capture as the new history. Called by RaiSim when the measurement source is RAISIM. A rolling shutter is a fatal error.

Parameters

ParameterDescription
world (in)the world that the sensor is in

getRayDirections ​

cpp
const CameraRayDirections &getRayDirections() const

Returns Ray directions in the sensor frame, one per pixel (see computeCameraRayDirections()). setProperties() and World::restoreCheckpoint() replace the table.

Static member functions ​

getType static ​

cpp
static Type getType()

Returns Sensor::Type::OPTICAL_FLOW.

Public attributes ​

kHit ​

cpp
static constexpr uint8_t kHit

Mask bit: the pixel sees a surface.

kHasHistory ​

cpp
static constexpr uint8_t kHasHistory

Mask bit: the previous capture (and the surface's body in it) exists.

kInFrame ​

cpp
static constexpr uint8_t kInFrame

Mask bit: the previous pixel position is inside the image, on a pixel that has a ray.

kVisible ​

cpp
static constexpr uint8_t kVisible

Mask bit: the point was not occluded at the previous capture.

Inherited members ​

From raisim::Sensor: capturesDelayed, getAcquisitionTimeStamp, getArticulatedSystem, getFrameId, getFrameOrientation, getFramePosition, getFullName, getMeasurementSource, getName, getOrientation, getOriInSensorFrame, getPosInSensorFrame, getPosition, getSensorSetModel, getSerialNumber, getUpdateRate, getUpdateTimeStamp, isUpdateDue, lock, lockMutex, MeasurementSource, serializeMeasurements, setAttachmentFrame, setMeasurementSource, setSerialNumber, setUpdateRate, setUpdateTimeStamp, try_lock, Type, unlock, unlockMutex, updatePose

RaiSim — physics for robotics and AI.