52 #include <visp3/core/vpCameraParameters.h> 53 #include <visp3/core/vpDebug.h> 54 #include <visp3/core/vpException.h> 55 #include <visp3/core/vpRotationMatrix.h> 57 const double vpCameraParameters::DEFAULT_PX_PARAMETER = 600.0;
58 const double vpCameraParameters::DEFAULT_PY_PARAMETER = 600.0;
59 const double vpCameraParameters::DEFAULT_U0_PARAMETER = 192.0;
60 const double vpCameraParameters::DEFAULT_V0_PARAMETER = 144.0;
61 const double vpCameraParameters::DEFAULT_KUD_PARAMETER = 0.0;
62 const double vpCameraParameters::DEFAULT_KDU_PARAMETER = 0.0;
73 : px(DEFAULT_PX_PARAMETER), py(DEFAULT_PY_PARAMETER), u0(DEFAULT_U0_PARAMETER), v0(DEFAULT_V0_PARAMETER),
74 kud(DEFAULT_KUD_PARAMETER), kdu(DEFAULT_KDU_PARAMETER), m_dist_coefs(), width(0), height(0),
75 isFov(false), m_hFovAngle(0), m_vFovAngle(0), fovNormals(), inv_px(1. / DEFAULT_PX_PARAMETER),
76 inv_py(1. / DEFAULT_PY_PARAMETER), projModel(DEFAULT_PROJ_TYPE)
85 : px(DEFAULT_PX_PARAMETER), py(DEFAULT_PY_PARAMETER), u0(DEFAULT_U0_PARAMETER), v0(DEFAULT_V0_PARAMETER),
86 kud(DEFAULT_KUD_PARAMETER), kdu(DEFAULT_KDU_PARAMETER), m_dist_coefs(), width(0), height(0),
87 isFov(false), m_hFovAngle(0), m_vFovAngle(0), fovNormals(), inv_px(1. / DEFAULT_PX_PARAMETER),
88 inv_py(1. / DEFAULT_PY_PARAMETER), projModel(DEFAULT_PROJ_TYPE)
101 : px(DEFAULT_PX_PARAMETER), py(DEFAULT_PY_PARAMETER), u0(DEFAULT_U0_PARAMETER), v0(DEFAULT_V0_PARAMETER),
102 kud(DEFAULT_KUD_PARAMETER), kdu(DEFAULT_KDU_PARAMETER), m_dist_coefs(), width(0), height(0),
103 isFov(false), m_hFovAngle(0), m_vFovAngle(0), fovNormals(), inv_px(1. / DEFAULT_PX_PARAMETER),
104 inv_py(1. / DEFAULT_PY_PARAMETER), projModel(DEFAULT_PROJ_TYPE)
119 double cam_v0,
double cam_kud,
double cam_kdu)
120 : px(DEFAULT_PX_PARAMETER), py(DEFAULT_PY_PARAMETER), u0(DEFAULT_U0_PARAMETER), v0(DEFAULT_V0_PARAMETER),
121 kud(DEFAULT_KUD_PARAMETER), kdu(DEFAULT_KDU_PARAMETER), m_dist_coefs(), width(0), height(0),
122 isFov(false), m_hFovAngle(0), m_vFovAngle(0), fovNormals(), inv_px(1. / DEFAULT_PX_PARAMETER),
123 inv_py(1. / DEFAULT_PY_PARAMETER), projModel(DEFAULT_PROJ_TYPE)
137 double cam_v0,
const std::vector<double> &coefficients)
138 : px(DEFAULT_PX_PARAMETER), py(DEFAULT_PY_PARAMETER), u0(DEFAULT_U0_PARAMETER), v0(DEFAULT_V0_PARAMETER),
139 kud(DEFAULT_KUD_PARAMETER), kdu(DEFAULT_KDU_PARAMETER), m_dist_coefs(), width(0), height(0),
140 isFov(false), m_hFovAngle(0), m_vFovAngle(0), fovNormals(), inv_px(1. / DEFAULT_PX_PARAMETER),
141 inv_py(1. / DEFAULT_PY_PARAMETER), projModel(DEFAULT_PROJ_TYPE)
151 if (fabs(this->px) < 1e-6) {
154 if (fabs(this->py) < 1e-6) {
157 this->inv_px = 1. / this->px;
158 this->inv_py = 1. / this->py;
210 if (fabs(px) < 1e-6) {
213 if (fabs(py) < 1e-6) {
216 this->inv_px = 1. / px;
217 this->inv_py = 1. / py;
263 double cam_v0,
double cam_kud,
double cam_kdu)
274 if (fabs(px) < 1e-6) {
277 if (fabs(py) < 1e-6) {
280 this->inv_px = 1. / px;
281 this->inv_py = 1. / py;
291 const std::vector<double> &coefficients)
300 if (fabs(px) < 1e-6) {
303 if (fabs(py) < 1e-6) {
306 this->inv_px = 1. / px;
307 this->inv_py = 1. / py;
309 this->m_dist_coefs = coefficients;
343 if (std::fabs(_K[2][2] - 1.0) > std::numeric_limits<double>::epsilon()) {
388 px = u0 / tan(hfov / 2);
389 py = v0 / tan(vfov / 2);
402 projModel = cam.projModel;
409 m_dist_coefs = cam.m_dist_coefs;
415 m_hFovAngle = cam.m_hFovAngle;
416 m_vFovAngle = cam.m_vFovAngle;
419 fovNormals = cam.fovNormals;
428 if (projModel != c.projModel)
431 if (!
vpMath::equal(px, c.px, std::numeric_limits<double>::epsilon()) ||
432 !
vpMath::equal(py, c.py, std::numeric_limits<double>::epsilon()) ||
433 !
vpMath::equal(u0, c.u0, std::numeric_limits<double>::epsilon()) ||
434 !
vpMath::equal(v0, c.v0, std::numeric_limits<double>::epsilon()) ||
435 !
vpMath::equal(kud, c.kud, std::numeric_limits<double>::epsilon()) ||
436 !
vpMath::equal(kdu, c.kdu, std::numeric_limits<double>::epsilon()) ||
437 !
vpMath::equal(inv_px, c.inv_px, std::numeric_limits<double>::epsilon()) ||
438 !
vpMath::equal(inv_py, c.inv_py, std::numeric_limits<double>::epsilon()))
441 for(
unsigned int i = 0; i < m_dist_coefs.size(); i++)
442 if(!
vpMath::equal(m_dist_coefs[i], c.m_dist_coefs[i], std::numeric_limits<double>::epsilon()))
445 if (isFov != c.isFov ||
446 !
vpMath::equal(m_hFovAngle, c.m_hFovAngle, std::numeric_limits<double>::epsilon()) ||
447 !
vpMath::equal(m_vFovAngle, c.m_vFovAngle, std::numeric_limits<double>::epsilon()) ||
448 width != c.width || height != c.height)
451 if (fovNormals.size() != c.fovNormals.size())
454 std::vector<vpColVector>::const_iterator it1 = fovNormals.begin();
455 std::vector<vpColVector>::const_iterator it2 = c.fovNormals.begin();
456 for (; it1 != fovNormals.end() && it2 != c.fovNormals.end(); ++it1, ++it2) {
468 return !(*
this == c);
479 if ((!isFov || w != width || h != height) && w != 0 && h != 0) {
480 fovNormals = std::vector<vpColVector>(4);
484 double hFovAngle = atan(((
double)w - u0) * (1.0 / px));
485 double vFovAngle = atan((v0) * (1.0 / py));
486 double minushFovAngle = atan((u0) * (1.0 / px));
487 double minusvFovAngle = atan(((
double)h - v0) * (1.0 / py));
501 nLeft = Rleft * (-n);
521 m_hFovAngle = hFovAngle + minushFovAngle;
522 m_vFovAngle = vFovAngle + minusvFovAngle;
562 K_inv[0][0] = inv_px;
563 K_inv[1][1] = inv_py;
564 K_inv[0][2] = -u0 * inv_px;
565 K_inv[1][2] = -v0 * inv_py;
578 std::ios::fmtflags original_flags(std::cout.flags());
581 std::cout.precision(10);
582 std::cout <<
"Camera parameters for perspective projection without distortion:" << std::endl;
583 std::cout <<
" px = " << px <<
"\t py = " << py << std::endl;
584 std::cout <<
" u0 = " << u0 <<
"\t v0 = " << v0 << std::endl;
587 std::cout.precision(10);
588 std::cout <<
"Camera parameters for perspective projection with distortion:" << std::endl;
589 std::cout <<
" px = " << px <<
"\t py = " << py << std::endl;
590 std::cout <<
" u0 = " << u0 <<
"\t v0 = " << v0 << std::endl;
591 std::cout <<
" kud = " << kud << std::endl;
592 std::cout <<
" kdu = " << kdu << std::endl;
595 std::cout <<
" Coefficients: ";
596 for (
unsigned int i = 0; i < m_dist_coefs.size(); i++)
597 std::cout <<
" " << m_dist_coefs[i];
598 std::cout << std::endl;
602 std::cout.flags(original_flags);
615 os <<
"Camera parameters for perspective projection without distortion:" << std::endl;
616 os <<
" px = " << cam.
get_px() <<
"\t py = " << cam.
get_py() << std::endl;
617 os <<
" u0 = " << cam.
get_u0() <<
"\t v0 = " << cam.
get_v0() << std::endl;
621 std::ios_base::fmtflags original_flags = os.flags();
623 os <<
"Camera parameters for perspective projection with distortion:" << std::endl;
624 os <<
" px = " << cam.
get_px() <<
"\t py = " << cam.
get_py() << std::endl;
625 os <<
" u0 = " << cam.
get_u0() <<
"\t v0 = " << cam.
get_v0() << std::endl;
626 os <<
" kud = " << cam.
get_kud() << std::endl;
627 os <<
" kdu = " << cam.
get_kdu() << std::endl;
628 os.flags(original_flags);
633 os <<
"Camera parameters for projection with Kannala-Brandt distortion:" << std::endl;
634 os <<
" px = " << cam.
get_px() <<
"\t py = " << cam.
get_py() << std::endl;
635 os <<
" u0 = " << cam.
get_u0() <<
"\t v0 = " << cam.
get_v0() << std::endl;
636 os <<
" Coefficients: ";
638 for(
unsigned int i = 0; i < tmp_coefs.size(); i++)
639 os <<
" " << tmp_coefs[i];
Used to indicate that a value is not in the allowed range.
Implementation of a matrix and operations on matrices.
void initFromCalibrationMatrix(const vpMatrix &_K)
void init()
basic initialization with the default parameters
vpCameraParametersProjType get_projModel() const
static bool equal(double x, double y, double s=0.001)
error that can be emited by ViSP classes.
unsigned int getRows() const
virtual ~vpCameraParameters()
void initProjWithKannalaBrandtDistortion(double px, double py, double u0, double v0, const std::vector< double > &distortion_coefficients)
void initPersProjWithDistortion(double px, double py, double u0, double v0, double kud, double kdu)
bool operator!=(const vpCameraParameters &c) const
Implementation of a rotation matrix and operations on such kind of matrices.
unsigned int getCols() const
vpColVector & normalize()
void initFromFov(const unsigned int &w, const unsigned int &h, const double &hfov, const double &vfov)
bool operator==(const vpCameraParameters &c) const
vpCameraParametersProjType
Generic class defining intrinsic camera parameters.
std::vector< double > getKannalaBrandtDistortionCoefficients() const
void initPersProjWithoutDistortion(double px, double py, double u0, double v0)
Implementation of column vector and the associated operations.
friend VISP_EXPORT std::ostream & operator<<(std::ostream &os, const vpCameraParameters &cam)
vpCameraParameters & operator=(const vpCameraParameters &c)
vpMatrix get_K_inverse() const
void computeFov(const unsigned int &w, const unsigned int &h)