class mrpt::img::TCamera

Parameters for the Brown-Conrady camera lens distortion model.

The parameters obtained for one camera resolution can be used for any other resolution by means of the method TCamera::scaleToResolution()

See also:

The application camera-calib-gui for calibrating a camera

#include <mrpt/img/TCamera.h>

class TCamera: public mrpt::serialization::CSerializable
{
public:
    //
fields

    uint32_t ncols {640};
    uint32_t nrows {480};
    mrpt::math::CMatrixDouble33 intrinsicParams;
    std::array<double, 8> dist {{.0, .0, .0, .0, .0, .0, .0, .0}};
    double focalLengthMeters {.0};

    //
methods

    void scaleToResolution(unsigned int new_ncols, unsigned int new_nrows);
    void saveToConfigFile(const std::string& section, mrpt::config::CConfigFileBase& cfg) const;
    void loadFromConfigFile(const std::string& section, const mrpt::config::CConfigFileBase& cfg);
    void loadFromConfigFile(const mrpt::config::CConfigFileBase& cfg, const std::string& section);
    std::string dumpAsText() const;
    void setIntrinsicParamsFromValues(double fx, double fy, double cx, double cy);
    void getDistortionParamsVector(mrpt::math::CMatrixDouble15& distParVector) const;
    std::vector<double> getDistortionParamsAsVector() const;
    void setDistortionParamsVector(const mrpt::math::CMatrixDouble15& distParVector);

    template <class VECTORLIKE>
    void setDistortionParamsVector(const VECTORLIKE& distParVector);

    void setDistortionParamsFromValues(double k1, double k2, double p1, double p2, double k3 = 0);
    double cx() const;
    double cy() const;
    double fx() const;
    double fy() const;
    void cx(double val);
    void cy(double val);
    void fx(double val);
    void fy(double val);
    double k1() const;
    double k2() const;
    double p1() const;
    double p2() const;
    double k3() const;
    double k4() const;
    double k5() const;
    double k6() const;
    void k1(double val);
    void k2(double val);
    void p1(double val);
    void p2(double val);
    void k3(double val);
    void k4(double val);
    void k5(double val);
    void k6(double val);
};

Fields

uint32_t ncols {640}

Camera resolution.

mrpt::math::CMatrixDouble33 intrinsicParams

Matrix of intrinsic parameters (containing the focal length and principal point coordinates):

[ fx 0 cx ] A = [ 0 fy cy ] [ 0 0 1 ]

std::array<double, 8> dist {{.0, .0, .0, .0, .0, .0, .0, .0}}

[k1 k2 t1 t2 k3 k4 k5 k6] -> k_i: parameters of radial distortion, t_i: parameters of tangential distortion (default=0)

double focalLengthMeters {.0}

The focal length of the camera, in meters (can be used among ‘intrinsicParams’ to determine the pixel size).

Methods

void scaleToResolution(unsigned int new_ncols, unsigned int new_nrows)

Rescale all the parameters for a new camera resolution (it raises an exception if the aspect ratio is modified, which is not permitted).

void saveToConfigFile(const std::string& section, mrpt::config::CConfigFileBase& cfg) const

Save as a config block:

[SECTION]
resolution = [NCOLS NROWS]
cx         = CX
cy         = CY
fx         = FX
fy         = FY
dist       = [K1 K2 T1 T2 K3]
focal_length = FOCAL_LENGTH
[SECTION]
resolution = NCOLS NROWS
cx         = CX
cy         = CY
fx         = FX
fy         = FY
dist       = K1 K2 T1 T2 T3
focal_length = FOCAL_LENGTH
void loadFromConfigFile(const std::string& section, const mrpt::config::CConfigFileBase& cfg)

Load all the params from a config source, in the format used in saveToConfigFile(), that is:

Load all the params from a config source, in the format described in saveToConfigFile()

[SECTION]
resolution = [NCOLS NROWS]
cx         = CX
cy         = CY
fx         = FX
fy         = FY
dist       = [K1 K2 T1 T2 K3]
focal_length = FOCAL_LENGTH  [optional field]

Parameters:

std::exception

on missing fields

void loadFromConfigFile(const mrpt::config::CConfigFileBase& cfg, const std::string& section)

overload This signature is consistent with the rest of MRPT APIs

std::string dumpAsText() const

Dumps all the parameters as a multi-line string, with the same format than saveToConfigFile.

See also:

saveToConfigFile

void setIntrinsicParamsFromValues(double fx, double fy, double cx, double cy)

Set the matrix of intrinsic params of the camera from the individual values of focal length and principal point coordinates (in pixels)

void getDistortionParamsVector(mrpt::math::CMatrixDouble15& distParVector) const

Get the vector of distortion params of the camera.

std::vector<double> getDistortionParamsAsVector() const

Get a vector with the distortion params of the camera.

void setDistortionParamsVector(const mrpt::math::CMatrixDouble15& distParVector)

Set the whole vector of distortion params of the camera.

template <class VECTORLIKE>
void setDistortionParamsVector(const VECTORLIKE& distParVector)

Set the whole vector of distortion params of the camera from a 4, 5, or 8-vector (see definition of dist for parameter order)

void setDistortionParamsFromValues(
    double k1,
    double k2,
    double p1,
    double p2,
    double k3 = 0
    )

Set the vector of distortion params of the camera from the individual values of the distortion coefficients.

double cx() const

Get the value of the principal point x-coordinate (in pixels).

double cy() const

Get the value of the principal point y-coordinate (in pixels).

double fx() const

Get the value of the focal length x-value (in pixels).

double fy() const

Get the value of the focal length y-value (in pixels).

void cx(double val)

Set the value of the principal point x-coordinate (in pixels).

void cy(double val)

Set the value of the principal point y-coordinate (in pixels).

void fx(double val)

Set the value of the focal length x-value (in pixels).

void fy(double val)

Set the value of the focal length y-value (in pixels).

double k1() const

Get the value of the k1 distortion parameter.

double k2() const

Get the value of the k2 distortion parameter.

double p1() const

Get the value of the p1 distortion parameter.

double p2() const

Get the value of the p2 distortion parameter.

double k3() const

Get the value of the k3 distortion parameter.

double k4() const

Get the value of the k4 distortion parameter.

double k5() const

Get the value of the k5 distortion parameter.

double k6() const

Get the value of the k6 distortion parameter.

void k1(double val)

Set the value of the k1 distortion parameter.

void k2(double val)

Set the value of the k2 distortion parameter.

void p1(double val)

Set the value of the p1 distortion parameter.

void p2(double val)

Set the value of the p2 distortion parameter.

void k3(double val)

Set the value of the k3 distortion parameter.

void k4(double val)

Set the value of the k4 distortion parameter.

void k5(double val)

Set the value of the k5 distortion parameter.

void k6(double val)

Set the value of the k6 distortion parameter.