-
Notifications
You must be signed in to change notification settings - Fork 127
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
Add bindings to ImgFrame for the new transformations API #1160
base: v3_develop
Are you sure you want to change the base?
Conversation
std::array<std::array<float, 3>, 3> ImgTransformation::getIntrinsicMatrix() const { | ||
return matmul(sourceIntrinsicMatrix, transformationMatrix); | ||
} | ||
std::array<std::array<float, 3>, 3> ImgTransformation::getIntrinsicMatrixInv() const { | ||
return matmul(transformationMatrixInv, sourceIntrinsicMatrixInv); | ||
} | ||
float ImgTransformation::getDFov() const { | ||
if(height <= 0) { | ||
throw std::runtime_error(fmt::format("Height is invalid. Height: {}", height)); | ||
} | ||
if(width <= 0) { | ||
throw std::runtime_error(fmt::format("Width is invalid. Width: {}", width)); | ||
} | ||
float HFovDegrees = getHFov(); | ||
|
||
// Calculate the diagonal ratio (DR) | ||
float dr = std::sqrt(std::pow(width, 2) + std::pow(height, 2)); | ||
|
||
// Validate the horizontal FOV | ||
if(HFovDegrees <= 0 || HFovDegrees >= 180) { | ||
throw std::runtime_error(fmt::format("Horizontal FOV is invalid. Horizontal FOV: {}", HFovDegrees)); | ||
} | ||
|
||
float HFovRadians = HFovDegrees * (static_cast<float>(M_PI) / 180.0f); | ||
|
||
// Calculate the tangent of half of the HFOV | ||
float tanHFovHalf = std::tan(HFovRadians / 2); | ||
|
||
// Calculate the tangent of half of the VFOV | ||
float tanDiagonalFovHalf = (dr / width) * tanHFovHalf; | ||
|
||
// Calculate the VFOV in radians | ||
float diagonalFovRadians = 2 * std::atan(tanDiagonalFovHalf); | ||
|
||
// Convert VFOV to degrees | ||
float diagonalFovDegrees = diagonalFovRadians * (180.0f / static_cast<float>(M_PI)); | ||
return diagonalFovDegrees; | ||
} | ||
float ImgTransformation::getHFov() const { | ||
float fx = getIntrinsicMatrix()[0][0]; | ||
|
||
// Calculate vertical FoV (in radians) | ||
float horizontalFoV = 2 * atan(width / (2.0f * fx)); | ||
|
||
// Convert radians to degrees | ||
return horizontalFoV * 180.0f / (float)M_PI; | ||
} | ||
float ImgTransformation::getVFov() const { | ||
float fy = getIntrinsicMatrix()[1][1]; | ||
|
||
// Calculate vertical FoV (in radians) | ||
float verticalFoV = 2 * atan(height / (2.0f * fy)); | ||
|
||
// Convert radians to degrees | ||
return verticalFoV * 180.0f / (float)M_PI; | ||
} |
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.
Let's also add implementations for source FOVs and then have ImgFrame just passthrough the calls to the ImgTransformations to have the functionality more centralized
…imgframe_bindings
* remap the point. | ||
* @param to Transformation to remap to | ||
* @param point Point to remap | ||
* @param normalized Set to true if the point is normalized | ||
*/ | ||
dai::Point2f remapPointTo(const ImgTransformation& to, dai::Point2f point) const; | ||
dai::Point2f remapPointTo(const ImgTransformation& to, dai::Point2f point, bool normalized = false) const; | ||
/** | ||
* Remap a point to this transformation from another. If the intrinsics are different (e.g. different camera), the function will also use the intrinsics to | ||
* remap the point. | ||
* @param from Transformation to remap from | ||
* @param point Point to remap | ||
* @param normalized Set to true if the point is normalized | ||
*/ | ||
dai::Point2f remapPointFrom(const ImgTransformation& from, dai::Point2f point) const; | ||
dai::Point2f remapPointFrom(const ImgTransformation& from, dai::Point2f point, bool normalized = false) const; | ||
/** | ||
* Remap a rotated rect from this transformation to another. If the intrinsics are different (e.g. different camera), the function will also use the | ||
* intrinsics to remap the rect. | ||
* @param to Transformation to remap to | ||
* @param rect RotatedRect to remap | ||
* @param normalized Set to true if the rect is normalized | ||
*/ | ||
dai::RotatedRect remapRectTo(const ImgTransformation& to, dai::RotatedRect rect) const; | ||
dai::RotatedRect remapRectTo(const ImgTransformation& to, dai::RotatedRect rect, bool normalized = false) const; | ||
/** | ||
* Remap a rotated rect to this transformation from another. If the intrinsics are different (e.g. different camera), the function will also use the | ||
* intrinsics to remap the rect. | ||
* @param from Transformation to remap from | ||
* @param point RotatedRect to remap | ||
* @param normalized Set to true if the rect is normalized | ||
*/ | ||
dai::RotatedRect remapRectFrom(const ImgTransformation& from, dai::RotatedRect rect) const; | ||
dai::RotatedRect remapRectFrom(const ImgTransformation& from, dai::RotatedRect rect, bool normalized = false) const; | ||
|
||
/** | ||
* Check if the transformations are valid. The transformations are valid if the source frame size and the current frame size are set. |
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.
I would add the normalized flag to dai::RotatedRect instead
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.
or is there a specific reason to keep to not add it?
No description provided.