Skip to content

hom_mat3d_projectHomMat3dProjectHomMat3dProjecthom_mat3d_projectT_hom_mat3d_projectπŸ”—

Short descriptionπŸ”—

hom_mat3d_projectHomMat3dProjectHomMat3dProjecthom_mat3d_projectT_hom_mat3d_project β€” Project an affine 3D transformation matrix to a 2D projective transformation matrix.

SignatureπŸ”—

hom_mat3d_project( hom_mat3d HomMat3D, point.y PrincipalPointRow, point.x PrincipalPointCol, number Focus, out hom_mat2d HomMat2D )void HomMat3dProject( const HTuple& HomMat3D, const HTuple& PrincipalPointRow, const HTuple& PrincipalPointCol, const HTuple& Focus, HTuple* HomMat2D )static void HOperatorSet.HomMat3dProject( HTuple homMat3D, HTuple principalPointRow, HTuple principalPointCol, HTuple focus, out HTuple homMat2D )def hom_mat3d_project( hom_mat_3d: Sequence[float], principal_point_row: Union[float, int], principal_point_col: Union[float, int], focus: Union[float, int] ) -> Sequence[float]

Herror T_hom_mat3d_project( const Htuple HomMat3D, const Htuple PrincipalPointRow, const Htuple PrincipalPointCol, const Htuple Focus, Htuple* HomMat2D )

HHomMat2D HHomMat3D::HomMat3dProject( const HTuple& PrincipalPointRow, const HTuple& PrincipalPointCol, const HTuple& Focus ) const

HHomMat2D HHomMat3D::HomMat3dProject( double PrincipalPointRow, double PrincipalPointCol, double Focus ) const

HHomMat2D HHomMat3D.HomMat3dProject( HTuple principalPointRow, HTuple principalPointCol, HTuple focus )

HHomMat2D HHomMat3D.HomMat3dProject( double principalPointRow, double principalPointCol, double focus )

DescriptionπŸ”—

hom_mat3d_projectHomMat3dProject calculates a homogeneous projection matrix from a homogeneous 3x4 transformation matrix describing an affine transformation in 3D. The result can be used to project a plane, in particular a plane containing an image. The projection matrix defines a projective transformation between two (two-dimensional) planes.

This can be used to create perspective distortions, which occur in a projection of a plane rotated around an axis other than the z axis. Usually, however, projective transformations are determined from point correspondences (see vector_to_proj_hom_mat2dVectorToProjHomMat2d, hom_vector_to_proj_hom_mat2dHomVectorToProjHomMat2d, and proj_match_points_ransacProjMatchPointsRansac).

Matrices for rotation, scale, and translation can be constructed using the operators hom_mat3d_identityHomMat3dIdentity, hom_mat3d_scaleHomMat3dScale, hom_mat3d_rotateHomMat3dRotate, hom_mat3d_translateHomMat3dTranslate and pose_to_hom_mat3dPoseToHomMat3d.

Note that for 3D transformations the x-axis represents the column axis while the y-axis represents the row axis (see also Calibration) while in projective_trans_imageProjectiveTransImage, the first row of HomMat2DhomMat2Dhom_mat_2d contains the transformation of the row axis and the second row contains the transformation of the column axis of the image.

The point (PrincipalPointRowprincipalPointRowprincipal_point_row, PrincipalPointColprincipalPointColprincipal_point_col) is the principal point of the projection and the point (PrincipalPointRowprincipalPointRowprincipal_point_row, PrincipalPointColprincipalPointColprincipal_point_col, 00) can thus be interpreted as the position of the camera in a virtual three-dimensional space. The direction of view is along the positive z-axis.

In this virtual space the plane containing the input image as well as the image plane are located at z=Focus, which is Focusfocusfocus pixels away form the camera. As a result, using the identity matrix as the input matrix HomMat3DhomMat3Dhom_mat_3d leads to a matrix HomMat2DhomMat2Dhom_mat_2d which also represents the identity in 2D.

Consequently, the parameter Focusfocusfocus is the β€œfocal distance” of the virtual camera used and its unit is pixels. Its value influences the degree of perspective distortions. The same input matrix at a bigger focal distance results in weaker distortions than at a low focal distance.

Let H be the affine 3D matrix with elements \(h_{ij}\), (r,c)=(PrincipalPointRow,PrincipalPointCol) and f=Focus.

Then the projective transformation matrix is calculated as follows: First, a 3x4 projection matrix is calculated as:

\[\begin{eqnarray*} Q = \left(\begin{array}{ccc} f & 0 & c \\ 0 & f & r \\ 0 & 0 & 1 \end{array} \right) \\ \cdot \\ \left(\begin{array}{cccc} 1 & 0 & 0 & -c \\ 0 & 1 & 0 & -r \\ 0 & 0 & 1 & 0 \end{array} \right) \\ \cdot \\ \left(\begin{array}{cccc} h_{11} & h_{12} & h_{13} & h_{14} \\ h_{21} & h_{22} & h_{23} & h_{24} \\ h_{31} & h_{32} & h_{33} & h_{34} \\ 0 & 0 & 0 & 1 \end{array} \right) \end{eqnarray*}\]

Since the image of a plane containing points \((x, y, f, 1)^T\) is to be calculated the last two columns of Q can be joined:

\[\begin{eqnarray*} R = \left(\begin{array}{ccc} r_{11} & r_{12} & r_{13} \\ r_{21} & r_{22} & r_{23} \\ r_{31} & r_{32} & r_{33} \end{array} \right) \\ = \\ \left(\begin{array}{ccc} q_{11} & q_{12} & f \cdot q_{13} + q_{14} \\ q_{21} & q_{22} & f \cdot r_{23} + q_{24} \\ q_{31} & q_{32} & f \cdot r_{33} + q_{34} \end{array} \right) \\ = Q \cdot \\ \left(\begin{array}{ccc} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & f \\ 0 & 0 & 1 \end{array} \right) \end{eqnarray*}\]

Finally, the columns and rows of R are swapped in a way that the first row of P contains the transformation of the row coordinates and the second row contains the transformation of the column coordinates so that P can be used directly in projective_trans_imageProjectiveTransImage:

\[\begin{eqnarray*} P = \left(\begin{array}{ccc} 0 & 1 & 0 \\ 1 & 0 & 0 \\ 0 & 0 & 1 \end{array} \right) \\ \cdot R \cdot \\ \left(\begin{array}{ccc} 0 & 1 & 0 \\ 1 & 0 & 0 \\ 0 & 0 & 1 \end{array} \right) \end{eqnarray*}\]

The overall transformation can be written as:

\[\begin{eqnarray*} P = \left(\begin{array}{ccc} 0 & 1 & 0 \\ 1 & 0 & 0 \\ 0 & 0 & 1 \end{array} \right) \\ \cdot \\ \left(\begin{array}{ccc} f & 0 & c \\ 0 & f & r \\ 0 & 0 & 1 \end{array} \right) \\ \cdot \\ \left(\begin{array}{cccc} 1 & 0 & 0 & -c \\ 0 & 1 & 0 & -r \\ 0 & 0 & 1 & 0 \end{array} \right) \\ \cdot H \cdot \\ \left(\begin{array}{ccc} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & f \\ 0 & 0 & 1 \end{array} \right) \cdot \\ \left(\begin{array}{ccc} 0 & 1 & 0 \\ 1 & 0 & 0 \\ 0 & 0 & 1 \end{array} \right) \end{eqnarray*}\]

Execution informationπŸ”—

Execution information
  • Multithreading type: reentrant (runs in parallel with non-exclusive operators).

  • Multithreading scope: global (may be called from any thread).

  • Processed without parallelization.

ParametersπŸ”—

HomMat3DhomMat3Dhom_mat_3d (input_control) hom_mat3d β†’ (real)HTuple (double)HHomMat3D, HTuple (double)Sequence[float]Htuple (double)

3Γ—4 3D transformation matrix.

PrincipalPointRowprincipalPointRowprincipal_point_row (input_control) point.y β†’ (real / integer)HTuple (double / Hlong)HTuple (double / int / long)Union[float, int]Htuple (double / Hlong)

Row coordinate of the principal point.

Default: 256256
Suggested values: 16, 32, 64, 128, 240, 256, 51216, 32, 64, 128, 240, 256, 512

PrincipalPointColprincipalPointColprincipal_point_col (input_control) point.x β†’ (real / integer)HTuple (double / Hlong)HTuple (double / int / long)Union[float, int]Htuple (double / Hlong)

Column coordinate of the principal point.

Default: 256256
Suggested values: 16, 32, 64, 128, 256, 320, 51216, 32, 64, 128, 256, 320, 512

Focusfocusfocus (input_control) number β†’ (real / integer)HTuple (double / Hlong)HTuple (double / int / long)Union[float, int]Htuple (double / Hlong)

Focal length in pixels.

Default: 256256
Suggested values: 1, 2, 5, 256, 327681, 2, 5, 256, 32768

HomMat2DhomMat2Dhom_mat_2d (output_control) hom_mat2d β†’ (real)HTuple (double)HHomMat2D, HTuple (double)Sequence[float]Htuple (double)

Homogeneous projective transformation matrix.

Combinations with other operatorsπŸ”—

Combinations

Possible predecessors

hom_mat3d_identityHomMat3dIdentity, hom_mat3d_rotateHomMat3dRotate, hom_mat3d_translateHomMat3dTranslate, hom_mat3d_scaleHomMat3dScale

Possible successors

projective_trans_imageProjectiveTransImage, projective_trans_point_2dProjectiveTransPoint2d, projective_trans_regionProjectiveTransRegion, projective_trans_contour_xldProjectiveTransContourXld, hom_mat2d_invertHomMat2dInvert

ModuleπŸ”—

Foundation