Struct ImgTransformation
Defined in File ImgTransformations.hpp
Struct Documentation
-
struct ImgTransformation
ImgTransformation struct. Holds information of how a ImgFrame or related message was transformed from their source. Useful for remapping from one ImgFrame to another.
Public Functions
-
ImgTransformation() = default
-
inline ImgTransformation(size_t width, size_t height)
-
inline ImgTransformation(size_t srcWidth, size_t srcHeight, size_t width, size_t height)
-
inline ImgTransformation(size_t width, size_t height, std::array<std::array<float, 3>, 3> sourceIntrinsicMatrix)
-
inline ImgTransformation(size_t width, size_t height, std::array<std::array<float, 3>, 3> sourceIntrinsicMatrix, CameraModel distortionModel, std::vector<float> distortionCoefficients)
-
inline ImgTransformation(size_t width, size_t height, std::array<std::array<float, 3>, 3> sourceIntrinsicMatrix, CameraModel distortionModel, std::vector<float> distortionCoefficients, Extrinsics extrinsics)
-
dai::Point2f transformPoint(dai::Point2f point) const
Transform a point from the source frame to the current frame.
- Parameters:
point – Point to transform
- Returns:
Transformed point
-
dai::RotatedRect transformRect(dai::RotatedRect rect) const
Transform a rotated rect from the source frame to the current frame.
- Parameters:
rect – Rectangle to transform
- Returns:
Transformed rectangle
-
dai::Point2f invTransformPoint(dai::Point2f point) const
Transform a point from the current frame to the source frame.
- Parameters:
point – Point to transform
- Returns:
Transformed point
-
dai::RotatedRect invTransformRect(dai::RotatedRect rect) const
Transform a rotated rect from the current frame to the source frame.
- Parameters:
rect – Rectangle to transform
- Returns:
Transformed rectangle
-
std::pair<size_t, size_t> getSize() const
Retrieve the size of the frame. Should be equal to the size of the corresponding ImgFrame message.
- Returns:
Size of the frame
-
std::pair<size_t, size_t> getSourceSize() const
Retrieve the size of the source frame from which this frame was derived.
- Returns:
Size of the frame
-
std::array<std::array<float, 3>, 3> getMatrix() const
Retrieve the transformation matrix from the source frame to the current frame.
- Returns:
Transformation matrix
-
std::array<std::array<float, 3>, 3> getMatrixInv() const
Retrieve the inverse transformation matrix from the current frame to the source frame.
- Returns:
Inverse transformation matrix
-
std::array<std::array<float, 3>, 3> getSourceIntrinsicMatrix() const
Retrieve the intrinsic matrix of the source sensor.
- Returns:
Intrinsic matrix
-
std::array<std::array<float, 3>, 3> getSourceIntrinsicMatrixInv() const
Retrieve the inverse intrinsic matrix of the source sensor.
- Returns:
Inverse intrinsic matrix
-
CameraModel getDistortionModel() const
Retrieve the distortion model of the source sensor
- Returns:
Distortion model
-
std::vector<float> getDistortionCoefficients() const
Retrieve the distortion coefficients of the source sensor
- Returns:
vector of distortion coefficients
-
Extrinsics getExtrinsics() const
Retrieve the extrinsics to the source sensor.
- Returns:
-
bool isEqualTransformation(const ImgTransformation &other) const
Two transformations are equal if the transformation matrices, intrinsic matrices, distortion models, distortion coefficients, extrinsics, and sizes are all equal.
- Parameters:
other – Transformation to compare with
- Returns:
True if the transformations are equal, false otherwise
-
inline std::array<std::array<float, 3>, 3> getTransformationMatrix() const
-
inline std::array<std::array<float, 3>, 3> getTransformationMatrixInv() const
-
std::array<std::array<float, 3>, 3> getIntrinsicMatrix() const
Retrieve the total intrinsic matrix calculated from transform * intrinsic.
- Returns:
total intrinsic matrix
-
std::array<std::array<float, 3>, 3> getIntrinsicMatrixInv() const
Retrieve the inverse of the total intrinsic matrix.
- Returns:
inverse total intrinsic matrix
-
float getDFov(bool source = false) const
Retrieve the diagonal field of view of the image.
- Parameters:
source – If true, the source field of view will be returned. Otherwise, the current field of view will be returned.
- Returns:
Diagonal field of view in degrees
-
float getHFov(bool source = false) const
Retrieve the horizontal field of view of the image.
- Parameters:
source – If true, the source field of view will be returned. Otherwise, the current field of view will be returned.
- Returns:
Horizontal field of view in degrees
-
float getVFov(bool source = false) const
Retrieve the vertical field of view of the image.
- Parameters:
source – If true, the source field of view will be returned. Otherwise, the current field of view will be returned.
- Returns:
Vertical field of view in degrees
-
std::vector<dai::RotatedRect> getSrcCrops() const
-
bool getSrcMaskPt(size_t x, size_t y)
Returns true if the point is inside the transformed region of interest (determined by crops used).
-
bool getDstMaskPt(size_t x, size_t y)
Returns true if the point is inside the image region (not in the background region).
-
ImgTransformation &addTransformation(std::array<std::array<float, 3>, 3> matrix)
Add a new transformation.
- Parameters:
matrix – Transformation matrix
-
ImgTransformation &addCrop(int x, int y, int width, int height)
Add a crop transformation.
- Parameters:
x – X coordinate of the top-left corner of the crop
y – Y coordinate of the top-left corner of the crop
width – Width of the crop
height – Height of the crop
-
ImgTransformation &addPadding(int top, int bottom, int left, int right)
Add a pad transformation. Works like crop, but in reverse.
- Parameters:
top – Padding on the top
bottom – Padding on the bottom
left – Padding on the left
right – Padding on the right
-
ImgTransformation &addFlipVertical()
Add a vertical flip transformation.
-
ImgTransformation &addFlipHorizontal()
Add a horizontal flip transformation.
-
ImgTransformation &addRotation(float angle, dai::Point2f rotationPoint)
Add a rotation transformation.
- Parameters:
angle – Angle in degrees
rotationPoint – Point around which to rotate
-
ImgTransformation &addScale(float scaleX, float scaleY)
Add a scale transformation.
- Parameters:
scaleX – Scale factor in the horizontal direction
scaleY – Scale factor in the vertical direction
-
ImgTransformation &addSrcCrops(const std::vector<dai::RotatedRect> &crops)
-
ImgTransformation &setSize(size_t width, size_t height)
-
ImgTransformation &setSourceSize(size_t width, size_t height)
-
ImgTransformation &setExtrinsics(const Extrinsics &extrinsics)
-
ImgTransformation &setIntrinsicMatrix(std::array<std::array<float, 3>, 3> intrinsicMatrix)
-
ImgTransformation &setDistortionModel(CameraModel model)
-
ImgTransformation &setDistortionCoefficients(std::vector<float> coefficients)
-
dai::Point2f remapPointTo(const ImgTransformation &to, dai::Point2f point) const
Remap a point from this transformation to another. If the intrinsics are different (e.g. different camera), the function will also use the intrinsics to remap the point.
Note
This function assumes both transformations have the same source (eg. same source camera socket). If they don’t, remapping will be inaccurate.
- Parameters:
to – Transformation to remap to
point – Point to remap
-
dai::Point2f remapPointFrom(const ImgTransformation &from, dai::Point2f point) 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.
- Parameters:
from – Transformation to remap from
point – Point to remap
-
dai::RotatedRect remapRectTo(const ImgTransformation &to, dai::RotatedRect rect) 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.
- Parameters:
to – Transformation to remap to
rect – RotatedRect to remap
-
dai::RotatedRect remapRectFrom(const ImgTransformation &from, dai::RotatedRect rect) 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.
- Parameters:
from – Transformation to remap from
rect – RotatedRect to remap
-
dai::Point2f project3DPoint(const dai::Point3f &point) const
Project a 3D spatial point into 2D point in the current frame defined by this transformation.
Note
This function assumes that the point is in the coordinate system of the current frame.
- Parameters:
point – 3D point to project
- Returns:
Projected 2D point in the current frame
-
dai::Point2f projectPointTo(const ImgTransformation &to, dai::Point2f &point, float depth) const
Project a 2D point from the source frame defined by this transformation into a 2D point in the target frame defined by the to transformation. This function will use the depth of the point to project it into 3D space and then reproject it back to 2D in the target frame.
- Parameters:
to – Target transformation to project to
point2f – Source 2D point in the current frame
depth – (mm) Depth of the point to project
- Returns:
Projected 2D point in the target frame (to transformation)
-
dai::Point2f project3DPointTo(const ImgTransformation &to, const dai::Point3f &point) const
Project a 3D spatial point from the source coordinate system (this transformation) into a 2D point in the target frame (to transformation).
Note
This function assumes that the point3f is in the coordinate system of the current frame.
- Parameters:
to – Target transformation to project to
point3f – 3D point to project
- Returns:
Projected 2D point in the target frame (to transformation)
-
dai::Point2f project3DPointFrom(const ImgTransformation &from, const dai::Point3f &point) const
Project a 3D point from the source frame (from transformation) into a 2D point in the current frame (this transformation).
Note
This function assumes that the point3f is in the coordinate system of the source frame.
- Parameters:
from – Transformation to project from
point3f – 3D point to project
- Returns:
Projected 2D point in the current frame
-
dai::Point3f remap3DPointTo(const ImgTransformation &to, const dai::Point3f &point) const
Remap a 3D point from the source coordinate system of this transformation to the coordinate system of the target transformation (to transformation).
Note
This function assumes that the point is in the coordinate system of the current frame.
- Parameters:
to – Target transformation to remap to
point – 3D point to remap
- Returns:
Remapped 3D point in the target coordinate system
-
dai::Point3f remap3DPointFrom(const ImgTransformation &from, const dai::Point3f &point) const
Remap a 3D point to the coordinate system of this transformation from the source coordinate system of the from transformation.
Note
This function assumes that the point is in the coordinate system of the source frame.
- Parameters:
from – Transformation to remap from
point – 3D point to remap
- Returns:
Remapped 3D point in the current coordinate system
-
std::array<std::array<float, 4>, 4> getExtrinsicsTransformationMatrixTo(const ImgTransformation &to, bool useSpecTranslation = false, LengthUnit sourceUnit = LengthUnit::CENTIMETER) const
Get the extrinsic transformation matrix from the source coordinate system of this transformation to the target coordinate system of the to transformation.
Note
Both transformations must have a common toCameraSocket. Otherwise extrinsics cannot be calculated.
- Parameters:
to – Target transformation to get extrinsics to
- Returns:
4x4 homogeneous transformation matrix representing the extrinsics from this transformation to the target transformation
-
std::array<std::array<float, 3>, 3> getRotationMatrixTo(const ImgTransformation &to) const
Get the extrinsic rotation matrix from the source coordinate system of this transformation to the target coordinate system of the to transformation.
- Parameters:
to – Transformation to get extrinsics to
- Returns:
3x3 rotation matrix representing the extrinsic rotation from this transformation to the target transformation
-
std::array<float, 3> getTranslationVectorTo(const ImgTransformation &to, bool useSpecTranslation = false, LengthUnit sourceUnit = LengthUnit::CENTIMETER) const
Get the extrinsic translation vector from the source coordinate system of this transformation to the target coordinate system of the to transformation.
- Parameters:
to – Transformation to get extrinsics to
- Returns:
3x1 translation vector representing the extrinsic translation from this transformation to the target transformation
-
bool isAlignedTo(const ImgTransformation &to) const
Check if the transformations are aligned
- Parameters:
to – Transformation to compare with
-
bool isValid() const
Check if the transformations are valid. The transformations are valid if the source frame size and the current frame size are set.
-
DEPTHAI_SERIALIZE(ImgTransformation, extrinsics, transformationMatrix, transformationMatrixInv, sourceIntrinsicMatrix, sourceIntrinsicMatrixInv, distortionModel, distortionCoefficients, srcWidth, srcHeight, width, height, srcCrops)
-
ImgTransformation() = default