46 #include <visp3/core/vpDebug.h> 47 #include <visp3/core/vpPixelMeterConversion.h> 48 #include <visp3/vision/vpCalibration.h> 49 #include <visp3/vision/vpPose.h> 51 double vpCalibration::threshold = 1e-10f;
52 unsigned int vpCalibration::nbIterMax = 4000;
53 double vpCalibration::gain = 0.25;
61 residual = residual_dist = 1000.;
75 :
cMo(),
cMo_dist(),
cam(),
cam_dist(),
rMe(),
eMc(),
eMc_dist(), npt(0), LoX(), LoY(), LoZ(), Lip(), residual(1000.),
84 :
cMo(),
cMo_dist(),
cam(),
cam_dist(),
rMe(),
eMc(),
eMc_dist(), npt(0), LoX(), LoY(), LoZ(), Lip(), residual(1000.),
102 npt = twinCalibration.npt;
103 LoX = twinCalibration.LoX;
104 LoY = twinCalibration.LoY;
105 LoZ = twinCalibration.LoZ;
106 Lip = twinCalibration.Lip;
108 residual = twinCalibration.residual;
109 cMo = twinCalibration.
cMo;
110 residual_dist = twinCalibration.residual_dist;
113 cam = twinCalibration.
cam;
116 rMe = twinCalibration.
rMe;
118 eMc = twinCalibration.
eMc;
170 std::list<double>::const_iterator it_LoX = LoX.begin();
171 std::list<double>::const_iterator it_LoY = LoY.begin();
172 std::list<double>::const_iterator it_LoZ = LoZ.begin();
173 std::list<vpImagePoint>::const_iterator it_Lip = Lip.begin();
175 for (
unsigned int i = 0; i < npt; i++) {
176 vpPoint P(*it_LoX, *it_LoY, *it_LoZ);
204 if (residual_lagrange < residual_dementhon)
205 cMo_est = cMo_lagrange;
207 cMo_est = cMo_dementhon;
223 double residual_ = 0;
225 std::list<double>::const_iterator it_LoX = LoX.begin();
226 std::list<double>::const_iterator it_LoY = LoY.begin();
227 std::list<double>::const_iterator it_LoZ = LoZ.begin();
228 std::list<vpImagePoint>::const_iterator it_Lip = Lip.begin();
230 double u0 = camera.
get_u0();
231 double v0 = camera.
get_v0();
232 double px = camera.
get_px();
233 double py = camera.
get_py();
236 for (
unsigned int i = 0; i < npt; i++) {
241 double cX = oX * cMo_est[0][0] + oY * cMo_est[0][1] + oZ * cMo_est[0][2] + cMo_est[0][3];
242 double cY = oX * cMo_est[1][0] + oY * cMo_est[1][1] + oZ * cMo_est[1][2] + cMo_est[1][3];
243 double cZ = oX * cMo_est[2][0] + oY * cMo_est[2][1] + oZ * cMo_est[2][2] + cMo_est[2][3];
249 double u = ip.
get_u();
250 double v = ip.
get_v();
252 double xp = u0 + x * px;
253 double yp = v0 + y * py;
262 this->residual = residual_;
263 return sqrt(residual_ / npt);
274 double residual_ = 0;
276 std::list<double>::const_iterator it_LoX = LoX.begin();
277 std::list<double>::const_iterator it_LoY = LoY.begin();
278 std::list<double>::const_iterator it_LoZ = LoZ.begin();
279 std::list<vpImagePoint>::const_iterator it_Lip = Lip.begin();
281 double u0 = camera.
get_u0();
282 double v0 = camera.
get_v0();
283 double px = camera.
get_px();
284 double py = camera.
get_py();
288 double inv_px = 1 / px;
289 double inv_py = 1 / px;
292 for (
unsigned int i = 0; i < npt; i++) {
297 double cX = oX * cMo_est[0][0] + oY * cMo_est[0][1] + oZ * cMo_est[0][2] + cMo_est[0][3];
298 double cY = oX * cMo_est[1][0] + oY * cMo_est[1][1] + oZ * cMo_est[1][2] + cMo_est[1][3];
299 double cZ = oX * cMo_est[2][0] + oY * cMo_est[2][1] + oZ * cMo_est[2][2] + cMo_est[2][3];
305 double u = ip.
get_u();
306 double v = ip.
get_v();
310 double xp = u0 + x * px * r2ud;
311 double yp = v0 + y * py * r2ud;
317 xp = u0 + x * px - kdu * (u - u0) * r2du;
318 yp = v0 + y * py - kdu * (v - v0) * r2du;
328 this->residual_dist = residual_;
329 return sqrt(residual_ / npt);
360 computePose(cam_est, cMo_est);
364 calibLagrange(cam_est, cMo_est);
379 std::cout <<
"start calibration without distortion" << std::endl;
381 calibVVS(cam_est, cMo_est, verbose);
403 std::cout <<
"start calibration with distortion" << std::endl;
405 calibVVSWithDistortion(cam_est, cMo_est, verbose);
449 unsigned int nbPose = (
unsigned int)table_cal.size();
450 for (
unsigned int i = 0; i < nbPose; i++) {
451 if (table_cal[i].
get_npt() > 3)
452 table_cal[i].computePose(cam_est, table_cal[i].
cMo);
457 std::cout <<
"this calibration method is not available in" << std::endl
458 <<
"vpCalibration::computeCalibrationMulti()" << std::endl;
461 table_cal[0].calibLagrange(cam_est, table_cal[0].
cMo);
462 table_cal[0].cam = cam_est;
463 table_cal[0].cam_dist = cam_est;
464 table_cal[0].cMo_dist = table_cal[0].cMo;
471 std::cout <<
"this calibration method is not available in" << std::endl
472 <<
"vpCalibration::computeCalibrationMulti()" << std::endl
473 <<
"with several images." << std::endl;
476 table_cal[0].calibLagrange(cam_est, table_cal[0].
cMo);
477 table_cal[0].cam = cam_est;
478 table_cal[0].cam_dist = cam_est;
479 table_cal[0].cMo_dist = table_cal[0].cMo;
481 calibVVSMulti(table_cal, cam_est, globalReprojectionError, verbose);
486 calibVVSMulti(table_cal, cam_est, globalReprojectionError, verbose);
506 std::cout <<
"Compute camera parameters with distortion" << std::endl;
508 calibVVSWithDistortionMulti(table_cal, cam_est, globalReprojectionError, verbose);
515 table_cal[0].cam.printParameters();
518 std::cout << std::endl;
547 unsigned int nbPose = (
unsigned int)table_cal.size();
549 std::vector<vpHomogeneousMatrix> table_cMo(nbPose);
550 std::vector<vpHomogeneousMatrix> table_cMo_dist(nbPose);
551 std::vector<vpHomogeneousMatrix> table_rMe(nbPose);
553 for (
unsigned int i = 0; i < nbPose; i++) {
554 table_cMo[i] = table_cal[i].cMo;
555 table_cMo_dist[i] = table_cal[i].cMo_dist;
556 table_rMe[i] = table_cal[i].rMe;
563 vpERROR_TRACE(
"Three images are needed to compute Tsai calibration !\n");
580 std::ofstream f(filename);
583 std::list<double>::const_iterator it_LoX = LoX.begin();
584 std::list<double>::const_iterator it_LoY = LoY.begin();
585 std::list<double>::const_iterator it_LoZ = LoZ.begin();
586 std::list<vpImagePoint>::const_iterator it_Lip = Lip.begin();
589 f.setf(std::ios::fixed, std::ios::floatfield);
590 f << LoX.size() << std::endl;
592 for (
unsigned int i = 0; i < LoX.size(); i++) {
599 double u = ip.
get_u();
600 double v = ip.
get_v();
602 f << oX <<
" " << oY <<
" " << oZ <<
" " << u <<
" " << v << std::endl;
628 std::cout <<
"There are " << n <<
" point on the calibration grid " << std::endl;
635 for (
unsigned int i = 0; i < n; i++) {
636 double x, y, z, u, v;
637 f >> x >> y >> z >> u >> v;
638 std::cout << x <<
" " << y <<
" " << z <<
" " << u <<
" " << v << std::endl;
667 std::list<double> &oZ,
bool verbose)
676 std::cout <<
"There are " << n <<
" points on the calibration grid " << std::endl;
688 for (
unsigned int i = 0; i < n; i++) {
689 f >> no_pt >> x >> y >> z;
691 std::cout << no_pt << std::endl;
692 std::cout << x <<
" " << y <<
" " << z << std::endl;
722 for (std::list<vpImagePoint>::const_iterator it = Lip.begin(); it != Lip.end(); ++it) {
724 if (subsampling_factor > 1.) {
757 std::list<double>::const_iterator it_LoX = LoX.begin();
758 std::list<double>::const_iterator it_LoY = LoY.begin();
759 std::list<double>::const_iterator it_LoZ = LoZ.begin();
761 for (
unsigned int i = 0; i < npt; i++) {
781 double cY = oX * cMo_dist[1][0] + oY * cMo_dist[1][1] + oZ * cMo_dist[1][2] + cMo_dist[1][3];
782 double cZ = oX * cMo_dist[2][0] + oY * cMo_dist[2][1] + oZ * cMo_dist[2][2] + cMo_dist[2][3];
790 ip.
set_u(u0_dist + x * px_dist * r2);
791 ip.set_v(v0_dist + y * py_dist * r2);
int computeCalibration(vpCalibrationMethodType method, vpHomogeneousMatrix &cMo_est, vpCameraParameters &cam_est, bool verbose=false)
Implementation of an homogeneous matrix and operations on such kind of matrices.
int readData(const char *filename)
Class to define colors available for display functionnalities.
error that can be emited by ViSP classes.
int addPoint(double X, double Y, double Z, vpImagePoint &ip)
void set_x(const double x)
Set the point x coordinate in the image plane.
static void convertPoint(const vpCameraParameters &cam, const double &u, const double &v, double &x, double &y)
Point coordinates conversion from pixel coordinates to normalized coordinates in meter...
Tools for perspective camera calibration.
vpHomogeneousMatrix cMo
(as a 3x4 matrix [R T])
Class that defines what is a point.
vpCalibration & operator=(const vpCalibration &twinCalibration)
int clearPoint()
Suppress all the point in the array of point.
static int computeCalibrationTsai(const std::vector< vpCalibration > &table_cal, vpHomogeneousMatrix &eMc, vpHomogeneousMatrix &eMc_dist)
Compute the multi-image calibration of effector-camera from R. Tsai and R. Lenz . ...
void set_u(const double u)
static double sqr(double x)
int displayGrid(vpImage< unsigned char > &I, vpColor color=vpColor::yellow, unsigned int thickness=1, int subsampling_factor=1)
vpHomogeneousMatrix cMo_dist
unsigned int get_npt() const
get the number of points
void set_v(const double v)
Class used for pose computation from N points (pose from point only). Some of the algorithms implemen...
Generic class defining intrinsic camera parameters.
vpHomogeneousMatrix eMc_dist
void set_y(const double y)
Set the point y coordinate in the image plane.
bool computePose(vpPoseMethodType method, vpHomogeneousMatrix &cMo, bool(*func)(vpHomogeneousMatrix *)=NULL)
vpHomogeneousMatrix rMe
reference coordinates (manipulator base coordinates)
double computeStdDeviation_dist(const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam)
static void displayCross(const vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
vpCameraParameters cam_dist
projection model with distortion
static void calibrationTsai(const std::vector< vpHomogeneousMatrix > &cMo, const std::vector< vpHomogeneousMatrix > &rMe, vpHomogeneousMatrix &eMc)
calibration method of effector-camera from R. Tsai and R. Lorenz .
int writeData(const char *filename)
vpHomogeneousMatrix eMc
position of the camera in relation to the effector
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
void computeStdDeviation(double &deviation, double &deviation_dist)
double computeResidual(const vpHomogeneousMatrix &cMo) const
Compute and return the residual expressed in meter for the pose matrix 'cMo'.
vpCameraParameters cam
projection model without distortion
static int computeCalibrationMulti(vpCalibrationMethodType method, std::vector< vpCalibration > &table_cal, vpCameraParameters &cam, double &globalReprojectionError, bool verbose=false)
void addPoint(const vpPoint &P)
int displayData(vpImage< unsigned char > &I, vpColor color=vpColor::red, unsigned int thickness=1, int subsampling_factor=1)
static int readGrid(const char *filename, unsigned int &n, std::list< double > &oX, std::list< double > &oY, std::list< double > &oZ, bool verbose=false)