class mrpt::img::TCamera

Intrinsic parameters for a pinhole or fisheye camera model, plus its associated lens distortion model.

The type of camera distortion is defined by the distortion field.

Parameters for one camera resolution can be used for any other resolutions 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;
    DistortionModel distortion = DistortionModel::none;
    std::array<double, 8> dist {{.0, .0, .0, .0, .0, .0, .0, .0}};
    double focalLengthMeters = .0;
    std::string cameraName = "camera1";

    // construction

    TCamera();

    //
methods

    mrpt::containers::yaml asYAML() const;
    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);
    std::vector<double> getDistortionParamsAsVector() const;
    mrpt::math::CMatrixDouble getDistortionParamsAsRowVector() const;

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

    void setDistortionPlumbBob(double k1_, double k2_, double p1_, double p2_, double k3_ = 0);
    void setDistortionKannalaBrandt(double k1_, double k2_, double k3_, double k4_);
    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);
    static TCamera FromYAML(const mrpt::containers::yaml& params);
};

Fields

uint32_t ncols = 640

Camera resolution.

mrpt::math::CMatrixDouble33 intrinsicParams

Camera matrix (intrinsic parameters), containing the focal length and principal point coordinates:

    [ fx  0 cx ]
A = [  0 fy cy ]
    [  0  0  1 ]
DistortionModel distortion = DistortionModel::none

The distortion model: none (already rectified), plumb_bob (common pin-hole radial and tangential distortion), or kannala_brandt (for fish-eye cameras)

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

Depending on the distortion model stored in distortion, the indices of this array mean:

It is recommended to access the specific terms via the getters k1(), k2(), p1(),… to avoid mistakes.

Default values is all to zero.

double focalLengthMeters = .0

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

std::string cameraName = "camera1"

Optional camera name.

(New in MRPT 2.1.8)

Construction

TCamera()

Default ctor: all intrinsic parameters set to zero.

Methods

mrpt::containers::yaml asYAML() const

Stores as yaml, in OpenCV calibration model.

Refer to this example.

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 ...]
camera_name = camera1
distortion = {none|plumb_bob|kannala_brandt}
[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] | [K1 K2 K3 K4]}
focal_length = FOCAL_LENGTH  [optional]
camera_name = camera1 [optional]
distortion = {none|plumb_bob|kannala_brandt}

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

Returns all parameters as a text block in the INI-file format.

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

See also:

asYAML()

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)

std::vector<double> getDistortionParamsAsVector() const

Get a vector with the distortion params of the camera, which depending on the distortion model may be an empty vector (Distortion::none), an 8-vector (Distortion::plumb_bob) or a 4-vector (Distortion::kannala_brandt)

mrpt::math::CMatrixDouble getDistortionParamsAsRowVector() const

Equivalent to getDistortionParamsAsVector()

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 setDistortionPlumbBob(
    double k1_,
    double k2_,
    double p1_,
    double p2_,
    double k3_ = 0
    )

Defines the distortion model and its parameters, in one call.

void setDistortionKannalaBrandt(double k1_, double k2_, double k3_, double k4_)

Defines the distortion model and its parameters, in one call.

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.

static TCamera FromYAML(const mrpt::containers::yaml& params)

Parse from yaml, in OpenCV calibration model.

Refer to this example.

For known distortion models see mrpt::img::DistortionModel