此页面由 AI 自动翻译。查看英文原版
最后更新

本页目录

  • 多设备设置中的外部参数
  • 用法
  • 相关示例
  • 参考
Claude CodeCodexCursor
Luxonis 智能体工具包为你常用的编程智能体加载 Luxonis 上下文与技能,更快地基于 OAK 开发应用。
安装工具包

ImgTransformations

最后更新
ImgTransformations 不是一个独立的 сообщения类型,而是附加到多个 DepthAI 消息的元数据,描述了生成此类图像的虚拟相机的所有参数。 存储的信息包括转换的完整历史记录(裁剪、调整大小、旋转、对齐、扭曲)、畸变系数、图像尺寸以及与公共参考坐标系的外部参数。 它们在所有节点中明确跟踪,而不是强制您手动从节点配置中重建它们。 节点可以使用 ImgTransformations 用于各种目的,包括:
  • 当几何体需要在 RGB、深度和其他派生流之间移动时,对齐它们。
  • 在 ImageManip、ImageAlign 或类似操作之后,重新映射矩形、点和其他图像空间几何体。
  • 读取实际生成的图像的内部参数、外部参数或任何其他相机属性,而不是假设原始传感器内部参数仍然适用。
Python
1frame = queue.get()
2transform = frame.getTransformation()
3intrinsics = transform.getSourceIntrinsicMatrix()

多设备设置中的外部参数

Extrinsics 使用两个字段标识目标参考相机:
  • toCameraSocket:外部参数转换到的相机插槽。
  • toDeviceId:目标相机插槽所属设备的设备 ID。
toDeviceId 会自动填充创建消息的设备的 ID,因为 toCameraSocket 指的是该设备上的相机。在处理跨多个设备的转换时,将 toDeviceId 与 toCameraSocket 一起使用。例如,一个设备上的 CAM_A 和另一个设备上的 CAM_A 是不同的参考相机,即使它们的插槽名称匹配。有关参考相机和转换约定的详细信息,请参阅 坐标系。

用法

以下消息具有 ImgTransformations 字段:

相关示例

参考

struct

dai::ImgTransformation

#include ImgTransformations.hpp
function
ImgTransformation()
inline function
ImgTransformation(size_t width, size_t height)
inline function
ImgTransformation(size_t srcWidth, size_t srcHeight, size_t width, size_t height)
inline function
ImgTransformation(size_t width, size_t height, std::array< std::array< float, 3 >, 3 > sourceIntrinsicMatrix)
inline function
ImgTransformation(size_t width, size_t height, std::array< std::array< float, 3 >, 3 > sourceIntrinsicMatrix, CameraModel distortionModel, std::vector< float > distortionCoefficients)
inline function
ImgTransformation(size_t width, size_t height, std::array< std::array< float, 3 >, 3 > sourceIntrinsicMatrix, CameraModel distortionModel, std::vector< float > distortionCoefficients, Extrinsics extrinsics)
function
dai::Point2f transformPoint(dai::Point2f point)
Transform a point from the source frame to the current frame.
Parameters
  • point: Point to transform
Returns
Transformed point
function
dai::RotatedRect transformRect(const dai::RotatedRect & rect)
Transform a rotated rect from the source frame to the current frame.
Parameters
  • rect: Rectangle to transform
Returns
Transformed rectangle
function
dai::Point2f invTransformPoint(dai::Point2f point)
Transform a point from the current frame to the source frame.
Parameters
  • point: Point to transform
Returns
Transformed point
function
dai::RotatedRect invTransformRect(const dai::RotatedRect & rect)
Transform a rotated rect from the current frame to the source frame.
Parameters
  • rect: Rectangle to transform
Returns
Transformed rectangle
function
std::pair< size_t, size_t > getSize()
Retrieve the size of the frame. Should be equal to the size of the corresponding ImgFrame message.
Returns
Size of the frame
function
std::pair< size_t, size_t > getSourceSize()
Retrieve the size of the source frame from which this frame was derived.
Returns
Size of the frame
function
std::array< std::array< float, 3 >, 3 > getMatrix()
Retrieve the transformation matrix from the source frame to the current frame.
Returns
Transformation matrix
function
std::array< std::array< float, 3 >, 3 > getMatrixInv()
Retrieve the inverse transformation matrix from the current frame to the source frame.
Returns
Inverse transformation matrix
function
std::array< std::array< float, 3 >, 3 > getSourceIntrinsicMatrix()
Retrieve the intrinsic matrix of the source sensor.
Returns
Intrinsic matrix
function
std::array< std::array< float, 3 >, 3 > getSourceIntrinsicMatrixInv()
Retrieve the inverse intrinsic matrix of the source sensor.
Returns
Inverse intrinsic matrix
function
CameraModel getDistortionModel()
Retrieve the distortion model of the source sensor
Returns
Distortion model
function
std::vector< float > getDistortionCoefficients()
Retrieve the distortion coefficients of the source sensor
Returns
vector of distortion coefficients
function
Extrinsics getExtrinsics()
Retrieve the pose of the source sensor or virtual camera relative to its target coordinate system. The target coordinate system is identified by Extrinsics::toDeviceId and Extrinsics::toCameraSocket.
Returns
function
bool isEqualTransformation(const ImgTransformation & other)
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 function
std::array< std::array< float, 3 >, 3 > getTransformationMatrix()
inline function
std::array< std::array< float, 3 >, 3 > getTransformationMatrixInv()
function
std::array< std::array< float, 3 >, 3 > getIntrinsicMatrix()
Retrieve the total intrinsic matrix calculated from transform * intrinsic.
Returns
total intrinsic matrix
function
std::array< std::array< float, 3 >, 3 > getIntrinsicMatrixInv()
Retrieve the inverse of the total intrinsic matrix.
Returns
inverse total intrinsic matrix
function
float getDFov(bool source)
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
function
float getHFov(bool source)
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
function
float getVFov(bool source)
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
function
std::vector< dai::RotatedRect > getSrcCrops()
function
ImgTransformation & rebaseExtrinsics(const Extrinsics & localOriginToTarget)
Re-express the source extrinsics relative to a new target coordinate system.The supplied transform must map the current local calibration origin to the new target. Only the extrinsics are changed; all image-space transformation data is preserved. The rebased extrinsics translation is stored in centimeters.
Parameters
  • localOriginToTarget: Transform from the current local calibration origin to the new target coordinate system.
Returns
This transformation.
function
bool getSrcMaskPt(size_t x, size_t y)
Returns true if the point is inside the transformed region of interest (determined by crops used).
function
bool getDstMaskPt(size_t x, size_t y)
Returns true if the point is inside the image region (not in the background region).
function
ImgTransformation & addTransformation(const std::array< std::array< float, 3 >, 3 > & matrix)
Add a new transformation.
Parameters
  • matrix: Transformation matrix
function
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
function
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
function
ImgTransformation & addFlipVertical()
Add a vertical flip transformation.
function
ImgTransformation & addFlipHorizontal()
Add a horizontal flip transformation.
function
ImgTransformation & addRotation(float angle, dai::Point2f rotationPoint)
Add a rotation transformation.
Parameters
  • angle: Angle in degrees
  • rotationPoint: Point around which to rotate
function
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
function
ImgTransformation & addSrcCrops(const std::vector< dai::RotatedRect > & crops)
function
ImgTransformation & setSize(size_t width, size_t height)
function
ImgTransformation & setSourceSize(size_t width, size_t height)
function
ImgTransformation & setExtrinsics(const Extrinsics & extrinsics)
function
ImgTransformation & setIntrinsicMatrix(const std::array< std::array< float, 3 >, 3 > & intrinsicMatrix)
function
ImgTransformation & setDistortionModel(CameraModel model)
function
ImgTransformation & setDistortionCoefficients(const std::vector< float > & coefficients)
function
dai::Point2f remapPointTo(const ImgTransformation & to, dai::Point2f point)
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.
Parameters
  • to: Transformation to remap to
  • point: Point to remap
Note
This function assumes both transformations have the same source (eg. same source camera socket). If they don't, remapping will be inaccurate.
function
dai::Point2f remapPointFrom(const ImgTransformation & from, dai::Point2f point)
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
function
dai::RotatedRect remapRectTo(const ImgTransformation & to, dai::RotatedRect rect)
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
function
dai::RotatedRect remapRectFrom(const ImgTransformation & from, const dai::RotatedRect & rect)
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
function
dai::Point2f project3DPoint(const dai::Point3f & point)
Project a 3D spatial point into 2D point in the current frame defined by this transformation.
Parameters
  • point: 3D point to project
Returns
Projected 2D point in the current frame
Note
This function assumes that the point is in the coordinate system of the current frame.
function
dai::Point2f projectPointTo(const ImgTransformation & to, dai::Point2f & point, float depth)
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)
function
dai::RotatedRect projectRectTo(const ImgTransformation & to, RotatedRect & rect, float depth)
Project a rotated rectangle from the source frame defined by this transformation into the target frame defined by the to transformation. This function assumes the rectangle is parallel to the image plane (i.e. the entire rectangle is at the same depth away). The function fits the smallest possible rectangle on to the projected corners of the original rectangle.
Parameters
  • to: Target transformation to project to
  • rect: Source rotated rectangle in the current frame
  • depth: (mm) Depth of the rectangle to project
function
dai::Point2f project3DPointTo(const ImgTransformation & to, const dai::Point3f & point)
Project a 3D spatial point from the source coordinate system (this transformation) into a 2D point in the target frame (to transformation).
Parameters
  • to: Target transformation to project to
  • point3f: 3D point to project
Returns
Projected 2D point in the target frame (to transformation)
Note
This function assumes that the point3f is in the coordinate system of the current frame.
function
dai::Point2f project3DPointFrom(const ImgTransformation & from, const dai::Point3f & point)
Project a 3D point from the source frame (from transformation) into a 2D point in the current frame (this transformation).
Parameters
  • from: Transformation to project from
  • point3f: 3D point to project
Returns
Projected 2D point in the current frame
Note
This function assumes that the point3f is in the coordinate system of the source frame.
function
dai::Point3f remap3DPointTo(const ImgTransformation & to, const dai::Point3f & point)
Remap a 3D point from the source coordinate system of this transformation to the coordinate system of the target transformation (to transformation).
Parameters
  • to: Target transformation to remap to
  • point: 3D point to remap
Returns
Remapped 3D point in the target coordinate system
Note
This function assumes that the point is in the coordinate system of the current frame.
function
dai::Point3f remap3DPointFrom(const ImgTransformation & from, const dai::Point3f & point)
Remap a 3D point to the coordinate system of this transformation from the source coordinate system of the from transformation.
Parameters
  • from: Transformation to remap from
  • point: 3D point to remap
Returns
Remapped 3D point in the current coordinate system
Note
This function assumes that the point is in the coordinate system of the source frame.
function
std::array< std::array< float, 4 >, 4 > getExtrinsicsTransformationMatrixTo(const ImgTransformation & to, bool useSpecTranslation, LengthUnit sourceUnit)
Get the extrinsic transformation matrix from the source coordinate system of this transformation to the target coordinate system of the to transformation.
Parameters
  • to: Target transformation to get extrinsics to
  • useSpecTranslation: If true, the translation vector w.r.t. the CAD design will be used instead of the translation vector obtained through calibration.
  • sourceUnit: The desired measurement unit in which to return the transformation matrix in.
Returns
4x4 homogeneous transformation matrix representing the extrinsics from this transformation to the target transformation
Note
Both transformations must have a compatible target device ID and a common target camera socket. Otherwise extrinsics cannot be calculated.
function
std::array< std::array< float, 3 >, 3 > getRotationMatrixTo(const ImgTransformation & to)
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
function
std::array< float, 3 > getTranslationVectorTo(const ImgTransformation & to, bool useSpecTranslation, LengthUnit sourceUnit)
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
function
bool isAlignedTo(const ImgTransformation & to)
Check if the transformations are aligned
Parameters
  • to: Transformation to compare with
function
bool isValid()
Check if the transformations are valid. The transformations are valid if the source frame size and the current frame size are set.
function
DEPTHAI_SERIALIZE(ImgTransformation, extrinsics, transformationMatrix, transformationMatrixInv, sourceIntrinsicMatrix, sourceIntrinsicMatrixInv, distortionModel, distortionCoefficients, srcWidth, srcHeight, width, height, srcCrops)

需要帮助?

请访问讨论论坛以获取技术支持或您可能有的任何其他问题。