template class cv::Matx

Overview

Template class for small matrices whose type and size are known at compilation time. Moreā€¦

#include <matx.hpp>

template <
    typename _Tp,
    int m,
    int n
    >
class Matx
{
public:
    // typedefs

    typedef Matx<_Tp, shortdim, 1> diag_type;
    typedef Matx<_Tp, m, n> mat_type;
    typedef _Tp value_type;

    // enums

    enum
    {
        depth    = DataType<_Tp>::depth,
        rows     = m,
        cols     = n,
        channels = rows*cols,
        type     = CV_MAKETYPE(depth, channels),
        shortdim = (m <n ? m : n),
    };

    // fields

    _Tp val[m *n];

    // construction

    Matx();
    Matx(_Tp v0);

    Matx(
        _Tp v0,
        _Tp v1
        );

    Matx(
        _Tp v0,
        _Tp v1,
        _Tp v2
        );

    Matx(
        _Tp v0,
        _Tp v1,
        _Tp v2,
        _Tp v3
        );

    Matx(
        _Tp v0,
        _Tp v1,
        _Tp v2,
        _Tp v3,
        _Tp v4
        );

    Matx(
        _Tp v0,
        _Tp v1,
        _Tp v2,
        _Tp v3,
        _Tp v4,
        _Tp v5
        );

    Matx(
        _Tp v0,
        _Tp v1,
        _Tp v2,
        _Tp v3,
        _Tp v4,
        _Tp v5,
        _Tp v6
        );

    Matx(
        _Tp v0,
        _Tp v1,
        _Tp v2,
        _Tp v3,
        _Tp v4,
        _Tp v5,
        _Tp v6,
        _Tp v7
        );

    Matx(
        _Tp v0,
        _Tp v1,
        _Tp v2,
        _Tp v3,
        _Tp v4,
        _Tp v5,
        _Tp v6,
        _Tp v7,
        _Tp v8
        );

    Matx(
        _Tp v0,
        _Tp v1,
        _Tp v2,
        _Tp v3,
        _Tp v4,
        _Tp v5,
        _Tp v6,
        _Tp v7,
        _Tp v8,
        _Tp v9
        );

    Matx(
        _Tp v0,
        _Tp v1,
        _Tp v2,
        _Tp v3,
        _Tp v4,
        _Tp v5,
        _Tp v6,
        _Tp v7,
        _Tp v8,
        _Tp v9,
        _Tp v10,
        _Tp v11
        );

    Matx(
        _Tp v0,
        _Tp v1,
        _Tp v2,
        _Tp v3,
        _Tp v4,
        _Tp v5,
        _Tp v6,
        _Tp v7,
        _Tp v8,
        _Tp v9,
        _Tp v10,
        _Tp v11,
        _Tp v12,
        _Tp v13
        );

    Matx(
        _Tp v0,
        _Tp v1,
        _Tp v2,
        _Tp v3,
        _Tp v4,
        _Tp v5,
        _Tp v6,
        _Tp v7,
        _Tp v8,
        _Tp v9,
        _Tp v10,
        _Tp v11,
        _Tp v12,
        _Tp v13,
        _Tp v14,
        _Tp v15
        );

    Matx(const _Tp* vals);

    Matx(
        const Matx<_Tp, m, n>& a,
        const Matx<_Tp, m, n>& b,
        Matx_AddOp
        );

    Matx(
        const Matx<_Tp, m, n>& a,
        const Matx<_Tp, m, n>& b,
        Matx_SubOp
        );

    template <typename _T2>
    Matx(
        const Matx<_Tp, m, n>& a,
        _T2 alpha,
        Matx_ScaleOp
        );

    Matx(
        const Matx<_Tp, m, n>& a,
        const Matx<_Tp, m, n>& b,
        Matx_MulOp
        );

    Matx(
        const Matx<_Tp, m, n>& a,
        const Matx<_Tp, m, n>& b,
        Matx_DivOp
        );

    template <int l>
    Matx(
        const Matx<_Tp, m, l>& a,
        const Matx<_Tp, l, n>& b,
        Matx_MatMulOp
        );

    Matx(
        const Matx<_Tp, n, m>& a,
        Matx_TOp
        );

    // methods

    template <
        typename _Tp1,
        typename _Tp2,
        int m,
        int n
        >
    static
    Matx<_Tp1, m, n>&
    operator+=(
        Matx<_Tp1, m, n>& a,
        const Matx<_Tp2, m, n>& b
        );

    template <
        typename _Tp1,
        typename _Tp2,
        int m,
        int n
        >
    static
    Matx<_Tp1, m, n>&
    operator-=(
        Matx<_Tp1, m, n>& a,
        const Matx<_Tp2, m, n>& b
        );

    template <
        typename _Tp,
        int m,
        int n
        >
    static
    Matx<_Tp, m, n>
    operator+(
        const Matx<_Tp, m, n>& a,
        const Matx<_Tp, m, n>& b
        );

    template <
        typename _Tp,
        int m,
        int n
        >
    static
    Matx<_Tp, m, n>
    operator-(
        const Matx<_Tp, m, n>& a,
        const Matx<_Tp, m, n>& b
        );

    template <
        typename _Tp,
        int m,
        int n
        >
    static
    Matx<_Tp, m, n>&
    operator*=(
        Matx<_Tp, m, n>& a,
        int alpha
        );

    template <
        typename _Tp,
        int m,
        int n
        >
    static
    Matx<_Tp, m, n>&
    operator*=(
        Matx<_Tp, m, n>& a,
        float alpha
        );

    template <
        typename _Tp,
        int m,
        int n
        >
    static
    Matx<_Tp, m, n>&
    operator*=(
        Matx<_Tp, m, n>& a,
        double alpha
        );

    template <
        typename _Tp,
        int m,
        int n
        >
    static
    Matx<_Tp, m, n>
    operator*(
        const Matx<_Tp, m, n>& a,
        int alpha
        );

    template <
        typename _Tp,
        int m,
        int n
        >
    static
    Matx<_Tp, m, n>
    operator*(
        const Matx<_Tp, m, n>& a,
        float alpha
        );

    template <
        typename _Tp,
        int m,
        int n
        >
    static
    Matx<_Tp, m, n>
    operator*(
        const Matx<_Tp, m, n>& a,
        double alpha
        );

    template <
        typename _Tp,
        int m,
        int n
        >
    static
    Matx<_Tp, m, n>
    operator*(
        int alpha,
        const Matx<_Tp, m, n>& a
        );

    template <
        typename _Tp,
        int m,
        int n
        >
    static
    Matx<_Tp, m, n>
    operator*(
        float alpha,
        const Matx<_Tp, m, n>& a
        );

    template <
        typename _Tp,
        int m,
        int n
        >
    static
    Matx<_Tp, m, n>
    operator*(
        double alpha,
        const Matx<_Tp, m, n>& a
        );

    template <
        typename _Tp,
        int m,
        int n
        >
    static
    Matx<_Tp, m, n>
    operator-(const Matx<_Tp, m, n>& a);

    template <
        typename _Tp,
        int m,
        int n,
        int l
        >
    static
    Matx<_Tp, m, n>
    operator*(
        const Matx<_Tp, m, l>& a,
        const Matx<_Tp, l, n>& b
        );

    template <
        typename _Tp,
        int m,
        int n
        >
    static
    Vec<_Tp, m>
    operator*(
        const Matx<_Tp, m, n>& a,
        const Vec<_Tp, n>& b
        );

    template <
        typename _Tp,
        int m,
        int n
        >
    static
    bool
    operator==(
        const Matx<_Tp, m, n>& a,
        const Matx<_Tp, m, n>& b
        );

    template <
        typename _Tp,
        int m,
        int n
        >
    static
    bool
    operator!=(
        const Matx<_Tp, m, n>& a,
        const Matx<_Tp, m, n>& b
        );

    Matx<_Tp, m, 1>
    col(int i) const;

    double
    ddot(const Matx<_Tp, m, n>& v) const;

    diag_type
    diag() const;

    Matx<_Tp, m, n>
    div(const Matx<_Tp, m, n>& a) const;

    _Tp
    dot(const Matx<_Tp, m, n>& v) const;

    template <
        int m1,
        int n1
        >
    Matx<_Tp, m1, n1>
    get_minor(
        int i,
        int j
        ) const;

    Matx<_Tp, n, m>
    inv(
        int method = DECOMP_LU,
        bool* p_is_ok = NULL
        ) const;

    Matx<_Tp, m, n>
    mul(const Matx<_Tp, m, n>& a) const;

    template <typename T2>
    operator Matx< T2, m, n >() const;

    const _Tp&
    operator()(
        int i,
        int j
        ) const;

    _Tp&
    operator()(
        int i,
        int j
        );

    const _Tp&
    operator()(int i) const;

    _Tp&
    operator()(int i);

    template <
        int m1,
        int n1
        >
    Matx<_Tp, m1, n1>
    reshape() const;

    Matx<_Tp, 1, n>
    row(int i) const;

    template <int l>
    Matx<_Tp, n, l>
    solve(
        const Matx<_Tp, m, l>& rhs,
        int flags = DECOMP_LU
        ) const;

    Vec<_Tp, n>
    solve(
        const Vec<_Tp, m>& rhs,
        int method
        ) const;

    Matx<_Tp, n, m>
    t() const;

    static
    Matx
    all(_Tp alpha);

    static
    Matx
    diag(const diag_type& d);

    static
    Matx
    eye();

    static
    Matx
    ones();

    static
    Matx
    randn(
        _Tp a,
        _Tp b
        );

    static
    Matx
    randu(
        _Tp a,
        _Tp b
        );

    static
    Matx
    zeros();
};

// direct descendants

template <
    typename _Tp,
    int cn
    >
class Vec;

Detailed Documentation

Template class for small matrices whose type and size are known at compilation time.

If you need a more flexible type, use Mat. The elements of the matrix M are accessible using the M(i,j) notation. Most of the common matrix operations (see also MatrixExpressions) are available. To do an operation on Matx that is not implemented, you can easily convert the matrix to Mat and backwards:

Matx33f m(1, 2, 3,
          4, 5, 6,
          7, 8, 9);
cout << sum(Mat(m*m.t())) << endl;

Construction

Matx()

default constructor

Matx(_Tp v0)

1x1 matrix

Matx(
    _Tp v0,
    _Tp v1
    )

1x2 or 2x1 matrix

Matx(
    _Tp v0,
    _Tp v1,
    _Tp v2
    )

1x3 or 3x1 matrix

Matx(
    _Tp v0,
    _Tp v1,
    _Tp v2,
    _Tp v3
    )

1x4, 2x2 or 4x1 matrix

Matx(
    _Tp v0,
    _Tp v1,
    _Tp v2,
    _Tp v3,
    _Tp v4
    )

1x5 or 5x1 matrix

Matx(
    _Tp v0,
    _Tp v1,
    _Tp v2,
    _Tp v3,
    _Tp v4,
    _Tp v5
    )

1x6, 2x3, 3x2 or 6x1 matrix

Matx(
    _Tp v0,
    _Tp v1,
    _Tp v2,
    _Tp v3,
    _Tp v4,
    _Tp v5,
    _Tp v6
    )

1x7 or 7x1 matrix

Matx(
    _Tp v0,
    _Tp v1,
    _Tp v2,
    _Tp v3,
    _Tp v4,
    _Tp v5,
    _Tp v6,
    _Tp v7
    )

1x8, 2x4, 4x2 or 8x1 matrix

Matx(
    _Tp v0,
    _Tp v1,
    _Tp v2,
    _Tp v3,
    _Tp v4,
    _Tp v5,
    _Tp v6,
    _Tp v7,
    _Tp v8
    )

1x9, 3x3 or 9x1 matrix

Matx(
    _Tp v0,
    _Tp v1,
    _Tp v2,
    _Tp v3,
    _Tp v4,
    _Tp v5,
    _Tp v6,
    _Tp v7,
    _Tp v8,
    _Tp v9
    )

1x10, 2x5 or 5x2 or 10x1 matrix

Matx(
    _Tp v0,
    _Tp v1,
    _Tp v2,
    _Tp v3,
    _Tp v4,
    _Tp v5,
    _Tp v6,
    _Tp v7,
    _Tp v8,
    _Tp v9,
    _Tp v10,
    _Tp v11
    )

1x12, 2x6, 3x4, 4x3, 6x2 or 12x1 matrix

Matx(
    _Tp v0,
    _Tp v1,
    _Tp v2,
    _Tp v3,
    _Tp v4,
    _Tp v5,
    _Tp v6,
    _Tp v7,
    _Tp v8,
    _Tp v9,
    _Tp v10,
    _Tp v11,
    _Tp v12,
    _Tp v13
    )

1x14, 2x7, 7x2 or 14x1 matrix

Matx(
    _Tp v0,
    _Tp v1,
    _Tp v2,
    _Tp v3,
    _Tp v4,
    _Tp v5,
    _Tp v6,
    _Tp v7,
    _Tp v8,
    _Tp v9,
    _Tp v10,
    _Tp v11,
    _Tp v12,
    _Tp v13,
    _Tp v14,
    _Tp v15
    )

1x16, 4x4 or 16x1 matrix

Matx(const _Tp* vals)

initialize from a plain array

Methods

Matx<_Tp, m, 1>
col(int i) const

extract the matrix column

double
ddot(const Matx<_Tp, m, n>& v) const

dot product computed in double-precision arithmetics

diag_type
diag() const

extract the matrix diagonal

Matx<_Tp, m, n>
div(const Matx<_Tp, m, n>& a) const

divide two matrices element-wise

_Tp
dot(const Matx<_Tp, m, n>& v) const

dot product computed with the default precision

template <
    int m1,
    int n1
    >
Matx<_Tp, m1, n1>
get_minor(
    int i,
    int j
    ) const

extract part of the matrix

Matx<_Tp, n, m>
inv(
    int method = DECOMP_LU,
    bool* p_is_ok = NULL
    ) const

invert the matrix

Matx<_Tp, m, n>
mul(const Matx<_Tp, m, n>& a) const

multiply two matrices element-wise

template <typename T2>
operator Matx< T2, m, n >() const

conversion to another data type

const _Tp&
operator()(
    int i,
    int j
    ) const

element access

const _Tp&
operator()(int i) const

1D element access

template <
    int m1,
    int n1
    >
Matx<_Tp, m1, n1>
reshape() const

change the matrix shape

Matx<_Tp, 1, n>
row(int i) const

extract the matrix row

template <int l>
Matx<_Tp, n, l>
solve(
    const Matx<_Tp, m, l>& rhs,
    int flags = DECOMP_LU
    ) const

solve linear system

Matx<_Tp, n, m>
t() const

transpose the matrix