DocumentationComponentsVision

Tune with snapshots

How to record what the vision unit sees and computes as a snapshot, change a parameter, take another and compare the two, step by step.

Tuning the unit's parameters needs results you can keep and compare. The dashboard and the log show the unit as it is now. They keep nothing of what it did before your change. The snapshot exporter records a snapshot: a burst of stereo pairs and the state the unit was in, as one zip of plain files. Take one snapshot before a change and one after, then compare them. This guide is written to be followed step by step, by a person or by an agent.

A snapshot tells you what a change did and by how much. It does not score the result: whether it is better is your decision.

#The loop

  1. Put the unit in front of a still scene, under steady light (The fixed scene).
  2. Take a snapshot, before.zip (Take a snapshot).
  3. Change one thing. Change a parameter through the API or the dashboard (Change a parameter has the request). Upload a firmware when the change is in the build or the code.
  4. Take a snapshot, after.zip.
  5. Compare the two (Compare two snapshots).
  6. Decide: keep the change or discard it, and start again at step 2 from the state you kept.

Change one thing between two snapshots, or you cannot tell which change did what. Before step 3, you can take a second snapshot with nothing changed and compare it with the first. The differences you see are the noise between snapshots of one setup, which a real change has to exceed.

A parameter you change through the API or the dashboard is unsaved until you save it, and a reboot drops it. Each snapshot records every parameter's value, its saved value and its state, so you can tell what was unsaved when you took it.

#Enable the exporter

The exporter is off until your vehicle's composer lists it among its exporters::

elixir
%VisionCore.Config{
  components: [stereo_component()],
  exporters: [{VisionCore.Snapshot.Exporter, []}]
}

The exporter is VisionCore.Snapshot.Exporter, with the id snapshot and the name "Snapshot". A change to the composer reaches the unit with a firmware upload (Vision unit).

The exporter reads the stereo unit's pairs, and the detections when the configuration has a detector. It does nothing with them between snapshots. Without a stereo unit it does not start: GET /api/exporters lists it at the level off, with the detail "Not started: no stereo unit to take a snapshot of", and its action answers a 503.

Its options are the second element of the tuple, for example {VisionCore.Snapshot.Exporter, burst_ms: 5_000}:

OptionDefaultMeaning
burst_pairs30The fewest pairs a burst records.
burst_ms3_000The shortest time a burst lasts. A burst ends when both are reached.
settle_ms2_000How old the last change must be for a burst to start.
deadline_ms30_000The time from the request to the end of the burst.
frames_kept30How many of the burst's first pairs keep their raw frames.
status_snapshot_delay_ms1_000How long after the burst starts a status snapshot must arrive to be kept.

The settle wait counts against deadline_ms. If you raise burst_pairs or burst_ms, raise deadline_ms with them. Keep it, with the encoding, under the 60 s the API waits for an answer (Take a snapshot). VisionCore.Snapshot.Exporter documents the remaining options, whose defaults read the running unit.

#Take a snapshot

The exporter has one action, take, which answers a zip. From the API:

sh
curl --cacert vision.pem --fail-with-body -X POST https://<vehicle>-vision.local/api/exporters/snapshot/actions/take \
  -H 'content-type: application/vnd.api+json' \
  -d '{"data": {"type": "exporter-actions"}}' \
  -o before.zip

--fail-with-body needs curl 7.76 or later. On an error answer, curl exits with 22 and before.zip holds the JSON error, not a zip: check the exit status before you use the file.

From the dashboard, open Exporters in the menu, then Snapshot, and click Take snapshot. When the snapshot ends, the browser downloads the zip.

A snapshot lasts at least burst_ms. It runs in this order:

  1. Settle. The exporter waits until the last change to the unit is settle_ms old (The settle time).
  2. Burst. It records the pairs the stereo pipeline publishes, for at least burst_ms and at least burst_pairs pairs, whichever ends later. The pairs are in the order the pipeline published them, but not always consecutive. A pair the pipeline dropped while busy, or one the exporter skipped while it was behind, is not in the burst. intervalMs is longer where a pair is missing.
  3. Answer. It collects the unit's state, encodes the zip and answers. The unit keeps nothing of it: no history, no list of snapshots.

A snapshot changes nothing on the unit, and the status of the exporter reads "Taking a snapshot" from the request until the answer. One snapshot is taken at a time. The API waits up to 60 s for the answer. After that it answers a 504 while the exporter goes on, and answers a 409 to the next request until the exporter has finished. The unit answers:

AnswerMeaningWhat to do
200The zip.
409Another snapshot is being taken.Wait for it, then ask again.
504The burst did not end within deadline_ms, or the API's 60 s ran out. For the burst, the detail names how many pairs arrived.Look for a pipeline or cameras that stopped, a unit too slow for the burst, or parameters still changing: each change restarts the settle wait.
500The snapshot failed. The detail holds the message.Read it. It names, for example, a last pair without images, disparity or depth, on a unit whose stages do not provide them.
503The exporter does not run.Read its status on the status channel, or on the dashboard's Exporters menu.
404No snapshot exporter.Add it to your composer and upload the firmware.
400The request has no JSON:API document.Send the document as in the example above.

#The fixed scene

The comparison assumes the unit does not move and nothing in front of it does: the unit sits facing a still scene, and the light stays steady. What a snapshot compares is then the unit's computation, not the scene. If the scene changes between two snapshots, you cannot tell its effect from the effect of your change.

Take both snapshots the same way: from the API both times, or from the dashboard both times, with the same pages open (Traps).

#The settle time

A change to the unit does not show in the pairs at once. The temporal filter carries the previous pairs' disparity, and a live setting applies from the next pair, or from the second one with native stages (Two pairs in flight). So the exporter does not start a burst on a unit that changed a moment ago.

A change is anything that alters what the stages compute or what the cameras deliver:

  • the stereo pipeline's start, which a reboot after a firmware upload includes;
  • any change of the pipeline's options: a parameter, the automatic row-offset correction (stereo.rectification.auto_row_offset, with the default prefix) or a calibration reload. A setting set to the value it already has is not a change;
  • any parameter applied through VisionCore.Parameters, the camera controls included.

The exporter takes the age of the later of the pipeline's last change and the parameters' last change. Under settle_ms, it waits until the age reaches it, then starts the burst. It records that age in the manifest as changeAgeMs, in milliseconds. If a change happens during the burst, the manifest's changesDuringBurst is 1, and the snapshot is not comparable: take it again.

The light, and what auto exposure does in answer to it, are not changes the exporter sees (Traps).

#What a snapshot holds

The zip has one top directory with the same name, vision-snapshot-<hostname>-<UTC timestamp>, where the timestamp reads YYYYMMDDTHHMMSSZ. Its README.md describes the other files.

FileContent
README.mdWhat each file is, the burst size, and how the snapshot was taken.
manifest.jsonTime, hostname, firmware, burst size, the age of the last change, the image size and the format of each binary file.
parameters.jsonEvery parameter: id, value, saved (the saved value) and state.
configuration.jsonThe unit's configuration, as VisionCore.settings/0 returns it.
calibration/left.yaml, calibration/right.yamlThe calibration files in use, as they are.
figures.jsonThe figures of each pair and of each status snapshot, and a summary of each figure.
timings.jsonEach stage's time over the burst.
detections.jsonWhat the detector published during the burst. Present only on a unit with detection.
frames/NNN-left.*, frames/NNN-right.*The raw frames of the first frames_kept pairs, as the cameras delivered them: grey frames as 8-bit PNG (.png), JPEG frames as the JPEG bytes (.jpg). NNN is the pair's index in the burst, from 000.
last/left-rectified.png, last/right-rectified.pngThe last pair's rectified images, 8-bit PNG.
last/disparity.f32The last pair's disparity: little-endian float32 in pixels, row-major, with the shape in the manifest. A pixel is matched when its value is above 0.
last/disparity.pngThe same disparity coloured for viewing, unmatched pixels black.
last/depth.pngThe last pair's depth: 16-bit PNG in millimetres, 0 where there is none.
last/depth-coloured.jpgThe depth as the dashboard colours it, blue at infinity whatever range the dashboard shows, so the colours of two snapshots compare. Present when it could be encoded.

#manifest.json

FieldMeaning
time, hostname, firmwareWhen and where the snapshot was taken, and the firmware: its revision, target and the Nerves system.
burstPairs, framesKeptThe pairs in the burst, and how many keep their raw frames.
statusSnapshots, statusAvailableThe status snapshots kept, and whether the unit's status could be read.
changeAgeMsHow long before the burst the last change was, in milliseconds; null when none was recorded.
changesDuringBurst0 or 1: whether anything changed during the burst.
imageSizewidth and height of the images.
formatsThe format of each binary file. For last/disparity.png, colourRangePx gives the disparities the colours span.

#figures.json

figures.json has three members:

  • pairs, one entry per burst pair;
  • snapshots, one entry per status snapshot;
  • summary, which holds mean, min, max, std and n for each figure with a number.

std is the population standard deviation and n counts the samples. A figure that was not measured on a pair is null for it and not counted. The names are camelCase, and a name ending in Ms, Px, Hz, Percent or Rows says its unit.

FigureInMeaning
intervalMspairsTime since the burst's previous pair, in milliseconds, longer where a pair is missing. The depth rate is 1000 divided by its mean. The burst's first pair has none.
deviceMspairsThe time the pair spent at the stereo device, from its hand-over to the device's reply, in milliseconds. The download of its outputs is left out.
sharpnessLeft, sharpnessRightpairsEach rectified image's sharpness. The scene sets the absolute value; see Stereo stages.
alignmentOffsetRowspairsHow far the right image's rows sit from the left one's, in rows. Within half a row, the calibration fits. null when it cannot be measured.
alignmentBandOffsetRowspairsThe same per vertical band, as a list. It has no summary.
matchedPercentpairsThe share of matched pixels. A pixel is matched when its disparity is above 0.
meanDisparityPx, spreadPxpairsThe mean and spread of the matched pixels' disparity, in pixels.
jitterPxpairsHow much a pixel's disparity changes from one pair to the next, in pixels: the matcher's noise on a still scene.
alignRowspairsThe RowAlignment stage's offset over the whole image, the same value as alignmentOffsetRows.
depthHzsnapshotsDepth images computed in the last second.
stereoLoadPercent, cpuPercentsnapshotsThe share of the second the pairs spent at the stereo device (Reading the figures), and the processors' busy share.
leftCameraFps, rightCameraFpssnapshotsFrames each camera delivered in the last second.
leftCameraExposureTimeUs, leftCameraAnalogueGain, leftCameraColourTemperature, and the rightCamera onessnapshotsWhat each camera reports, when it reports it.
syncPairs, syncOffsetMedianMs, syncOffsetMaxMssnapshotsThe cameras' synchronisation, as on the dashboard.

matchedPercent, meanDisparityPx, spreadPx, jitterPx and alignRows are metrics a stage reports, under the stage's name for them. Any other figure of the pairs is one too, and the stage's module documents it.

The first four come from the Quality stage (Stereo stages). It measures the final disparity, after the temporal filter: held matches raise matchedPercent and smoothing lowers jitterPx. To measure the matcher alone, set the temporal filter's alpha to 1 and hold to 0 for both snapshots.

A figure of the pairs has a sample for each pair of the burst. A status snapshot describes one second, so a figure of the status snapshots has only a few samples, and the comparison task never judges it against its spread.

#timings.json

One entry for each stage, with median, p95 and max in milliseconds over the burst's pairs, and n. The names are the pipeline's:

  • A stage is named after its module, underscored: SpeckleFilter is speckle_filter.
  • Consecutive stages that run on one device form a segment, timed as one entry named after its members joined with +. The members of a native segment are timed under their own names too.
  • total is the time from the pipeline taking a pair to just before it publishes it.

#detections.json

A list with one entry for each publication during the burst: the captureNs of the pair, or of the camera's frame for a detector on a camera of its own, and its detections. Each detection has label, score, distanceM and outline. The outline is the [x, y] vertices as fractions of the width and height of the image the detections were found on, the left image for the stereo pair, as in the API's detections event.

#Compare two snapshots

Run the commands of this section from the repository's root, with both zips there. Unzip both snapshots, each into a directory that does not exist yet, and run the comparison task on the two zips (The comparison task). The task prints most of what the steps below read. For what it does not print, the steps name the file each figure comes from.

sh
unzip -q before.zip -d before
unzip -q after.zip -d after

Each snapshot unzips into one top directory with its own timestamp, which the diff commands below match with *. A before that already holds an earlier snapshot breaks them. On a later pass, remove the two directories first (rm -rf before after) or use other names.

Follow the steps in order: each catches what would make the next one mislead you.

#1. Check that the two can be compared

The task's Snapshots block, or manifest.json in each snapshot, says how each was taken. Check that:

  • hostname is the same: both come from the same unit. firmware, the revision, is the same, unless the firmware is what you changed.
  • changes during the burst (changesDuringBurst) is 0 in both. A 1 means something changed while the burst ran: take that snapshot again.
  • status is available (statusAvailable is true) in both. Otherwise the figures of the status are missing.
  • last change before the burst (changeAgeMs) is a time in milliseconds, or none recorded.

Only the manifest has imageSize and statusSnapshots. Check that imageSize is the same in both: the task stops on two sizes. Check that statusSnapshots is not 0.

#2. The state: what changed between them

Compare the parameters. A parameter whose value differs is what you changed, or what changed by itself. The automatic row-offset correction moves stereo.rectification.right_row_offset, and a reboot drops the parameters you left unsaved. If a parameter differs that you did not change, find out why before you read the figures.

The task's Parameters section lists each parameter whose value differs in parameters.json, with - for a snapshot that lacks the parameter, or reads Parameters: none differ. It does not compare the configuration or the calibration; compare them yourself. diff exits with 1 when the files differ:

sh
diff before/*/configuration.json after/*/configuration.json
diff before/*/calibration/left.yaml after/*/calibration/left.yaml
diff before/*/calibration/right.yaml after/*/calibration/right.yaml

#3. The figures, against their spreads

Compare each figure's summary in figures.json. Its change is B's mean minus A's. The rule is the comparison task's. A change counts only when it is larger than the larger of the two std. It never counts:

  • for a figure of the status snapshots: its spread, over a few snapshots, is too rough to judge by;
  • when either figure has fewer than 3 samples: a figure with too few samples has no spread to judge by.

A change smaller than the spread is noise.

  • Read the figures of the pairs first: they have a sample for each pair of the burst. intervalMs gives the depth rate; matchedPercent and jitterPx tell how complete and how steady the depth is. On a fixed scene, a change beyond the spread in meanDisparityPx or spreadPx comes from the unit, not from the scene.
  • Read the figures of the status as indications. They have a few samples each, and the comparison task never judges them, however many there are: it reads status figure, not judged. For the depth rate, use intervalMs.
  • Check the cameras' exposure and gain by their values, not by a spread. leftCameraExposureTimeUs, leftCameraAnalogueGain and the rightCamera ones are status figures, which the task never judges. Compare their mean, min and max in figures.json; the Figures table shows the means. With auto exposure off, the values are equal in both snapshots. With it on, a difference between the means means the light moved: take the snapshots again once it is steady (Traps).
  • A figure that only one snapshot measured is named under the table, as Figures only in A: ... or Figures only in B: ..., and is not compared. Find out why: for example, the status was unavailable in one snapshot, or a stage that reports it is in one unit's stages only.

#4. The timings

Compare the median and p95 of each stage in timings.json, and of total, a pair's latency. A stage whose time grew is where your change cost time; one whose time shrank is where it saved some. The timings carry no std: p95 and max tell how far a stage's time varies.

The comparison task prints only the stages that both snapshots timed, and names the others under the table, as Stages only in A: ... or Stages only in B: .... Adding or removing a stage renames the segment that holds it, so the segment's old and new entries appear there.

#5. The images

Look at each snapshot's last pair: last/disparity.png, last/depth-coloured.jpg and the rectified pair. The comparison task counts and draws the difference between the two last pairs' disparity and depth:

  • The pixels matched in both, in A only and in B only (matched means a disparity above 0). The A-only pixels are the matches your change lost, the B-only pixels the matches it gained.
  • The mean absolute difference of the disparity, in pixels, and of the depth, in millimetres, over the pixels that both snapshots have a value for.
  • disparity-diff.png and depth-diff.png, 8-bit grey images of the snapshots' size. A pixel is black where neither snapshot has a value, and white where only one has. Otherwise it is as bright as the absolute difference: 32 grey levels for a pixel of disparity, 1 grey level for 4 mm of depth, capped at white. A difference of about 8 pixels of disparity, or about 1 m of depth, or more, is white too.

Each snapshot has one last pair, so its images carry the noise of a single pair. Read them against the noise between two snapshots of one setup. Run the comparison task once on two snapshots with nothing changed between them, and keep that result as the floor for the changed pair.

The colours of last/disparity.png span colourRangePx in the manifest: two snapshots compare by colour only when their ranges are the same. The first frames of each snapshot, frames/000-left.png and frames/000-right.png (or .jpg), show whether the scene and the light were the same.

#The comparison task

vision_core has a task for the host that prints the Snapshots, Parameters, Figures, Timings and pixel sections of the steps above. It runs in vision/core, on a workstation where mix compile works (Running it on a workstation). From the repository's root, run it in a subshell, so that your shell stays at the root for the other commands. The paths the task takes are relative to vision/core:

sh
(cd vision/core && mise exec -- mix vision_core.compare_snapshots ../../before.zip ../../after.zip --out ../../compare-out)

It prints five sections, with B read against A, and writes the two difference images to the directory --out names, compare-out by default. The paths it prints are the ones it was given, relative to vision/core. From the repository's root, the images of the example are in compare-out/. Figures, timings and pixel differences carry 4 significant digits, and one under 0.0001 reads in scientific notation, as 3.699e-06. Parameter values print in full. The values below are illustrative:

text
Snapshots
snapshot  hostname          time                  firmware  last change before the burst  changes during the burst  status     file
A       <vehicle>-vision  2026-11-03T14:02:11Z  ce99e251  5120 ms                       0                         available  ../../before.zip
B       <vehicle>-vision  2026-11-03T14:06:40Z  ce99e251  2003 ms                       0                         available  ../../after.zip

Parameters that differ
parameter            A  B
stereo.disparity.p1  8  10

Figures, change is B - A
figure                    A mean    A std      A n  B mean    B std      B n  change     against spread
intervalMs                38.41     1.907      29   38.6      2.114      29   0.189      within spread
jitterPx                  0.087     0.011      30   0.052     0.009      30   -0.035     beyond spread
leftCameraExposureTimeUs  33013     0          2    33013     0          2    0          status figure, not judged
matchedPercent            64.7      0.812      30   68.1      0.79       30   3.4        beyond spread
sharpnessLeft             0.004592  3.699e-06  30   0.004594  3.912e-06  30   2.000e-06  within spread
stereoLoadPercent         97.5      0.5        2    98.0      0          2    0.5        status figure, not judged

Timings, in milliseconds
stage           A median  B median  A p95  B p95
disparity       30.51     30.48     31.9   31.88
speckle_filter  3.301     3.296     3.512  3.54
total           61.25     61.19     66.4   66.31

Last pairs' pixels
matched in both                         60112
matched in A only                       1204
matched in B only                       3871
mean absolute disparity difference, px  0.412
mean absolute depth difference, mm      18.64

Difference images:
  ../../compare-out/depth-diff.png
  ../../compare-out/disparity-diff.png

The lines below show when no parameter differs, or a figure or a stage is in one snapshot only, each in its own section. The first replaces the Parameters table; the others come right below the Figures and Timings tables:

text
Parameters: none differ
Figures only in A: leftCameraLensPosition, rightCameraLensPosition
Stages only in B: median_filter
SectionWhat it holds
SnapshotsFor A, then B, what the manifest says: hostname, time, firmware (the revision), the last change before the burst, the changes during the burst, whether the status was available, and the file you gave. - where the manifest lacks a value.
ParametersEach parameter whose value differs, by id, under Parameters that differ; - where a snapshot lacks the parameter. When none differs, the section is the single line Parameters: none differ.
FiguresEach figure that both snapshots measured: the summaries side by side and the change. The last column reads within spread or beyond spread; status figure, not judged for a figure of the status snapshots; or too few samples for a figure of the pairs when either snapshot has fewer than 3 samples of it. A figure only one snapshot measured is named below the table, as Figures only in A: ... or Figures only in B: ....
TimingsThe median and the 95th percentile of each stage that both snapshots timed. A stage only one snapshot timed is named below the table, as Stages only in A: ... or Stages only in B: ....
Last pairs' pixelsThe counts of matched pixels and the mean differences of step 5. - where no pixel counts.

The task stops with a message that names the snapshot and the file when:

  • a file is not a zip;
  • a snapshot lacks a file the task reads: manifest.json, parameters.json, figures.json, timings.json, last/disparity.f32 or last/depth.png;
  • a snapshot holds one that is malformed;
  • the two snapshots' images differ in size.

The task does not read the configuration, the calibration, the frames or the detections: read them yourself. VisionCore.Snapshot.Compare documents each value.

#Traps

  • Auto exposure. With auto exposure on, the cameras change their exposure and gain with the light. The brightness of both images moves with them, with no parameter change. The exporter does not count it as a change. Compare the cameras' exposure and gain figures between the snapshots, by their values, as step 3 says.

    To take the cameras out of the comparison, switch auto exposure off and set the exposure and gain yourself, then tune. The switch is a parameter change: take the first snapshot after it. After a boot, or after switching auto exposure on, wait until the exposure figures are steady before you take a snapshot: the exporter waits only for settle_ms.

    The parameter ids depend on the camera driver. Read GET /api/parameters for the ids your unit has: the camera controls are the ids that start with stereo.cameras. (with the default prefix).

    • With VisionCore.Camera.LibCamera, the switches are stereo.cameras.auto_exposure and stereo.cameras.auto_gain, and the settings stereo.cameras.exposure_time_us and stereo.cameras.analogue_gain.
    • With VisionCore.Camera.V4L2Pair, the one switch is stereo.cameras.auto_exposure, which covers the gain too: there is no auto_gain. The settings are stereo.cameras.exposure_us and stereo.cameras.analogue_gain, which auto exposure keeps within stereo.cameras.max_exposure_us and stereo.cameras.max_gain.
  • Light. Daylight, a cloud, a lamp that you switch: any of them changes the images, and the matched pixels with them. Keep the light steady, and use the noise floor (The loop) to see what one setup does by itself.

  • An open dashboard. The unit encodes the previews only while a dashboard is showing them, and the encoding takes processor time. A dashboard open for one snapshot and closed for the other moves the depth rate and the load figures. Take both snapshots with the same pages open, or with none: use the API.

  • What else runs. The other exporters, the detection and the dashboard load the unit too: keep them the same for both snapshots.

  • Status figures. The depth rate of the status, the stereo load, the CPU and the cameras' rates have only a few samples per snapshot. The comparison task never judges their differences. Read them as indications; use intervalMs for the depth rate.

  • A change during the burst. A parameter you set, or the automatic row-offset correction moving, while the burst runs makes changesDuringBurst 1. Take the snapshot again.

  • A firmware upload. The unit reboots and drops its unsaved parameters; the new snapshot's parameters.json shows what is in force. The pipeline's start counts as a change, so the exporter waits settle_ms after it.

  • A different working size. Snapshots with different imageSize cannot be compared by the task.

#See also

This page is docs/vision/tuning.md in the ovcs repository; edit it there.