Skip to content

Rayrai Example: Ground Truth ​

Overview ​

A camera head on a joint swings slowly left and right while a blue crate slides and turns and a yellow ball circles in front of it. The head carries four cameras with the same lens and resolution (256 x 160): an RGB camera that rayrai renders, and a segmentation camera, a normal camera and an optical-flow camera that RaiSim ray casts. A 2 x 2 grid shows:

  • the RGB image with the tight 2D box of every object, named by its class and world index (the floor is left out),
  • the segmentation labels,
  • the surface normals in the camera's OpenCV frame, drawn as (n + 1) / 2,
  • the backward optical flow since the previous capture.

Target ​

CMake target: rayrai_ground_truth.

Run ​

From the repository root, build the target and run it:

bash
source ./raisim_env.sh
cmake --build build-examples --target rayrai_ground_truth --parallel 2
./build-examples/examples/rayrai_ground_truth

See Build examples to configure a new build directory.

On Windows, run rayrai_ground_truth.exe instead. This example renders in process with rayrai and does not need rayrai_tcp_viewer.

Controls ​

  • Flow for full color: the flow length, in pixels, drawn with full color. The hue gives the direction a point came from and the saturation its distance; pixels without valid flow are dark, and points that were hidden at the previous capture are drawn at half brightness.
  • Export to temp dir writes the current capture to raisim_ground_truth in the system's temporary folder (usually /tmp/raisim_ground_truth on Linux) and prints the folder:
    • rgb.png: the color image,
    • flow.flo: the flow as a Middlebury .flo file,
    • flow_kitti.png: the flow as a KITTI 16-bit PNG, valid where the point is in the image at both captures,
    • normals.png: the normals as a 16-bit PNG,
    • instances.json: the boxes and instance masks as COCO detections, with the world's segmentation classes as categories.

Save the window ​

The capture that the rayrai examples share (see rayrai/example_common.hpp) saves the window as a PNG and exits:

bash
RAYRAI_EXAMPLE_CAPTURE=ground_truth.png ./build-examples/examples/rayrai_ground_truth

Details ​

  • Declares the cameras in the sensor XML: type="segmentation" with <segmentation type="panoptic"/>, type="normal" with <normal frame="camera"/> and type="optical_flow", each inside <camera>.
  • Keeps the three ground-truth cameras on the MANUAL source and calls their update(world) after every World::integrate(), so all three images and the flow history belong to the same captures.
  • Moves the crate and the ball with setPosition() and setOrientation(); the flow follows the poses of the bodies at the two captures.
  • Computes the boxes with raisim::computeBoundingBoxes2D(segmentationCamera, boxes) and writes the files with writeMiddleburyFlow(), writeKittiFlowPng(), writeNormalPng(), makeCocoImage() and writeCocoDetectionJson() (raisim/sensors/GroundTruthIo.hpp).
  • The ground-truth cameras see the collision shapes; here they are the same primitives rayrai draws.

See Normal camera, Optical-flow camera, Bounding boxes and Ground-truth files for the images, their conventions and the file formats.

RaiSim — physics for robotics and AI.