HomogeneousMatrix

class HomogeneousMatrix(*args, **kwargs)

Bases: ArrayDouble2D

Implementation of an homogeneous matrix and operations on such kind of matrices.

The class provides a data structure for the homogeneous matrices as well as a set of operations on these matrices.

The vpHomogeneousMatrix class is derived from vpArray2D<double> .

An homogeneous matrix is 4x4 matrix defines as

\[\begin{split}^a{\bf M}_b = \left(\begin{array}{cc} ^a{\bf R}_b & ^a{\bf t}_b \\{\bf 0}_{1\times 3} & 1 \end{array} \right) \end{split}\]

that defines the position of frame b in frame a

\(^a{\bf R}_b\) is a rotation matrix and \(^a{\bf t}_b\) is a translation vector.

There are different ways to initialize an homogeneous matrix. You can set each element of the matrix like:

#include <visp3/core/vpHomogeneousMatrix.h>

int main()
{
  vpHomogeneousMatrix M;
  M[0][0] =  0; M[0][1] =  0; M[0][2] = -1; M[0][3] = 0.1;
  M[1][0] =  0; M[1][1] = -1; M[1][2] =  0; M[1][3] = 0.2;
  M[2][0] = -1; M[2][1] =  0; M[2][2] =  0; M[2][3] = 0.3;

  std::cout << "M:" << std::endl;
  for (unsigned int i = 0; i < M.getRows(); ++i) {
    for (unsigned int j = 0; j < M.getCols(); ++j) {
      std::cout << M[i][j] << " ";
    }
    std::cout << std::endl;
  }
}

It produces the following printings:

M:
0 0 -1 0.1
0 -1 0 0.2
-1 0 0 0.3
0 0 0 1

You can also use vpRotationMatrix::operator<< and vpTranslationVector::operator<< like:

#include <visp3/core/vpHomogeneousMatrix.h>

int main()
{
  vpTranslationVector t;
  vpRotationMatrix R;
  R << 0, 0, -1,
      0, -1, 0,
      -1, 0, 0;
  t << 0.1, 0.2, 0.3;
  vpHomogeneousMatrix M(t, R);
  std::cout << "M:\n" << M << std::endl;
}

If ViSP is build with c++11 enabled, you can do the same using:

#include <visp3/core/vpHomogeneousMatrix.h>

int main()
{
  {
    vpHomogeneousMatrix M( vpTranslationVector(0.1, 0.2, 0.3), vpRotationMatrix( {0, 0, -1, 0, -1, 0, -1, 0, 0} ) );
    std::cout << "M:\n" << M << std::endl;
  }
  {
    vpHomogeneousMatrix M { 0,  0, -1, 0.1,
                            0, -1,  0, 0.2,
                          -1,  0,  0, 0.3 };
    std::cout << "M:\n" << M << std::endl;
  }
}

JSON serialization

Since ViSP 3.6.0, if ViSP is build with soft_tool_json 3rd-party we introduce JSON serialization capabilities for vpHomogeneousMatrix . The following sample code shows how to save a homogeneous matrix in a file named homo-mat.json and reload the values from this JSON file.

#include <visp3/core/vpHomogeneousMatrix.h>

int main()
{
#if defined(VISP_HAVE_NLOHMANN_JSON)
  std::string filename = "homo-mat.json";
  {
    vpHomogeneousMatrix M(vpTranslationVector(0.1, 0.2, 0.3), vpRotationMatrix({ 0, 0, -1, 0, -1, 0, -1, 0, 0 }));
    std::ofstream file(filename);
    const nlohmann::json j = M;
    file << j;
    file.close();
  }
  {
    std::ifstream file(filename);
    const nlohmann::json j = nlohmann::json::parse(file);
    vpHomogeneousMatrix M;
    M = j;
    file.close();
    std::cout << "Read homogeneous matrix from " << filename << ":\n" << M << std::endl;
  }
#endif
}

If you build and execute the sample code, it will produce the following output:

Read homogeneous matrix from homo-mat.json:
0  0  -1  0.1
0  -1  0  0.2
-1  0  0  0.3
0  0  0  1

The content of the homo-mat.json file is the following:

$ cat homo-mat.json
{"cols":4,"data":[0.0,0.0,-1.0,0.1,0.0,-1.0,0.0,0.2,-1.0,0.0,0.0,0.3,0.0,0.0,0.0,1.0],"rows":4,"type":"vpHomogeneousMatrix"}

Overloaded function.

  1. __init__(self: visp._visp.core.HomogeneousMatrix) -> None

Default constructor that initialize an homogeneous matrix as identity.

  1. __init__(self: visp._visp.core.HomogeneousMatrix, M: visp._visp.core.HomogeneousMatrix) -> None

Copy constructor that initialize an homogeneous matrix from another homogeneous matrix.

  1. __init__(self: visp._visp.core.HomogeneousMatrix, t: visp._visp.core.TranslationVector, R: visp._visp.core.RotationMatrix) -> None

Construct an homogeneous matrix from a translation vector and a rotation matrix.

  1. __init__(self: visp._visp.core.HomogeneousMatrix, t: visp._visp.core.TranslationVector, tu: visp._visp.core.ThetaUVector) -> None

Construct an homogeneous matrix from a translation vector and \(\theta {\bf u}\) rotation vector.

  1. __init__(self: visp._visp.core.HomogeneousMatrix, t: visp._visp.core.TranslationVector, q: visp._visp.core.QuaternionVector) -> None

Construct an homogeneous matrix from a translation vector and quaternion rotation vector.

  1. __init__(self: visp._visp.core.HomogeneousMatrix, p: visp._visp.core.PoseVector) -> None

Construct an homogeneous matrix from a pose vector.

  1. __init__(self: visp._visp.core.HomogeneousMatrix, v: list[float]) -> None

Construct an homogeneous matrix from a vector of float.The following example shows how to use this function:

#include <visp3/core/vpHomogeneousMatrix.h>

int main()
{
  std::vector<float> v(12, 0);
  v[1]  = -1.; // ry=-90
  v[4]  =  1.; // rx=90
  v[10] = -1.; // rz=-90
  v[3]  = 0.3; // tx
  v[7]  = 0.4; // ty
  v[11] = 0.5; // tz

  std::cout << "v: ";
  for(unsigned int i=0; i<v.size(); ++i)
    std::cout << v[i] << " ";
  std::cout << std::endl;

  vpHomogeneousMatrix M(v);
  std::cout << "M:\n" << M << std::endl;
}

It produces the following printings:

v: 0 -1 0 0.3 1 0 0 0.4 0 0 -1 0.5
M:
0  -1  0  0.3000000119
1  0  0  0.400000006
0  0  -1  0.5
0  0  0  1
Parameters:
v

Vector of 12 or 16 values corresponding to the values of the homogeneous matrix.

  1. __init__(self: visp._visp.core.HomogeneousMatrix, v: list[float]) -> None

Construct an homogeneous matrix from a vector of double.The following example shows how to use this function:

#include <visp3/core/vpHomogeneousMatrix.h>

int main()
{
  std::vector<double> v(12, 0);
  v[1]  = -1.; // ry=-90
  v[4]  =  1.; // rx=90
  v[10] = -1.; // rz=-90
  v[3]  = 0.3; // tx
  v[7]  = 0.4; // ty
  v[11] = 0.5; // tz

  std::cout << "v: ";
  for(unsigned int i=0; i<v.size(); ++i)
    std::cout << v[i] << " ";
  std::cout << std::endl;

  vpHomogeneousMatrix M(v);
  std::cout << "M:\n" << M << std::endl;
}

It produces the following printings:

v: 0 -1 0 0.3 1 0 0 0.4 0 0 -1 0.5
M:
0  -1  0  0.3
1  0  0  0.4
0  0  -1  0.5
0  0  0  1
Parameters:
v

Vector of 12 or 16 values corresponding to the values of the homogeneous matrix.

  1. __init__(self: visp._visp.core.HomogeneousMatrix, tx: float, ty: float, tz: float, tux: float, tuy: float, tuz: float) -> None

Construct an homogeneous matrix from a translation vector \({\bf t}=(t_x, t_y, t_z)^T\) and a \(\theta {\bf u}=(\theta u_x, \theta u_y, \theta u_z)^T\) rotation vector.

  1. __init__(self: visp._visp.core.HomogeneousMatrix, list: std::initializer_list<double>) -> None

Construct an homogeneous matrix from a list of 12 or 16 double values.

Parameters:
list

List of double. The following code shows how to use this constructor to initialize an homogeneous matrix:

#include <visp3/core/vpHomogeneousMatrix.h>

int main()
{
  vpHomogeneousMatrix M {
    0, 0, 1, 0.1,
    0, 1, 0, 0.2,
    1, 0, 0, 0.3 };
  std::cout << "M:\n" << M << std::endl;
  vpHomogeneousMatrix N {
    0, 0, 1, 0.1,
    0, 1, 0, 0.2,
    1, 0, 0, 0.3,
    0, 0, 0, 1 };
  std::cout << "N:\n" << N << std::endl;
}

It produces the following output:

M:
0  0  1  0.1
0  1  0  0.2
1  0  0  0.3
0  0  0  1
N:
0  0  1  0.1
0  1  0  0.2
1  0  0  0.3
0  0  0  1

  1. __init__(self: visp._visp.core.HomogeneousMatrix, np_array: numpy.ndarray[numpy.float64]) -> None

Construct a homogeneous matrix by copying a 2D numpy array. This numpy array should be of dimensions \(4 \times 4\) and be a valid homogeneous matrix. If it is not a homogeneous matrix, an exception will be raised.

Parameters:
np_array

The numpy 1D array to copy.

Methods

__init__

Overloaded function.

buildFrom

Overloaded function.

compute3d3dTransformation

param p:

First point cloud.

convert

Converts an homogeneous matrix to a vector of 12 doubles.

extract

Overloaded function.

eye

Set transformation to identity.

getCol

The following example shows how to use this function:

getRotationMatrix

Return the rotation matrix from the homogeneous transformation matrix.

getThetaUVector

Return the \(\theta {\bf u}\) vector that corresponds to the rotation part of the homogeneous transformation.

getTranslationVector

Return the translation vector from the homogeneous transformation matrix.

insert

Overloaded function.

inverse

Overloaded function.

isAnHomogeneousMatrix

Test if the 3x3 rotational part of the homogeneous matrix is a valid rotation matrix and the last row is equal to [0, 0, 0, 1].

isValid

return:

true when no NaN found, false otherwise.

load

Overloaded function.

mean

Compute the Euclidean mean of the homogeneous matrices.

numpy

Numpy view of the underlying array data.

orthogonalizeRotation

Perform orthogonalization of the rotation part of the homogeneous transformation.

print

Print the matrix as a pose vector \(({\bf t}^T \theta {\bf u}^T)\) .

resize

Overloaded function.

save

Overloaded function.

Inherited Methods

getCols

Return the number of columns of the 2D array.

insertStatic

Insert array B in array A at the given position.

reshape

getRows

Return the number of rows of the 2D array.

size

Return the number of elements of the 2D array.

getMinValue

Return the array min value.

getMaxValue

Return the array max value.

hadamard

param m:

Second matrix;

saveYAML

Save an array in a YAML-formatted file.

conv2

Overloaded function.

t

Compute the transpose of the array.

Operators

__doc__

__getitem__

Overloaded function.

__imul__

Operator that allow to multiply an homogeneous matrix by an other one.

__init__

Overloaded function.

__module__

__mul__

Overloaded function.

Attributes

__annotations__

__hash__

__eq__(*args, **kwargs)

Overloaded function.

  1. __eq__(self: visp._visp.core.ArrayDouble2D, A: visp._visp.core.ArrayDouble2D) -> bool

Equal to comparison operator of a 2D array.

  1. __eq__(self: visp._visp.core.ArrayDouble2D, A: visp._visp.core.ArrayDouble2D) -> bool

Equal to comparison operator of a 2D array.

  1. __eq__(self: visp._visp.core.ArrayDouble2D, A: visp._visp.core.ArrayDouble2D) -> bool

Equal to comparison operator of a 2D array.

__getitem__(*args, **kwargs)

Overloaded function.

  1. __getitem__(self: visp._visp.core.HomogeneousMatrix, arg0: tuple[int, int]) -> float

  2. __getitem__(self: visp._visp.core.HomogeneousMatrix, arg0: int) -> numpy.ndarray[numpy.float64]

  3. __getitem__(self: visp._visp.core.HomogeneousMatrix, arg0: slice) -> numpy.ndarray[numpy.float64]

  4. __getitem__(self: visp._visp.core.HomogeneousMatrix, arg0: tuple) -> numpy.ndarray[numpy.float64]

__imul__(self, M: visp._visp.core.HomogeneousMatrix) visp._visp.core.HomogeneousMatrix

Operator that allow to multiply an homogeneous matrix by an other one.

#include <visp3/core/vpHomogeneousMatrix.h>

int main()
{
  vpHomogeneousMatrix M1, M2;
  // Initialize M1 and M2...

  // Compute M1 = M1 * M2
  M1 *= M2;
}
__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: visp._visp.core.HomogeneousMatrix) -> None

Default constructor that initialize an homogeneous matrix as identity.

  1. __init__(self: visp._visp.core.HomogeneousMatrix, M: visp._visp.core.HomogeneousMatrix) -> None

Copy constructor that initialize an homogeneous matrix from another homogeneous matrix.

  1. __init__(self: visp._visp.core.HomogeneousMatrix, t: visp._visp.core.TranslationVector, R: visp._visp.core.RotationMatrix) -> None

Construct an homogeneous matrix from a translation vector and a rotation matrix.

  1. __init__(self: visp._visp.core.HomogeneousMatrix, t: visp._visp.core.TranslationVector, tu: visp._visp.core.ThetaUVector) -> None

Construct an homogeneous matrix from a translation vector and \(\theta {\bf u}\) rotation vector.

  1. __init__(self: visp._visp.core.HomogeneousMatrix, t: visp._visp.core.TranslationVector, q: visp._visp.core.QuaternionVector) -> None

Construct an homogeneous matrix from a translation vector and quaternion rotation vector.

  1. __init__(self: visp._visp.core.HomogeneousMatrix, p: visp._visp.core.PoseVector) -> None

Construct an homogeneous matrix from a pose vector.

  1. __init__(self: visp._visp.core.HomogeneousMatrix, v: list[float]) -> None

Construct an homogeneous matrix from a vector of float.The following example shows how to use this function:

#include <visp3/core/vpHomogeneousMatrix.h>

int main()
{
  std::vector<float> v(12, 0);
  v[1]  = -1.; // ry=-90
  v[4]  =  1.; // rx=90
  v[10] = -1.; // rz=-90
  v[3]  = 0.3; // tx
  v[7]  = 0.4; // ty
  v[11] = 0.5; // tz

  std::cout << "v: ";
  for(unsigned int i=0; i<v.size(); ++i)
    std::cout << v[i] << " ";
  std::cout << std::endl;

  vpHomogeneousMatrix M(v);
  std::cout << "M:\n" << M << std::endl;
}

It produces the following printings:

v: 0 -1 0 0.3 1 0 0 0.4 0 0 -1 0.5
M:
0  -1  0  0.3000000119
1  0  0  0.400000006
0  0  -1  0.5
0  0  0  1
Parameters:
v

Vector of 12 or 16 values corresponding to the values of the homogeneous matrix.

  1. __init__(self: visp._visp.core.HomogeneousMatrix, v: list[float]) -> None

Construct an homogeneous matrix from a vector of double.The following example shows how to use this function:

#include <visp3/core/vpHomogeneousMatrix.h>

int main()
{
  std::vector<double> v(12, 0);
  v[1]  = -1.; // ry=-90
  v[4]  =  1.; // rx=90
  v[10] = -1.; // rz=-90
  v[3]  = 0.3; // tx
  v[7]  = 0.4; // ty
  v[11] = 0.5; // tz

  std::cout << "v: ";
  for(unsigned int i=0; i<v.size(); ++i)
    std::cout << v[i] << " ";
  std::cout << std::endl;

  vpHomogeneousMatrix M(v);
  std::cout << "M:\n" << M << std::endl;
}

It produces the following printings:

v: 0 -1 0 0.3 1 0 0 0.4 0 0 -1 0.5
M:
0  -1  0  0.3
1  0  0  0.4
0  0  -1  0.5
0  0  0  1
Parameters:
v

Vector of 12 or 16 values corresponding to the values of the homogeneous matrix.

  1. __init__(self: visp._visp.core.HomogeneousMatrix, tx: float, ty: float, tz: float, tux: float, tuy: float, tuz: float) -> None

Construct an homogeneous matrix from a translation vector \({\bf t}=(t_x, t_y, t_z)^T\) and a \(\theta {\bf u}=(\theta u_x, \theta u_y, \theta u_z)^T\) rotation vector.

  1. __init__(self: visp._visp.core.HomogeneousMatrix, list: std::initializer_list<double>) -> None

Construct an homogeneous matrix from a list of 12 or 16 double values.

Parameters:
list

List of double. The following code shows how to use this constructor to initialize an homogeneous matrix:

#include <visp3/core/vpHomogeneousMatrix.h>

int main()
{
  vpHomogeneousMatrix M {
    0, 0, 1, 0.1,
    0, 1, 0, 0.2,
    1, 0, 0, 0.3 };
  std::cout << "M:\n" << M << std::endl;
  vpHomogeneousMatrix N {
    0, 0, 1, 0.1,
    0, 1, 0, 0.2,
    1, 0, 0, 0.3,
    0, 0, 0, 1 };
  std::cout << "N:\n" << N << std::endl;
}

It produces the following output:

M:
0  0  1  0.1
0  1  0  0.2
1  0  0  0.3
0  0  0  1
N:
0  0  1  0.1
0  1  0  0.2
1  0  0  0.3
0  0  0  1

  1. __init__(self: visp._visp.core.HomogeneousMatrix, np_array: numpy.ndarray[numpy.float64]) -> None

Construct a homogeneous matrix by copying a 2D numpy array. This numpy array should be of dimensions \(4 \times 4\) and be a valid homogeneous matrix. If it is not a homogeneous matrix, an exception will be raised.

Parameters:
np_array

The numpy 1D array to copy.

__mul__(*args, **kwargs)

Overloaded function.

  1. __mul__(self: visp._visp.core.HomogeneousMatrix, M: visp._visp.core.HomogeneousMatrix) -> visp._visp.core.HomogeneousMatrix

Operator that allow to multiply an homogeneous matrix by an other one.

#include <visp3/core/vpHomogeneousMatrix.h>

int main()
{
  vpHomogeneousMatrix aMb, bMc;
  // Initialize aMb and bMc...

  // Compute aMc * bMc
  vpHomogeneousMatrix aMc = aMb * bMc;
}
  1. __mul__(self: visp._visp.core.HomogeneousMatrix, v: visp._visp.core.ColVector) -> visp._visp.core.ColVector

Operator that allow to multiply an homogeneous matrix by a 4-dimension column vector.

  1. __mul__(self: visp._visp.core.HomogeneousMatrix, t: visp._visp.core.TranslationVector) -> visp._visp.core.TranslationVector

Since a translation vector could be seen as the origin point of a frame, this function computes the new coordinates of a translation vector after applying an homogeneous transformation.

Parameters:
t

Translation vector seen as the 3D coordinates of a point.

Returns:

A translation vector that contains the new 3D coordinates after applying the homogeneous transformation.

  1. __mul__(self: visp._visp.core.HomogeneousMatrix, R: visp._visp.core.RotationMatrix) -> visp._visp.core.HomogeneousMatrix

Operator that allows to multiply a rotation matrix by a rotation matrix.

The following snippet shows how to use this method:

vpHomogeneousMatrix c1_M_c2;
vpRotationMatrix c2_R_c3;
vpHomogeneousMatrix c1_M_c3 = c1_M_c2 * c2_R_c3;
Parameters:
R

Rotation matrix.

Returns:

The product between the homogeneous matrix and the rotation matrix R .

  1. __mul__(self: visp._visp.core.HomogeneousMatrix, bP: visp._visp.core.Point) -> visp._visp.core.Point

From the coordinates of the point in camera frame b and the transformation between camera frame a and camera frame b computes the coordinates of the point in camera frame a.

Parameters:
bP

3D coordinates of the point in camera frame bP.

Returns:

A point with 3D coordinates in the camera frame a. The coordinates in the world or object frame are set to the same coordinates than the one in the camera frame.

__ne__(*args, **kwargs)

Overloaded function.

  1. __ne__(self: visp._visp.core.ArrayDouble2D, A: visp._visp.core.ArrayDouble2D) -> bool

Not equal to comparison operator of a 2D array.

  1. __ne__(self: visp._visp.core.ArrayDouble2D, A: visp._visp.core.ArrayDouble2D) -> bool

Not equal to comparison operator of a 2D array.

  1. __ne__(self: visp._visp.core.ArrayDouble2D, A: visp._visp.core.ArrayDouble2D) -> bool

Not equal to comparison operator of a 2D array.

buildFrom(*args, **kwargs)

Overloaded function.

  1. buildFrom(self: visp._visp.core.HomogeneousMatrix, t: visp._visp.core.TranslationVector, R: visp._visp.core.RotationMatrix) -> None

Build an homogeneous matrix from a translation vector and a rotation matrix.

  1. buildFrom(self: visp._visp.core.HomogeneousMatrix, t: visp._visp.core.TranslationVector, tu: visp._visp.core.ThetaUVector) -> None

Build an homogeneous matrix from a translation vector and a \(\theta {\bf u}\) rotation vector.

  1. buildFrom(self: visp._visp.core.HomogeneousMatrix, t: visp._visp.core.TranslationVector, q: visp._visp.core.QuaternionVector) -> None

Build an homogeneous matrix from a translation vector and a quaternion rotation vector.

  1. buildFrom(self: visp._visp.core.HomogeneousMatrix, p: visp._visp.core.PoseVector) -> None

Build an homogeneous matrix from a pose vector.

  1. buildFrom(self: visp._visp.core.HomogeneousMatrix, v: list[float]) -> None

Build an homogeneous matrix from a vector of float.The following example shows how to use this function:

#include <visp3/core/vpHomogeneousMatrix.h>

int main()
{
  std::vector<float> v(12, 0);
  v[1]  = -1.; // ry=-90
  v[4]  =  1.; // rx=90
  v[10] = -1.; // rz=-90
  v[3]  = 0.3; // tx
  v[7]  = 0.4; // ty
  v[11] = 0.5; // tz

  std::cout << "v: ";
  for(unsigned int i=0; i<v.size(); ++i)
    std::cout << v[i] << " ";
  std::cout << std::endl;

  vpHomogeneousMatrix M;
  M.buildFrom(v);
  std::cout << "M:\n" << M << std::endl;
}

It produces the following printings:

v: 0 -1 0 0.3 1 0 0 0.4 0 0 -1 0.5
M:
0  -1  0  0.3000000119
1  0  0  0.400000006
0  0  -1  0.5
0  0  0  1
Parameters:
v

Vector of 12 or 16 values corresponding to the values of the homogeneous matrix.

  1. buildFrom(self: visp._visp.core.HomogeneousMatrix, v: list[float]) -> None

Build an homogeneous matrix from a vector of double.The following example shows how to use this function:

#include <visp3/core/vpHomogeneousMatrix.h>

int main()
{
  std::vector<double> v(12, 0);
  v[1]  = -1.; // ry=-90
  v[4]  =  1.; // rx=90
  v[10] = -1.; // rz=-90
  v[3]  = 0.3; // tx
  v[7]  = 0.4; // ty
  v[11] = 0.5; // tz

  std::cout << "v: ";
  for(unsigned int i=0; i<v.size(); ++i)
    std::cout << v[i] << " ";
  std::cout << std::endl;

  vpHomogeneousMatrix M;
  M.buildFrom(v);
  std::cout << "M:\n" << M << std::endl;
}

It produces the following printings:

v: 0 -1 0 0.3 1 0 0 0.4 0 0 -1 0.5
M:
0  -1  0  0.3
1  0  0  0.4
0  0  -1  0.5
0  0  0  1
Parameters:
v

Vector of 12 or 16 values corresponding to the values of the homogeneous matrix.

  1. buildFrom(self: visp._visp.core.HomogeneousMatrix, tx: float, ty: float, tz: float, tux: float, tuy: float, tuz: float) -> None

Build an homogeneous matrix from a translation vector \({\bf t}=(t_x, t_y, t_z)^T\) and a \(\theta {\bf u}=(\theta u_x, \theta u_y, \theta u_z)^T\) rotation vector.

static compute3d3dTransformation(p: list[visp._visp.core.Point], q: list[visp._visp.core.Point]) visp._visp.core.HomogeneousMatrix
Parameters:
p: list[visp._visp.core.Point]

First point cloud.

q: list[visp._visp.core.Point]

Second point cloud.

Returns:

The homogeneous transformation \({^p}{\bf M}_q\) .

static conv2(*args, **kwargs)

Overloaded function.

  1. conv2(M: visp._visp.core.ArrayDouble2D, kernel: visp._visp.core.ArrayDouble2D, mode: str) -> visp._visp.core.ArrayDouble2D

Perform a 2D convolution similar to Matlab conv2 function: \(M \star kernel\) .

<unparsed image <doxmlparser.compound.docImageType object at 0x7ff6a36292a0>>

Note

This is a very basic implementation that does not use FFT.

Parameters:
M

First matrix.

kernel

Second matrix.

mode

Convolution mode: “full” (default), “same”, “valid”.

  1. conv2(M: visp._visp.core.ArrayDouble2D, kernel: visp._visp.core.ArrayDouble2D, res: visp._visp.core.ArrayDouble2D, mode: str) -> None

Perform a 2D convolution similar to Matlab conv2 function: \(M \star kernel\) .

<unparsed image <doxmlparser.compound.docImageType object at 0x7ff6a362aec0>>

Note

This is a very basic implementation that does not use FFT.

Parameters:
M

First array.

kernel

Second array.

res

Result.

mode

Convolution mode: “full” (default), “same”, “valid”.

convert(self) list[float]

Converts an homogeneous matrix to a vector of 12 doubles.

Returns:

A tuple containing:

  • M: Converted matrix.

extract(*args, **kwargs)

Overloaded function.

  1. extract(self: visp._visp.core.HomogeneousMatrix, R: visp._visp.core.RotationMatrix) -> None

Extract the rotational matrix from the homogeneous matrix.

Parameters:
R

rotational component as a rotation matrix.

  1. extract(self: visp._visp.core.HomogeneousMatrix, tu: visp._visp.core.ThetaUVector) -> None

Extract the rotation as a \(\theta \bf u\) vector.

  1. extract(self: visp._visp.core.HomogeneousMatrix, t: visp._visp.core.TranslationVector) -> None

Extract the translation vector from the homogeneous matrix.

  1. extract(self: visp._visp.core.HomogeneousMatrix, q: visp._visp.core.QuaternionVector) -> None

Extract the rotation as a quaternion.

eye(self) None

Set transformation to identity.

getCol(self, j: int) visp._visp.core.ColVector

The following example shows how to use this function:

#include <visp3/core/vpColVector.h>
#include <visp3/core/vpHomogeneousMatrix.h>

int main()
{
  vpHomogeneousMatrix M;

  vpColVector t = M.getCol(3);
  std::cout << "Last column: \n" << t << std::endl;
}

It produces the following output:

Last column:
0
0
1
0
Parameters:
j: int

Index of the column to extract. If j=0, the first column is extracted.

Returns:

The extracted column vector.

getCols(self) int

Return the number of columns of the 2D array.

Note

See getRows() , size()

getMaxValue(self) float

Return the array max value.

getMinValue(self) float

Return the array min value.

getRotationMatrix(self) visp._visp.core.RotationMatrix

Return the rotation matrix from the homogeneous transformation matrix.

getRows(self) int

Return the number of rows of the 2D array.

Note

See getCols() , size()

getThetaUVector(self) visp._visp.core.ThetaUVector

Return the \(\theta {\bf u}\) vector that corresponds to the rotation part of the homogeneous transformation.

getTranslationVector(self) visp._visp.core.TranslationVector

Return the translation vector from the homogeneous transformation matrix.

hadamard(self, m: visp._visp.core.ArrayDouble2D) visp._visp.core.ArrayDouble2D
Parameters:
m: visp._visp.core.ArrayDouble2D

Second matrix;

Returns:

m1.hadamard(m2) The Hadamard product : \(m1 \circ m2 = (m1 \circ m2)_{i,j} = (m1)_{i,j} (m2)_{i,j}\)

insert(*args, **kwargs)

Overloaded function.

  1. insert(self: visp._visp.core.HomogeneousMatrix, R: visp._visp.core.RotationMatrix) -> None

Insert the rotational component of the homogeneous matrix.

  1. insert(self: visp._visp.core.HomogeneousMatrix, tu: visp._visp.core.ThetaUVector) -> None

Insert the rotational component of the homogeneous matrix from a \(theta {\bf u}\) rotation vector.

  1. insert(self: visp._visp.core.HomogeneousMatrix, t: visp._visp.core.TranslationVector) -> None

Insert the translational component in a homogeneous matrix.

  1. insert(self: visp._visp.core.HomogeneousMatrix, t: visp._visp.core.QuaternionVector) -> None

Insert the rotational component of the homogeneous matrix from a quaternion rotation vector.

  1. insert(self: visp._visp.core.ArrayDouble2D, A: visp._visp.core.ArrayDouble2D, r: int, c: int) -> None

Insert array A at the given position in the current array.

Warning

Throw vpException::dimensionError if the dimensions of the matrices do not allow the operation.

Parameters:
A

The array to insert.

r

The index of the row to begin to insert data.

c

The index of the column to begin to insert data.

  1. insert(self: visp._visp.core.ArrayDouble2D, A: visp._visp.core.ArrayDouble2D, B: visp._visp.core.ArrayDouble2D, r: int, c: int) -> visp._visp.core.ArrayDouble2D

Insert array B in array A at the given position.

Warning

Throw exception if the sizes of the arrays do not allow the insertion.

Parameters:
A

Main array.

B

Array to insert.

r

Index of the row where to add the array.

c

Index of the column where to add the array.

Returns:

Array with B insert in A.

static insertStatic(A: visp._visp.core.ArrayDouble2D, B: visp._visp.core.ArrayDouble2D, C: visp._visp.core.ArrayDouble2D, r: int, c: int) None

Insert array B in array A at the given position.

Warning

Throw exception if the sizes of the arrays do not allow the insertion.

Parameters:
A: visp._visp.core.ArrayDouble2D

Main array.

B: visp._visp.core.ArrayDouble2D

Array to insert.

C: visp._visp.core.ArrayDouble2D

Result array.

r: int

Index of the row where to insert array B.

c: int

Index of the column where to insert array B.

inverse(*args, **kwargs)

Overloaded function.

  1. inverse(self: visp._visp.core.HomogeneousMatrix) -> visp._visp.core.HomogeneousMatrix

Invert the homogeneous matrix

Returns:

\(\left[\begin{array}{cc} {\bf R} & {\bf t} \\{\bf 0}_{1\times 3} & 1 \end{array} \right]^{-1} = \left[\begin{array}{cc} {\bf R}^T & -{\bf R}^T {\bf t} \\{\bf 0}_{1\times 3} & 1 \end{array} \right]\)

  1. inverse(self: visp._visp.core.HomogeneousMatrix, Mi: visp._visp.core.HomogeneousMatrix) -> None

Invert the homogeneous matrix.

isAnHomogeneousMatrix(self, threshold: float = 1e-6) bool

Test if the 3x3 rotational part of the homogeneous matrix is a valid rotation matrix and the last row is equal to [0, 0, 0, 1].

Returns:

true if the matrix is a homogeneous matrix, false otherwise.

isValid(self) bool
Returns:

true when no NaN found, false otherwise.

load(*args, **kwargs)

Overloaded function.

  1. load(self: visp._visp.core.HomogeneousMatrix, f: std::basic_ifstream<char, std::char_traits<char> >) -> None

Read an homogeneous matrix from an input file stream. The homogeneous matrix is considered as a 4 by 4 matrix.

The code below shows how to get an homogeneous matrix from a file.

vpHomogeneousMatrix M;

std::ifstream f("homogeneous.dat");
M.load(f);

Note

See load(const std::string &) , save(std::ifstream &)

Parameters:
f

Input file stream.

  1. load(self: visp._visp.core.HomogeneousMatrix, filename: str) -> None

Read an homogeneous matrix from an input file. The homogeneous matrix is considered as a 4 by 4 matrix.

The code below shows how to get an homogeneous matrix from a file.

vpHomogeneousMatrix M;

M.load("homogeneous.dat");

Note

See load(std::ifstream &) , save(const std::string &)

Parameters:
filename

Input file name.

static mean(vec_M: list[visp._visp.core.HomogeneousMatrix]) visp._visp.core.HomogeneousMatrix

Compute the Euclidean mean of the homogeneous matrices. The Euclidean mean of the rotation matrices is computed following Moakher’s method (SIAM 2002).

Note

See vpTranslationVector::mean() , vpRotationMatrix::mean()

Parameters:
vec_M: list[visp._visp.core.HomogeneousMatrix]

Set of homogeneous matrices.

Returns:

The Euclidean mean of the homogeneous matrices.

numpy(self) numpy.ndarray[numpy.float64]

Numpy view of the underlying array data. This numpy view cannot be modified. If you try to modify the array, an exception will be raised.

orthogonalizeRotation(self) None

Perform orthogonalization of the rotation part of the homogeneous transformation.

print(self) None

Print the matrix as a pose vector \(({\bf t}^T \theta {\bf u}^T)\) .

reshape(self, nrows: int, ncols: int) None
resize(*args, **kwargs)

Overloaded function.

  1. resize(self: visp._visp.core.HomogeneousMatrix, nrows: int, ncols: int, flagNullify: bool = true) -> None

This function is not applicable to an homogeneous matrix that is always a 4-by-4 matrix.

  1. resize(self: visp._visp.core.ArrayDouble2D, nrows: int, ncols: int, flagNullify: bool = true, recopy_: bool = true) -> None

Set the size of the array and initialize all the values to zero.

Parameters:
nrows

number of rows.

ncols

number of column.

flagNullify

if true, then the array is re-initialized to 0 after resize. If false, the initial values from the common part of the array (common part between old and new version of the array) are kept. Default value is true.

recopy_

if true, will perform an explicit recopy of the old data.

save(*args, **kwargs)

Overloaded function.

  1. save(self: visp._visp.core.HomogeneousMatrix, f: std::basic_ofstream<char, std::char_traits<char> >) -> None

Save an homogeneous matrix in an output file stream.

The code below shows how to save an homogeneous matrix in a file.

// Construct an homogeneous matrix
vpTranslationVector t(1,2,3);
vpRxyzVector r(M_PI, 0, -M_PI/4.);
vpRotationMatrix R(r);
vpHomogeneousMatrix M(t, R);

// Save the content of the matrix in "homogeneous.dat"
std::ofstream f("homogeneous.dat");
M.save(f);

Note

See save(const std::string &), load(std::ifstream &)

Parameters:
f

Output file stream. The homogeneous matrix is saved as a 4 by 4 matrix.

  1. save(self: visp._visp.core.HomogeneousMatrix, filename: str) -> None

Save an homogeneous matrix in a file.

The code below shows how to save an homogeneous matrix in a file.

// Construct an homogeneous matrix
vpTranslationVector t(1,2,3);
vpRxyzVector r(M_PI, 0, -M_PI/4.);
vpRotationMatrix R(r);
vpHomogeneousMatrix M(t, R);

// Save the content of the matrix in "homogeneous.dat"
M.save("homogeneous.dat");

Note

See save(std::ofstream &), load(const std::string &)

Parameters:
filename

Output file name. The homogeneous matrix is saved as a 4 by 4 matrix.

static saveYAML(filename: str, A: visp._visp.core.ArrayDouble2D, header: str =) bool

Save an array in a YAML-formatted file.

Here is an example of outputs.

vpArray2D<double> M(3,4);
vpArray2D::saveYAML("matrix.yml", M, "example: a YAML-formatted header");
vpArray2D::saveYAML("matrixIndent.yml", M, "example:\n    - a YAML-formatted \
header\n    - with inner indentation");

Content of matrix.yml:

example: a YAML-formatted header
rows: 3
cols: 4
data:
  - [0, 0, 0, 0]
  - [0, 0, 0, 0]
  - [0, 0, 0, 0]

Content of matrixIndent.yml:

example:
    - a YAML-formatted header
    - with inner indentation
rows: 3
cols: 4
data:
    - [0, 0, 0, 0]
    - [0, 0, 0, 0]
    - [0, 0, 0, 0]

Note

See loadYAML()

Parameters:
filename

absolute file name.

A

array to be saved in the file.

header

optional lines that will be saved at the beginning of the file. Should be YAML-formatted and will adapt to the indentation if any.

Returns:

Returns true if success.

size(self) int

Return the number of elements of the 2D array.

t(self) visp._visp.core.ArrayDouble2D

Compute the transpose of the array.

Returns:

vpArray2D<Type> C = A^T

__hash__ = None