Skip to content

Add device ID to image transformations - #1942

Open
pheec wants to merge 2 commits into
developfrom
feature/dev_tf_AddDeviceIdToImgTransformations
Open

Add device ID to image transformations#1942
pheec wants to merge 2 commits into
developfrom
feature/dev_tf_AddDeviceIdToImgTransformations

Conversation

@pheec

@pheec pheec commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Adds the source device ID to ImgTransformation.
The device ID is stored directly on the transformation instead of in Extrinsics, because extrinsics are part of per-camera EEPROM calibration data. Storing device-level information there would duplicate it for every camera.
This PR also:
Serializes and deserializes the device ID.
Exposes it through the C++ and Python APIs.
Propagates it through rectification.
Prevents remapping and alignment between transformations with different known device IDs.
Treats an empty device ID as unknown for compatibility with older replay datasets.
Adds tests for serialization, equality, alignment, remapping, and replay compatibility.

Summary by CodeRabbit

  • New Features

    • Image transformations now retain and expose their originating device ID.
    • Python APIs support reading and updating transformation device IDs.
    • Device ID metadata is preserved when transformations are serialized and restored.
  • Bug Fixes

    • Transformations between different known devices are now rejected to prevent invalid remapping.
    • Comparison and alignment checks now account for device identity.

@pheec
pheec changed the base branch from main to develop August 14, 2026 10:26
@coderabbitai

coderabbitai Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 717cc11d-1496-4475-9232-cbe305204e95

📥 Commits

Reviewing files that changed from the base of the PR and between 68bca7c and 8cd244c.

📒 Files selected for processing (8)
  • bindings/python/src/pipeline/datatype/ImgFrameBindings.cpp
  • include/depthai/common/ImgTransformations.hpp
  • protos/common.proto
  • src/pipeline/datatype/ImgTransformations.cpp
  • src/pipeline/node/Rectification.cpp
  • src/utility/ProtoSerialize.cpp
  • tests/src/ondevice_tests/img_transformation_test.cpp
  • tests/src/onhost_tests/image_transformations_test.cpp
📜 Recent review details
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2026-03-23T09:35:30.339Z
Learnt from: aljazkonec1
Repo: luxonis/depthai-core PR: 1728
File: protos/common.proto:20-25
Timestamp: 2026-03-23T09:35:30.339Z
Learning: In luxonis/depthai-core’s `protos/common.proto`, do not change existing enumerator values for the public `LengthUnit` and `CameraBoardSocket` enums, and do not prepend new zero-value entries like `UNSPECIFIED`. These enums are already released as public API and are used in serialized data; altering numeric values or changing the first/zero member will break backward compatibility with existing user code and stored/serialized representations.

Applied to files:

  • protos/common.proto
📚 Learning: 2026-03-24T22:39:04.364Z
Learnt from: MaticTonin
Repo: luxonis/depthai-core PR: 1732
File: src/pipeline/Pipeline.cpp:705-705
Timestamp: 2026-03-24T22:39:04.364Z
Learning: Do not flag the `!= ""` part of the auto-calibration condition as redundant when it appears in `PipelineImpl::build()` (or closely related pipeline build logic). If the code uses `utility::getEnvAs<std::string>(..., default)` with a default such as `"ON_START"`, the explicit empty-string guard may still be intentional to treat an explicitly empty env var as “OFF/disabled” (or to avoid special-casing elsewhere). Only consider removing `!= ""` if the codebase has an explicit, enforceable guarantee that `DEPTHAI_AUTOCALIBRATION` can never be set to an empty string (e.g., via validated parsing/CI checks); otherwise, keep the guard.

Applied to files:

  • src/pipeline/node/Rectification.cpp
  • src/pipeline/datatype/ImgTransformations.cpp
🔇 Additional comments (8)
include/depthai/common/ImgTransformations.hpp (1)

4-5: LGTM!

Also applies to: 29-29, 73-79, 157-165, 264-264, 416-417

protos/common.proto (1)

49-49: LGTM!

bindings/python/src/pipeline/datatype/ImgFrameBindings.cpp (1)

140-147: LGTM!

Also applies to: 169-169, 184-184

src/pipeline/datatype/ImgTransformations.cpp (1)

20-38: LGTM!

Also applies to: 70-70, 88-88, 141-141, 262-264, 377-380, 558-563

tests/src/onhost_tests/image_transformations_test.cpp (1)

7-7: LGTM!

Also applies to: 235-268

src/pipeline/node/Rectification.cpp (1)

94-102: LGTM!

Also applies to: 232-235

tests/src/ondevice_tests/img_transformation_test.cpp (1)

402-402: LGTM!

Also applies to: 415-416

src/utility/ProtoSerialize.cpp (1)

94-94: LGTM!

Also applies to: 189-189


📝 Walkthrough

Walkthrough

ImgTransformation now carries an optional source deviceId. The value is exposed through C++ and Python APIs, propagated by rectification, included in comparisons and cross-device validation, serialized through protobuf, and covered by host and on-device tests.

Changes

Device identity for image transformations

Layer / File(s) Summary
Transformation device ID contract
include/depthai/common/ImgTransformations.hpp, protos/common.proto, bindings/python/src/pipeline/datatype/ImgFrameBindings.cpp
ImgTransformation stores an optional deviceId, exposes getter and setter APIs, includes the field in serialized state, and exposes the constructor and methods to Python. The protobuf message adds field 11.
Cross-device transformation validation
src/pipeline/datatype/ImgTransformations.cpp, tests/src/onhost_tests/image_transformations_test.cpp
Equality and alignment compare device IDs. Remapping and extrinsics operations reject differing known device IDs. Tests cover matching, differing, absent, replay, and comparison cases.
Rectification device ID propagation
src/pipeline/node/Rectification.cpp, tests/src/ondevice_tests/img_transformation_test.cpp
Rectification passes input device IDs to output transformations. On-device tests verify that frame transformations contain the pipeline device ID.
Device ID serialization
src/utility/ProtoSerialize.cpp, tests/src/onhost_tests/image_transformations_test.cpp
Serialization writes and deserialization restores the transformation device ID. The host test covers the round trip.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 8cd24

The change adds and propagates device IDs for image transformations with compatibility handling and tests; no actionable merge-blocking risk remains beyond normal checks and review.

Possibly related PRs

  • luxonis/depthai-core#1904: Both changes update rectification processing and use ImgTransformation device or extrinsics metadata.

Suggested labels: testable

Suggested reviewers: aljazkonec1, asahtik

Poem

A rabbit checks the frame ID bright,
Carries it through transforms right.
Across-device paths now safely part,
Serialized with careful art.
Hop, hop—the metadata stays in sight!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding a device ID to image transformations.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/dev_tf_AddDeviceIdToImgTransformations

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@aljazkonec1
aljazkonec1 self-requested a review August 17, 2026 14:41

@aljazkonec1 aljazkonec1 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks, I'm struggling to understand the usefulness of having source device ID stored? This PR is then not meant for multi device support no?

CameraModel distortionModel = CameraModel::Perspective;
std::vector<float> distortionCoefficients;
Extrinsics extrinsics = {};
std::string deviceId;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

In the context of multi device pipelines, how would deviceId be used? Looking at the current code, it throws any time the deviceId is different. Is there a reason you decided against deviceId meaning the target device? Is there a reason why we need source device ID at all?

}
}

} // namespace

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

lets remove the codex generated anonymous namespace :)

Comment on lines +24 to +25
bool differentKnownDeviceIds(const ImgTransformation& lhs, const ImgTransformation& rhs) {
const auto& lhsDeviceId = lhs.getDeviceId();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

lhs and rhs arent general parameter names. From my understanding we will be using deviceId for multi-device cases so this naming really does not fit here

}

dai::Point2f interSourceFrameTransform(dai::Point2f sourcePt, const ImgTransformation& from, const ImgTransformation& to) {
validateSameKnownDevice(from, to, "remap between");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I would expand the function to also validate the toCameraSockets like it is done in the below lines. Also if deviceId means target device to where it is pointing to, then we should make it a member funciton of Extrnisics

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