Skip to content

feat(driver): expose per-frame ExposureTime via JNI#33

Merged
mcm001 merged 3 commits into
PhotonVision:masterfrom
JosephTLockwood:feature/per-frame-exposure-time
May 15, 2026
Merged

feat(driver): expose per-frame ExposureTime via JNI#33
mcm001 merged 3 commits into
PhotonVision:masterfrom
JosephTLockwood:feature/per-frame-exposure-time

Conversation

@JosephTLockwood

Copy link
Copy Markdown

Why

PhotonVision's libcamera path currently publishes the start-of-exposure timestamp from libcamera::controls::SensorTimestamp as the "image capture time." The scene a detector integrates over actually spans [SOE, SOE+exposure], so the closest single-instant approximation is the midpoint of that window. Surfacing per-frame ExposureTime from libcamera is the prerequisite for the consumer-side mid-exposure correction in PhotonVision/photonvision (PR linked once opened).

What

  • Read libcamera::controls::ExposureTime alongside the existing SensorTimestamp in camera_runner.cpp and propagate it through gpu_queueMatPair.
  • New JNI entry Java_org_photonvision_raspi_LibCameraJNI_getFrameExposureTimeUs returns the value in microseconds, matching the existing uS-based exposure setter in this repo.
  • value_or(0) from libcamera + MatPair zero-init means callers get 0 when the metadata wasn't populated for the frame, which the consumer treats as "unknown" and leaves the timestamp uncorrected.

Verification

  • ./gradlew compileJava and ./gradlew publishToMavenLocal succeed locally.
  • The cmake build (and the actual Pi-side validation) is exercised by the existing arm-runner CI job.
  • Consumer PR builds green against the locally-published patched jar.

Scope notes

  • Single-purpose change. No refactors of unrelated code in the runner.
  • USB / V4L path is intentionally untouched: that path has separate caveats around proprietary exposure scales (some Arducam V4L drivers) and unreliable per-frame metadata under auto-exposure. Out of scope here.

Adds getFrameExposureTimeUs returning libcamera's ExposureTime in
microseconds. Returns 0 when metadata is absent so consumers can
detect "unknown" and leave timestamps uncorrected.
@JosephTLockwood

Copy link
Copy Markdown
Author

Paired PhotonVision consumer PR: PhotonVision/photonvision#2489

Comment thread src/libcamera_jni.cpp Outdated
Comment on lines +444 to +446
// 0 means libcamera did not populate ExposureTime metadata for this
// frame. Consumers should treat 0 as "unknown" and not attempt the
// SOE -> mid-exposure timestamp correction.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 0 means libcamera did not populate ExposureTime metadata for this
// frame. Consumers should treat 0 as "unknown" and not attempt the
// SOE -> mid-exposure timestamp correction.

MatPair::exposureTimeUs already includes this comment

Comment thread src/camera_runner.cpp Outdated
Comment thread src/camera_runner.cpp
@mcm001 mcm001 merged commit 1c68e03 into PhotonVision:master May 15, 2026
5 checks passed
@JosephTLockwood JosephTLockwood deleted the feature/per-frame-exposure-time branch May 15, 2026 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants