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
structBodyPose — Pose of one body at a capture, keyed by stable object id and body index.structOpticalFlowCameraProperties — Configuration of an OpticalFlowCamera. Change it with setProperties().
Constructors & destructor
OpticalFlowCamera
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
| Parameter | Description |
|---|---|
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
server::BoundedWriter serializeProp(server::BoundedWriter data) const finalUsed by the server. Do not use it if you don't know what it does. It serializes the sensor properties
Parameters
| Parameter | Description |
|---|---|
data (in) | where the property is written; throws server::SerializationError if it does not fit |
Returns where the next data should be written
getProperties
const OpticalFlowCameraProperties &getProperties() constReturns The camera properties.
setProperties
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
| Parameter | Description |
|---|---|
prop (in) | New properties. name and full_name must match the current ones (fatal error otherwise). |
getFlowArray
const std::vector<float> &getFlowArray() constFlow image, width * height * 2 floats (see the class comment).
Returns The image.
std::vector<float> &getFlowArray()Mutable access for MANUAL measurements (renderers); keep its size.
Returns The image.
getMaskArray
const std::vector<uint8_t> &getMaskArray() constValidity mask, width * height bytes of kHit | kHasHistory | kInFrame | kVisible bits.
Returns The mask.
std::vector<uint8_t> &getMaskArray()Mutable access for MANUAL measurements (renderers); keep its size.
Returns The mask.
setFlowArray
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
| Parameter | Description |
|---|---|
flow (in) | New flow image. |
setMaskArray
void setMaskArray(const std::vector<uint8_t> &mask)Replace the delivered mask directly, without latency. Fatal error unless it has width * height values.
Parameters
| Parameter | Description |
|---|---|
mask (in) | New mask. |
getCaptureFlowArray
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
std::vector<uint8_t> &getCaptureMaskArray()Mask that receives the next capture (see getCaptureFlowArray()).
Returns Writable capture mask.
commitCapture
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
| Parameter | Description |
|---|---|
acquisitionTime (in) | World time of the capture (s); must be finite with a latency. |
getDeliveryTimeStamp
double getDeliveryTimeStamp() constReturns World time at which the delivered capture was delivered (its acquisition time without latency); negative before the first.
getDroppedCaptureCount
uint64_t getDroppedCaptureCount() constReturns Captures dropped because the latency queue was full, since the properties last changed.
getPendingCaptureCount
size_t getPendingCaptureCount() constReturns Captures waiting for delivery.
resetNoise
void resetNoise() noexceptRestart the latency-jitter stream from the sensor identity, owner id and World environment seed.
resetHistory
void resetHistory()Forget the previous capture: the next capture has no history (kHasHistory clear, zero flow).
hasHistory
bool hasHistory() constReturns whether update() has a previous capture to compute the flow against.
getHistoryEpoch
uint64_t getHistoryEpoch() constReturns 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
void update(class World &world) finalRay-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
| Parameter | Description |
|---|---|
world (in) | the world that the sensor is in |
getRayDirections
const CameraRayDirections &getRayDirections() constReturns Ray directions in the sensor frame, one per pixel (see computeCameraRayDirections()). setProperties() and World::restoreCheckpoint() replace the table.
Static member functions
getType static
static Type getType()Returns Sensor::Type::OPTICAL_FLOW.
Public attributes
kHit
static constexpr uint8_t kHitMask bit: the pixel sees a surface.
kHasHistory
static constexpr uint8_t kHasHistoryMask bit: the previous capture (and the surface's body in it) exists.
kInFrame
static constexpr uint8_t kInFrameMask bit: the previous pixel position is inside the image, on a pixel that has a ray.
kVisible
static constexpr uint8_t kVisibleMask 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