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), width(0), height(0), isFov(false), m_hFovAngle(0),
75 m_vFovAngle(0), fovNormals(), inv_px(1. / DEFAULT_PX_PARAMETER), inv_py(1. / DEFAULT_PY_PARAMETER),
76 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), width(0), height(0), isFov(false), m_hFovAngle(0),
87 m_vFovAngle(0), fovNormals(), inv_px(1. / DEFAULT_PX_PARAMETER), inv_py(1. / DEFAULT_PY_PARAMETER),
88 projModel(DEFAULT_PROJ_TYPE)
102 : px(DEFAULT_PX_PARAMETER), py(DEFAULT_PY_PARAMETER), u0(DEFAULT_U0_PARAMETER), v0(DEFAULT_V0_PARAMETER),
103 kud(DEFAULT_KUD_PARAMETER), kdu(DEFAULT_KDU_PARAMETER), width(0), height(0), isFov(false), m_hFovAngle(0),
104 m_vFovAngle(0), fovNormals(), inv_px(1. / DEFAULT_PX_PARAMETER), inv_py(1. / DEFAULT_PY_PARAMETER),
105 projModel(DEFAULT_PROJ_TYPE)
120 const double cam_v0,
const double cam_kud,
const double cam_kdu)
121 : px(DEFAULT_PX_PARAMETER), py(DEFAULT_PY_PARAMETER), u0(DEFAULT_U0_PARAMETER), v0(DEFAULT_V0_PARAMETER),
122 kud(DEFAULT_KUD_PARAMETER), kdu(DEFAULT_KDU_PARAMETER), width(0), height(0), isFov(false), m_hFovAngle(0),
123 m_vFovAngle(0), fovNormals(), inv_px(1. / DEFAULT_PX_PARAMETER), inv_py(1. / DEFAULT_PY_PARAMETER),
124 projModel(DEFAULT_PROJ_TYPE)
134 if (fabs(this->px) < 1e-6) {
138 if (fabs(this->py) < 1e-6) {
142 this->inv_px = 1. / this->px;
143 this->inv_py = 1. / this->py;
195 if (fabs(px) < 1e-6) {
199 if (fabs(py) < 1e-6) {
203 this->inv_px = 1. / px;
204 this->inv_py = 1. / py;
250 const double cam_v0,
const double cam_kud,
const double cam_kdu)
261 if (fabs(px) < 1e-6) {
265 if (fabs(py) < 1e-6) {
269 this->inv_px = 1. / px;
270 this->inv_py = 1. / py;
304 if (std::fabs(_K[2][2] - 1.0) > std::numeric_limits<double>::epsilon()) {
349 px = u0 / tan(hfov / 2);
350 py = v0 / tan(vfov / 2);
363 projModel = cam.projModel;
375 m_hFovAngle = cam.m_hFovAngle;
376 m_vFovAngle = cam.m_vFovAngle;
379 fovNormals = cam.fovNormals;
388 if (projModel != c.projModel)
391 if (!
vpMath::equal(px, c.px, std::numeric_limits<double>::epsilon()) ||
392 !
vpMath::equal(py, c.py, std::numeric_limits<double>::epsilon()) ||
393 !
vpMath::equal(u0, c.u0, std::numeric_limits<double>::epsilon()) ||
394 !
vpMath::equal(v0, c.v0, std::numeric_limits<double>::epsilon()) ||
395 !
vpMath::equal(kud, c.kud, std::numeric_limits<double>::epsilon()) ||
396 !
vpMath::equal(kdu, c.kdu, std::numeric_limits<double>::epsilon()) ||
397 !
vpMath::equal(inv_px, c.inv_px, std::numeric_limits<double>::epsilon()) ||
398 !
vpMath::equal(inv_py, c.inv_py, std::numeric_limits<double>::epsilon()))
401 if (isFov != c.isFov ||
402 !
vpMath::equal(m_hFovAngle, c.m_hFovAngle, std::numeric_limits<double>::epsilon()) ||
403 !
vpMath::equal(m_vFovAngle, c.m_vFovAngle, std::numeric_limits<double>::epsilon()) ||
404 width != c.width || height != c.height)
407 if (fovNormals.size() != c.fovNormals.size())
410 std::vector<vpColVector>::const_iterator it1 = fovNormals.begin();
411 std::vector<vpColVector>::const_iterator it2 = c.fovNormals.begin();
412 for (; it1 != fovNormals.end() && it2 != c.fovNormals.end(); ++it1, ++it2) {
424 return !(*
this == c);
435 if ((!isFov || w != width || h != height) && w != 0 && h != 0) {
436 fovNormals = std::vector<vpColVector>(4);
440 double hFovAngle = atan(((
double)w - u0) * (1.0 / px));
441 double vFovAngle = atan((v0) * (1.0 / py));
442 double minushFovAngle = atan((u0) * (1.0 / px));
443 double minusvFovAngle = atan(((
double)h - v0) * (1.0 / py));
457 nLeft = Rleft * (-n);
477 m_hFovAngle = hFovAngle + minushFovAngle;
478 m_vFovAngle = vFovAngle + minusvFovAngle;
518 K_inv[0][0] = inv_px;
519 K_inv[1][1] = inv_py;
520 K_inv[0][2] = -u0 * inv_px;
521 K_inv[1][2] = -v0 * inv_py;
534 std::ios::fmtflags original_flags(std::cout.flags());
537 std::cout.precision(10);
538 std::cout <<
"Camera parameters for perspective projection without distortion:" << std::endl;
539 std::cout <<
" px = " << px <<
"\t py = " << py << std::endl;
540 std::cout <<
" u0 = " << u0 <<
"\t v0 = " << v0 << std::endl;
543 std::cout.precision(10);
544 std::cout <<
"Camera parameters for perspective projection with distortion:" << std::endl;
545 std::cout <<
" px = " << px <<
"\t py = " << py << std::endl;
546 std::cout <<
" u0 = " << u0 <<
"\t v0 = " << v0 << std::endl;
547 std::cout <<
" kud = " << kud << std::endl;
548 std::cout <<
" kdu = " << kdu << std::endl;
552 std::cout.flags(original_flags);
565 os <<
"Camera parameters for perspective projection without distortion:" << std::endl;
566 os <<
" px = " << cam.
get_px() <<
"\t py = " << cam.
get_py() << std::endl;
567 os <<
" u0 = " << cam.
get_u0() <<
"\t v0 = " << cam.
get_v0() << std::endl;
570 std::ios_base::fmtflags original_flags = os.flags();
572 os <<
"Camera parameters for perspective projection with distortion:" << std::endl;
573 os <<
" px = " << cam.
get_px() <<
"\t py = " << cam.
get_py() << std::endl;
574 os <<
" u0 = " << cam.
get_u0() <<
"\t v0 = " << cam.
get_v0() << std::endl;
575 os <<
" kud = " << cam.
get_kud() << std::endl;
576 os <<
" kdu = " << cam.
get_kdu() << std::endl;
578 os.flags(original_flags);
bool operator!=(const vpCameraParameters &c) const
vpMatrix get_K_inverse() const
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
static bool equal(double x, double y, double s=0.001)
error that can be emited by ViSP classes.
unsigned int getCols() const
virtual ~vpCameraParameters()
Implementation of a rotation matrix and operations on such kind of matrices.
void initPersProjWithoutDistortion(const double px, const double py, const double u0, const double v0)
vpColVector & normalize()
void initFromFov(const unsigned int &w, const unsigned int &h, const double &hfov, const double &vfov)
vpCameraParametersProjType
Generic class defining intrinsic camera parameters.
unsigned int getRows() const
Implementation of column vector and the associated operations.
vpCameraParametersProjType get_projModel() const
bool operator==(const vpCameraParameters &c) const
friend VISP_EXPORT std::ostream & operator<<(std::ostream &os, const vpCameraParameters &cam)
vpCameraParameters & operator=(const vpCameraParameters &c)
void initPersProjWithDistortion(const double px, const double py, const double u0, const double v0, const double kud, const double kdu)
void computeFov(const unsigned int &w, const unsigned int &h)