39 #include <visp3/core/vpDebug.h>
40 #include <visp3/core/vpPixelMeterConversion.h>
41 #include <visp3/vision/vpCalibration.h>
42 #include <visp3/vision/vpPose.h>
46 double vpCalibration::m_threshold = 1e-10f;
47 unsigned int vpCalibration::m_nbIterMax = 4000;
48 double vpCalibration::m_gain = 0.25;
54 m_residual = m_residual_dist = 1000.;
65 : cMo(), cMo_dist(), cam(), cam_dist(), rMe(), eMc(), eMc_dist(), m_aspect_ratio(-1), m_npt(0),
66 m_LoX(), m_LoY(), m_LoZ(), m_Lip(), m_residual(1000.), m_residual_dist(1000.)
73 : cMo(), cMo_dist(), cam(), cam_dist(), rMe(), eMc(), eMc_dist(), m_aspect_ratio(-1), m_npt(0),
74 m_LoX(), m_LoY(), m_LoZ(), m_Lip(), m_residual(1000.), m_residual_dist(1000.)
83 m_npt = twinCalibration.m_npt;
84 m_LoX = twinCalibration.m_LoX;
85 m_LoY = twinCalibration.m_LoY;
86 m_LoZ = twinCalibration.m_LoZ;
87 m_Lip = twinCalibration.m_Lip;
89 m_residual = twinCalibration.m_residual;
91 m_residual_dist = twinCalibration.m_residual_dist;
144 std::list<double>::const_iterator it_LoX = m_LoX.begin();
145 std::list<double>::const_iterator it_LoY = m_LoY.begin();
146 std::list<double>::const_iterator it_LoZ = m_LoZ.begin();
147 std::list<vpImagePoint>::const_iterator it_Lip = m_Lip.begin();
149 for (
unsigned int i = 0; i < m_npt; i++) {
150 vpPoint P(*it_LoX, *it_LoY, *it_LoZ);
172 std::list<double>::const_iterator it_LoX = m_LoX.begin();
173 std::list<double>::const_iterator it_LoY = m_LoY.begin();
174 std::list<double>::const_iterator it_LoZ = m_LoZ.begin();
175 std::list<vpImagePoint>::const_iterator it_Lip = m_Lip.begin();
177 double u0 = camera.
get_u0();
178 double v0 = camera.
get_v0();
179 double px = camera.
get_px();
180 double py = camera.
get_py();
183 for (
unsigned int i = 0; i < m_npt; i++) {
188 double cX = oX * cMo_est[0][0] + oY * cMo_est[0][1] + oZ * cMo_est[0][2] + cMo_est[0][3];
189 double cY = oX * cMo_est[1][0] + oY * cMo_est[1][1] + oZ * cMo_est[1][2] + cMo_est[1][3];
190 double cZ = oX * cMo_est[2][0] + oY * cMo_est[2][1] + oZ * cMo_est[2][2] + cMo_est[2][3];
196 double u = ip.
get_u();
197 double v = ip.
get_v();
199 double xp = u0 + x * px;
200 double yp = v0 + y * py;
209 return sqrt(m_residual / m_npt);
216 std::list<double>::const_iterator it_LoX = m_LoX.begin();
217 std::list<double>::const_iterator it_LoY = m_LoY.begin();
218 std::list<double>::const_iterator it_LoZ = m_LoZ.begin();
219 std::list<vpImagePoint>::const_iterator it_Lip = m_Lip.begin();
221 double u0 = camera.
get_u0();
222 double v0 = camera.
get_v0();
223 double px = camera.
get_px();
224 double py = camera.
get_py();
228 double inv_px = 1 / px;
229 double inv_py = 1 / px;
232 for (
unsigned int i = 0; i < m_npt; i++) {
237 double cX = oX * cMo_est[0][0] + oY * cMo_est[0][1] + oZ * cMo_est[0][2] + cMo_est[0][3];
238 double cY = oX * cMo_est[1][0] + oY * cMo_est[1][1] + oZ * cMo_est[1][2] + cMo_est[1][3];
239 double cZ = oX * cMo_est[2][0] + oY * cMo_est[2][1] + oZ * cMo_est[2][2] + cMo_est[2][3];
245 double u = ip.
get_u();
246 double v = ip.
get_v();
250 double xp = u0 + x * px * r2ud;
251 double yp = v0 + y * py * r2ud;
257 xp = u0 + x * px - kdu * (u - u0) * r2du;
258 yp = v0 + y * py - kdu * (v - v0) * r2du;
266 m_residual_dist /= 2;
268 return sqrt(m_residual_dist / m_npt);
281 computePose(cam_est, cMo_est);
285 calibLagrange(cam_est, cMo_est);
300 std::cout <<
"start calibration without distortion" << std::endl;
302 calibVVS(cam_est, cMo_est, verbose);
324 std::cout <<
"start calibration with distortion" << std::endl;
326 calibVVSWithDistortion(cam_est, cMo_est, verbose);
350 std::cout <<
"Unable to calibrate the camera. Estimated parameters are negative." << std::endl;
366 unsigned int nbPose = (
unsigned int)table_cal.size();
367 for (
unsigned int i = 0; i < nbPose; i++) {
368 if (table_cal[i].
get_npt() > 3)
369 table_cal[i].computePose(cam_est, table_cal[i].
cMo);
374 std::cout <<
"this calibration method is not available in" << std::endl
375 <<
"vpCalibration::computeCalibrationMulti()" << std::endl;
379 table_cal[0].calibLagrange(cam_est, table_cal[0].
cMo);
380 table_cal[0].cam = cam_est;
381 table_cal[0].cam_dist = cam_est;
382 table_cal[0].cMo_dist = table_cal[0].cMo;
389 std::cout <<
"this calibration method is not available in" << std::endl
390 <<
"vpCalibration::computeCalibrationMulti()" << std::endl
391 <<
"with several images." << std::endl;
395 table_cal[0].calibLagrange(cam_est, table_cal[0].
cMo);
396 table_cal[0].cam = cam_est;
397 table_cal[0].cam_dist = cam_est;
398 table_cal[0].cMo_dist = table_cal[0].cMo;
400 calibVVSMulti(table_cal, cam_est, globalReprojectionError, verbose, table_cal[0].
m_aspect_ratio);
405 calibVVSMulti(table_cal, cam_est, globalReprojectionError, verbose, table_cal[0].
m_aspect_ratio);
425 std::cout <<
"Compute camera parameters with distortion" << std::endl;
427 calibVVSWithDistortionMulti(table_cal, cam_est, globalReprojectionError, verbose, table_cal[0].
m_aspect_ratio);
434 table_cal[0].cam.printParameters();
437 std::cout << std::endl;
442 std::cout <<
"Unable to calibrate the camera. Estimated parameters are negative." << std::endl;
456 std::ofstream f(filename.c_str());
459 std::list<double>::const_iterator it_LoX = m_LoX.begin();
460 std::list<double>::const_iterator it_LoY = m_LoY.begin();
461 std::list<double>::const_iterator it_LoZ = m_LoZ.begin();
462 std::list<vpImagePoint>::const_iterator it_Lip = m_Lip.begin();
465 f.setf(std::ios::fixed, std::ios::floatfield);
466 f << m_LoX.size() << std::endl;
468 for (
unsigned int i = 0; i < m_LoX.size(); ++i) {
475 double u = ip.
get_u();
476 double v = ip.
get_v();
478 f << oX <<
" " << oY <<
" " << oZ <<
" " << u <<
" " << v << std::endl;
494 f.open(filename.c_str());
498 std::cout <<
"There are " << n <<
" point on the calibration grid " << std::endl;
505 for (
unsigned int i = 0; i < n; i++) {
506 double x, y, z, u, v;
507 f >> x >> y >> z >> u >> v;
508 std::cout << x <<
" " << y <<
" " << z <<
" " << u <<
" " << v << std::endl;
523 std::list<double> &oZ,
bool verbose)
527 f.open(filename.c_str());
532 std::cout <<
"There are " << n <<
" points on the calibration grid " << std::endl;
544 for (
unsigned int i = 0; i < n; i++) {
545 f >> no_pt >> x >> y >> z;
547 std::cout << no_pt << std::endl;
548 std::cout << x <<
" " << y <<
" " << z << std::endl;
570 for (std::list<vpImagePoint>::const_iterator it = m_Lip.begin(); it != m_Lip.end(); ++it) {
572 if (subsampling_factor > 1.) {
595 std::list<double>::const_iterator it_LoX = m_LoX.begin();
596 std::list<double>::const_iterator it_LoY = m_LoY.begin();
597 std::list<double>::const_iterator it_LoZ = m_LoZ.begin();
599 for (
unsigned int i = 0; i < m_npt; i++) {
614 ip.
set_u(u0_dist + x * px_dist * r2);
615 ip.set_v(v0_dist + y * py_dist * r2);
631 if (aspect_ratio > 0.) {
Tools for perspective camera calibration.
void computeStdDeviation(double &deviation, double &deviation_dist)
int displayData(vpImage< unsigned char > &I, vpColor color=vpColor::red, unsigned int thickness=1, int subsampling_factor=1)
unsigned int get_npt() const
int computeCalibration(vpCalibrationMethodType method, vpHomogeneousMatrix &cMo_est, vpCameraParameters &cam_est, bool verbose=false)
int addPoint(double X, double Y, double Z, vpImagePoint &ip)
vpHomogeneousMatrix eMc_dist
int writeData(const std::string &filename)
vpCalibration & operator=(const vpCalibration &twinCalibration)
double computeStdDeviation_dist(const vpHomogeneousMatrix &cMo_est, const vpCameraParameters &camera)
static int computeCalibrationMulti(vpCalibrationMethodType method, std::vector< vpCalibration > &table_cal, vpCameraParameters &cam_est, double &globalReprojectionError, bool verbose=false)
vpCameraParameters cam_dist
static int readGrid(const std::string &filename, unsigned int &n, std::list< double > &oX, std::list< double > &oY, std::list< double > &oZ, bool verbose=false)
void setAspectRatio(double aspect_ratio)
vpHomogeneousMatrix cMo_dist
int displayGrid(vpImage< unsigned char > &I, vpColor color=vpColor::yellow, unsigned int thickness=1, int subsampling_factor=1)
@ CALIB_LAGRANGE_VIRTUAL_VS
@ CALIB_LAGRANGE_VIRTUAL_VS_DIST
int readData(const std::string &filename)
Generic class defining intrinsic camera parameters.
Class to define RGB colors available for display functionalities.
static void displayCross(const vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
error that can be emitted by ViSP classes.
@ badValue
Used to indicate that a value is not in the allowed range.
Implementation of an homogeneous matrix and operations on such kind of matrices.
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
static double sqr(double x)
static void convertPoint(const vpCameraParameters &cam, const double &u, const double &v, double &x, double &y)
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
Class used for pose computation from N points (pose from point only). Some of the algorithms implemen...
void addPoint(const vpPoint &P)
@ DEMENTHON_LAGRANGE_VIRTUAL_VS
bool computePose(vpPoseMethodType method, vpHomogeneousMatrix &cMo, FuncCheckValidityPose func=nullptr)