46 #include <visp3/vision/vpCalibration.h>
47 #include <visp3/core/vpDebug.h>
48 #include <visp3/vision/vpPose.h>
49 #include <visp3/core/vpPixelMeterConversion.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(),
76 npt(0), LoX(), LoY(), LoZ(), Lip(), residual(1000.), residual_dist(1000.)
84 : cMo(), cMo_dist(), cam(), cam_dist(), rMe(), eMc(), eMc_dist(),
85 npt(0), LoX(), LoY(), LoZ(), Lip(), residual(1000.), residual_dist(1000.)
106 npt = twinCalibration.npt ;
107 LoX = twinCalibration.LoX ;
108 LoY = twinCalibration.LoY ;
109 LoZ = twinCalibration.LoZ ;
110 Lip = twinCalibration.Lip ;
112 residual = twinCalibration.residual;
113 cMo = twinCalibration.
cMo;
114 residual_dist = twinCalibration.residual_dist;
117 cam = twinCalibration.
cam ;
120 rMe = twinCalibration.
rMe;
122 eMc = twinCalibration.
eMc;
174 std::list<double>::const_iterator it_LoX = LoX.begin();
175 std::list<double>::const_iterator it_LoY = LoY.begin();
176 std::list<double>::const_iterator it_LoZ = LoZ.begin();
177 std::list<vpImagePoint>::const_iterator it_Lip = Lip.begin();
179 for (
unsigned int i =0 ; i < npt ; i++)
181 vpPoint P(*it_LoX, *it_LoY, *it_LoZ);
209 if (residual_lagrange < residual_dementhon)
210 cMo_est = cMo_lagrange;
212 cMo_est = cMo_dementhon;
229 double residual_ = 0 ;
231 std::list<double>::const_iterator it_LoX = LoX.begin();
232 std::list<double>::const_iterator it_LoY = LoY.begin();
233 std::list<double>::const_iterator it_LoZ = LoZ.begin();
234 std::list<vpImagePoint>::const_iterator it_Lip = Lip.begin();
236 double u0 = camera.
get_u0() ;
237 double v0 = camera.
get_v0() ;
238 double px = camera.
get_px() ;
239 double py = camera.
get_py() ;
242 for (
unsigned int i =0 ; i < npt ; i++)
248 double cX = oX*cMo_est[0][0]+oY*cMo_est[0][1]+oZ*cMo_est[0][2] + cMo_est[0][3];
249 double cY = oX*cMo_est[1][0]+oY*cMo_est[1][1]+oZ*cMo_est[1][2] + cMo_est[1][3];
250 double cZ = oX*cMo_est[2][0]+oY*cMo_est[2][1]+oZ*cMo_est[2][2] + cMo_est[2][3];
256 double u = ip.
get_u() ;
257 double v = ip.
get_v() ;
259 double xp = u0 + x*px;
260 double yp = v0 + y*py;
269 this->residual = residual_ ;
270 return sqrt(residual_/npt) ;
282 double residual_ = 0 ;
284 std::list<double>::const_iterator it_LoX = LoX.begin();
285 std::list<double>::const_iterator it_LoY = LoY.begin();
286 std::list<double>::const_iterator it_LoZ = LoZ.begin();
287 std::list<vpImagePoint>::const_iterator it_Lip = Lip.begin();
289 double u0 = camera.
get_u0() ;
290 double v0 = camera.
get_v0() ;
291 double px = camera.
get_px() ;
292 double py = camera.
get_py() ;
293 double kud = camera.
get_kud() ;
294 double kdu = camera.
get_kdu() ;
296 double inv_px = 1/px;
297 double inv_py = 1/px;
300 for (
unsigned int i =0 ; i < npt ; i++)
306 double cX = oX*cMo_est[0][0]+oY*cMo_est[0][1]+oZ*cMo_est[0][2] + cMo_est[0][3];
307 double cY = oX*cMo_est[1][0]+oY*cMo_est[1][1]+oZ*cMo_est[1][2] + cMo_est[1][3];
308 double cZ = oX*cMo_est[2][0]+oY*cMo_est[2][1]+oZ*cMo_est[2][2] + cMo_est[2][3];
314 double u = ip.
get_u() ;
315 double v = ip.
get_v() ;
319 double xp = u0 + x*px*r2ud;
320 double yp = v0 + y*py*r2ud;
326 xp = u0 + x*px - kdu*(u-u0)*r2du;
327 yp = v0 + y*py - kdu*(v-v0)*r2du;
337 this->residual_dist = residual_;
338 return sqrt(residual_/npt) ;
372 computePose(cam_est,cMo_est);
378 calibLagrange(cam_est, cMo_est);
395 if (verbose){std::cout <<
"start calibration without distortion"<< std::endl;}
396 calibVVS(cam_est, cMo_est, verbose);
419 if (verbose){std::cout <<
"start calibration with distortion"<< std::endl;}
420 calibVVSWithDistortion(cam_est, cMo_est, verbose);
460 std::vector<vpCalibration> &table_cal,
462 double &globalReprojectionError,
466 unsigned int nbPose = (
unsigned int) table_cal.size();
467 for(
unsigned int i=0;i<nbPose;i++){
469 table_cal[i].computePose(cam_est,table_cal[i].
cMo);
474 std::cout <<
"this calibration method is not available in" << std::endl
475 <<
"vpCalibration::computeCalibrationMulti()" << std::endl;
479 table_cal[0].calibLagrange(cam_est,table_cal[0].
cMo);
480 table_cal[0].cam = cam_est ;
481 table_cal[0].cam_dist = cam_est ;
482 table_cal[0].cMo_dist = table_cal[0].cMo ;
489 std::cout <<
"this calibration method is not available in" << std::endl
490 <<
"vpCalibration::computeCalibrationMulti()" << std::endl
491 <<
"with several images." << std::endl;
495 table_cal[0].calibLagrange(cam_est,table_cal[0].
cMo);
496 table_cal[0].cam = cam_est ;
497 table_cal[0].cam_dist = cam_est ;
498 table_cal[0].cMo_dist = table_cal[0].cMo ;
500 calibVVSMulti(table_cal, cam_est, globalReprojectionError, verbose);
505 calibVVSMulti(table_cal, cam_est, globalReprojectionError, verbose);
526 std::cout <<
"Compute camera parameters with distortion"<<std::endl;
528 calibVVSWithDistortionMulti(table_cal, cam_est, globalReprojectionError, verbose);
535 table_cal[0].cam.printParameters();
538 std::cout<<std::endl;
565 unsigned int nbPose = (
unsigned int)table_cal.size();
567 std::vector<vpHomogeneousMatrix> table_cMo(nbPose);
568 std::vector<vpHomogeneousMatrix> table_cMo_dist(nbPose);
569 std::vector<vpHomogeneousMatrix> table_rMe(nbPose);
571 for(
unsigned int i=0;i<nbPose;i++){
572 table_cMo[i] = table_cal[i].cMo;
573 table_cMo_dist[i] = table_cal[i].cMo_dist;
574 table_rMe[i] = table_cal[i].rMe;
582 vpERROR_TRACE(
"Three images are needed to compute Tsai calibration !\n");
601 std::ofstream f(filename) ;
604 std::list<double>::const_iterator it_LoX = LoX.begin();
605 std::list<double>::const_iterator it_LoY = LoY.begin();
606 std::list<double>::const_iterator it_LoZ = LoZ.begin();
607 std::list<vpImagePoint>::const_iterator it_Lip = Lip.begin();
610 f.setf(std::ios::fixed,std::ios::floatfield);
611 f << LoX.size() << std::endl ;
613 for (
unsigned int i =0 ; i < LoX.size() ; i++)
621 double u = ip.
get_u() ;
622 double v = ip.
get_v() ;
624 f << oX <<
" " << oY <<
" " << oZ <<
" " << u <<
" " << v <<std::endl ;
651 std::cout <<
"There are "<< n <<
" point on the calibration grid " << std::endl ;
658 for (
unsigned int i=0 ; i < n ; i++)
660 double x, y, z, u, v ;
661 f >> x >> y >> z >> u >> v ;
662 std::cout << x <<
" "<<y <<
" "<<z<<
" "<<u<<
" "<<v <<std::endl ;
692 std::list<double> &oX, std::list<double> &oY, std::list<double> &oZ,
bool verbose)
701 std::cout <<
"There are "<< n <<
" points on the calibration grid " << std::endl ;
713 for (
unsigned int i=0 ; i < n ; i++)
715 f >> no_pt >> x >> y >> z ;
717 std::cout << no_pt <<std::endl ;
718 std::cout << x <<
" "<< y <<
" "<< z <<std::endl ;
731 catch(...){
return -1;}
746 unsigned int thickness,
int subsampling_factor)
749 for (std::list<vpImagePoint>::const_iterator it = Lip.begin(); it != Lip.end(); ++ it) {
751 if (subsampling_factor > 1.) {
771 unsigned int thickness,
int subsampling_factor)
785 std::list<double>::const_iterator it_LoX = LoX.begin();
786 std::list<double>::const_iterator it_LoY = LoY.begin();
787 std::list<double>::const_iterator it_LoZ = LoZ.begin();
789 for (
unsigned int i =0 ; i < npt ; i++)
809 double cY = oX*cMo_dist[1][0]+oY*cMo_dist[1][1]+oZ*cMo_dist[1][2]+cMo_dist[1][3];
810 double cZ = oX*cMo_dist[2][0]+oY*cMo_dist[2][1]+oZ*cMo_dist[2][2]+cMo_dist[2][3];
818 ip.
set_u( u0_dist + x*px_dist*r2 );
819 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)
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.
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
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
unsigned int get_npt() const
get the number of points
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 calibrationTsai(std::vector< vpHomogeneousMatrix > &cMo, std::vector< vpHomogeneousMatrix > &rMe, vpHomogeneousMatrix &eMc)
calibration method of effector-camera from R. Tsai and R. Lorenz .
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
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 ...
static int computeCalibrationTsai(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 computeStdDeviation(double &deviation, double &deviation_dist)
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)
double computeResidual(const vpHomogeneousMatrix &cMo) const
Compute and return the residual expressed in meter for the pose matrix 'cMo'.
static int readGrid(const char *filename, unsigned int &n, std::list< double > &oX, std::list< double > &oY, std::list< double > &oZ, bool verbose=false)