-
Notifications
You must be signed in to change notification settings - Fork 192
Add device ID to image transformations #1942
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,8 +17,25 @@ | |
| #include "pipeline/utilities/Alignment/AlignmentUtilities.hpp" | ||
| namespace dai { | ||
|
|
||
| namespace { | ||
|
|
||
| constexpr float ROUND_UP_EPS = 1e-3f; | ||
|
|
||
| bool differentKnownDeviceIds(const ImgTransformation& lhs, const ImgTransformation& rhs) { | ||
| const auto& lhsDeviceId = lhs.getDeviceId(); | ||
|
Comment on lines
+24
to
+25
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| const auto& rhsDeviceId = rhs.getDeviceId(); | ||
| return !lhsDeviceId.empty() && !rhsDeviceId.empty() && lhsDeviceId != rhsDeviceId; | ||
| } | ||
|
|
||
| void validateSameKnownDevice(const ImgTransformation& lhs, const ImgTransformation& rhs, const std::string& operation) { | ||
| if(differentKnownDeviceIds(lhs, rhs)) { | ||
| throw std::runtime_error( | ||
| fmt::format("Cannot {} ImgTransformations from different devices: '{}' and '{}'.", operation, lhs.getDeviceId(), rhs.getDeviceId())); | ||
| } | ||
| } | ||
|
|
||
| } // namespace | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lets remove the codex generated anonymous namespace :) |
||
|
|
||
| // Function to check if a point is inside a rotated rectangle | ||
| inline bool isPointInRotatedRectangle(const dai::Point2f& p, const dai::RotatedRect& rect) { | ||
| auto theta = -rect.angle * (float)M_PI / 180.0f; | ||
|
|
@@ -50,6 +67,7 @@ inline bool RRinRR(const dai::RotatedRect& in, const dai::RotatedRect& out) { | |
| } | ||
|
|
||
| dai::Point2f interSourceFrameTransform(dai::Point2f sourcePt, const ImgTransformation& from, const ImgTransformation& to) { | ||
| validateSameKnownDevice(from, to, "remap between"); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| if(from.isEqualTransformation(to)) { | ||
| return sourcePt; | ||
| } | ||
|
|
@@ -67,6 +85,7 @@ dai::Point2f interSourceFrameTransform(dai::Point2f sourcePt, const ImgTransform | |
| } | ||
|
|
||
| dai::RotatedRect interSourceFrameTransform(const dai::RotatedRect& sourceRect, const ImgTransformation& from, const ImgTransformation& to) { | ||
| validateSameKnownDevice(from, to, "remap between"); | ||
| if(from.isEqualTransformation(to)) { | ||
| return sourceRect; | ||
| } | ||
|
|
@@ -119,6 +138,7 @@ bool ImgTransformation::isEqualTransformation(const ImgTransformation& other) co | |
| auto thisExtrinsics = getExtrinsics(); | ||
| auto otherExtrinsics = other.getExtrinsics(); | ||
| if(!thisExtrinsics.isEqualExtrinsics(otherExtrinsics)) return false; | ||
| if(getDeviceId() != other.getDeviceId()) return false; | ||
|
|
||
| if(getSize() != other.getSize()) return false; | ||
| if(getSourceSize() != other.getSourceSize()) return false; | ||
|
|
@@ -239,6 +259,9 @@ std::vector<float> ImgTransformation::getDistortionCoefficients() const { | |
| Extrinsics ImgTransformation::getExtrinsics() const { | ||
| return extrinsics; | ||
| } | ||
| const std::string& ImgTransformation::getDeviceId() const { | ||
| return deviceId; | ||
| } | ||
| std::vector<dai::RotatedRect> ImgTransformation::getSrcCrops() const { | ||
| return srcCrops; | ||
| } | ||
|
|
@@ -351,6 +374,10 @@ ImgTransformation& ImgTransformation::setExtrinsics(const Extrinsics& extrinsics | |
| this->extrinsics = extrinsics; | ||
| return *this; | ||
| } | ||
| ImgTransformation& ImgTransformation::setDeviceId(const std::string& deviceId) { | ||
| this->deviceId = deviceId; | ||
| return *this; | ||
| } | ||
| ImgTransformation& ImgTransformation::setDistortionModel(CameraModel model) { | ||
| distortionModel = model; | ||
| return *this; | ||
|
|
@@ -528,10 +555,12 @@ std::array<float, 3> ImgTransformation::getTranslationVectorTo(const ImgTransfor | |
| std::array<std::array<float, 4>, 4> ImgTransformation::getExtrinsicsTransformationMatrixTo(const ImgTransformation& to, | ||
| const bool useSpecTranslation, | ||
| const LengthUnit sourceUnit) const { | ||
| validateSameKnownDevice(*this, to, "get extrinsics transformation between"); | ||
| return this->extrinsics.getExtrinsicsTransformationTo(to.getExtrinsics(), useSpecTranslation, sourceUnit); | ||
| } | ||
|
|
||
| bool ImgTransformation::isAlignedTo(const ImgTransformation& to) const { | ||
| if(differentKnownDeviceIds(*this, to)) return false; | ||
| if(width != to.width || height != to.height) return false; | ||
| if(this->distortionModel != to.distortionModel) return false; | ||
| auto approxEqual = [](float a, float b, float absTol = ROUND_UP_EPS, float relTol = 2 * ROUND_UP_EPS) { | ||
|
|
||
There was a problem hiding this comment.
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?