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:
source ./raisim_env.sh
cmake --build build-examples --target rayrai_ground_truth --parallel 2
./build-examples/examples/rayrai_ground_truthSee 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_truthin the system's temporary folder (usually/tmp/raisim_ground_truthon Linux) and prints the folder:rgb.png: the color image,flow.flo: the flow as a Middlebury.flofile,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:
RAYRAI_EXAMPLE_CAPTURE=ground_truth.png ./build-examples/examples/rayrai_ground_truthDetails
- Declares the cameras in the sensor XML:
type="segmentation"with<segmentation type="panoptic"/>,type="normal"with<normal frame="camera"/>andtype="optical_flow", each inside<camera>. - Keeps the three ground-truth cameras on the
MANUALsource and calls theirupdate(world)after everyWorld::integrate(), so all three images and the flow history belong to the same captures. - Moves the crate and the ball with
setPosition()andsetOrientation(); the flow follows the poses of the bodies at the two captures. - Computes the boxes with
raisim::computeBoundingBoxes2D(segmentationCamera, boxes)and writes the files withwriteMiddleburyFlow(),writeKittiFlowPng(),writeNormalPng(),makeCocoImage()andwriteCocoDetectionJson()(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.