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)
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), width(0), height(0), isFov(false), m_hFovAngle(0),
103 m_vFovAngle(0), fovNormals(), inv_px(1. / DEFAULT_PX_PARAMETER), inv_py(1. / DEFAULT_PY_PARAMETER),
104 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), width(0), height(0), isFov(false), m_hFovAngle(0),
122 m_vFovAngle(0), fovNormals(), inv_px(1. / DEFAULT_PX_PARAMETER), inv_py(1. / DEFAULT_PY_PARAMETER),
123 projModel(DEFAULT_PROJ_TYPE)
133 if (fabs(this->px) < 1e-6) {
137 if (fabs(this->py) < 1e-6) {
141 this->inv_px = 1. / this->px;
142 this->inv_py = 1. / this->py;
194 if (fabs(px) < 1e-6) {
198 if (fabs(py) < 1e-6) {
202 this->inv_px = 1. / px;
203 this->inv_py = 1. / py;
249 double cam_v0,
double cam_kud,
double cam_kdu)
260 if (fabs(px) < 1e-6) {
264 if (fabs(py) < 1e-6) {
268 this->inv_px = 1. / px;
269 this->inv_py = 1. / py;
303 if (std::fabs(_K[2][2] - 1.0) > std::numeric_limits<double>::epsilon()) {
348 px = u0 / tan(hfov / 2);
349 py = v0 / tan(vfov / 2);
362 projModel = cam.projModel;
374 m_hFovAngle = cam.m_hFovAngle;
375 m_vFovAngle = cam.m_vFovAngle;
378 fovNormals = cam.fovNormals;
387 if (projModel != c.projModel)
390 if (!
vpMath::equal(px, c.px, std::numeric_limits<double>::epsilon()) ||
391 !
vpMath::equal(py, c.py, std::numeric_limits<double>::epsilon()) ||
392 !
vpMath::equal(u0, c.u0, std::numeric_limits<double>::epsilon()) ||
393 !
vpMath::equal(v0, c.v0, std::numeric_limits<double>::epsilon()) ||
394 !
vpMath::equal(kud, c.kud, std::numeric_limits<double>::epsilon()) ||
395 !
vpMath::equal(kdu, c.kdu, std::numeric_limits<double>::epsilon()) ||
396 !
vpMath::equal(inv_px, c.inv_px, std::numeric_limits<double>::epsilon()) ||
397 !
vpMath::equal(inv_py, c.inv_py, std::numeric_limits<double>::epsilon()))
400 if (isFov != c.isFov ||
401 !
vpMath::equal(m_hFovAngle, c.m_hFovAngle, std::numeric_limits<double>::epsilon()) ||
402 !
vpMath::equal(m_vFovAngle, c.m_vFovAngle, std::numeric_limits<double>::epsilon()) ||
403 width != c.width || height != c.height)
406 if (fovNormals.size() != c.fovNormals.size())
409 std::vector<vpColVector>::const_iterator it1 = fovNormals.begin();
410 std::vector<vpColVector>::const_iterator it2 = c.fovNormals.begin();
411 for (; it1 != fovNormals.end() && it2 != c.fovNormals.end(); ++it1, ++it2) {
423 return !(*
this == c);
434 if ((!isFov || w != width || h != height) && w != 0 && h != 0) {
435 fovNormals = std::vector<vpColVector>(4);
439 double hFovAngle = atan(((
double)w - u0) * (1.0 / px));
440 double vFovAngle = atan((v0) * (1.0 / py));
441 double minushFovAngle = atan((u0) * (1.0 / px));
442 double minusvFovAngle = atan(((
double)h - v0) * (1.0 / py));
456 nLeft = Rleft * (-n);
476 m_hFovAngle = hFovAngle + minushFovAngle;
477 m_vFovAngle = vFovAngle + minusvFovAngle;
517 K_inv[0][0] = inv_px;
518 K_inv[1][1] = inv_py;
519 K_inv[0][2] = -u0 * inv_px;
520 K_inv[1][2] = -v0 * inv_py;
533 std::ios::fmtflags original_flags(std::cout.flags());
536 std::cout.precision(10);
537 std::cout <<
"Camera parameters for perspective projection without distortion:" << std::endl;
538 std::cout <<
" px = " << px <<
"\t py = " << py << std::endl;
539 std::cout <<
" u0 = " << u0 <<
"\t v0 = " << v0 << std::endl;
542 std::cout.precision(10);
543 std::cout <<
"Camera parameters for perspective projection with distortion:" << std::endl;
544 std::cout <<
" px = " << px <<
"\t py = " << py << std::endl;
545 std::cout <<
" u0 = " << u0 <<
"\t v0 = " << v0 << std::endl;
546 std::cout <<
" kud = " << kud << std::endl;
547 std::cout <<
" kdu = " << kdu << std::endl;
551 std::cout.flags(original_flags);
564 os <<
"Camera parameters for perspective projection without distortion:" << std::endl;
565 os <<
" px = " << cam.
get_px() <<
"\t py = " << cam.
get_py() << std::endl;
566 os <<
" u0 = " << cam.
get_u0() <<
"\t v0 = " << cam.
get_v0() << std::endl;
569 std::ios_base::fmtflags original_flags = os.flags();
571 os <<
"Camera parameters for perspective projection with distortion:" << std::endl;
572 os <<
" px = " << cam.
get_px() <<
"\t py = " << cam.
get_py() << std::endl;
573 os <<
" u0 = " << cam.
get_u0() <<
"\t v0 = " << cam.
get_v0() << std::endl;
574 os <<
" kud = " << cam.
get_kud() << std::endl;
575 os <<
" kdu = " << cam.
get_kdu() << std::endl;
577 os.flags(original_flags);
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 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.
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)