50 #include <visp/vpCalibration.h>
51 #include <visp/vpDebug.h>
52 #include <visp/vpPose.h>
53 #include <visp/vpPixelMeterConversion.h>
55 double vpCalibration::threshold = 1e-10f;
56 unsigned int vpCalibration::nbIterMax = 4000;
57 double vpCalibration::gain = 0.25;
65 residual = residual_dist = 1000.;
79 : cMo(), cMo_dist(), cam(), cam_dist(), rMe(), eMc(), eMc_dist(),
80 npt(0), LoX(), LoY(), LoZ(), Lip(), residual(1000.), residual_dist(1000.)
88 : cMo(), cMo_dist(), cam(), cam_dist(), rMe(), eMc(), eMc_dist(),
89 npt(0), LoX(), LoY(), LoZ(), Lip(), residual(1000.), residual_dist(1000.)
110 npt = twinCalibration.npt ;
111 LoX = twinCalibration.LoX ;
112 LoY = twinCalibration.LoY ;
113 LoZ = twinCalibration.LoZ ;
114 Lip = twinCalibration.Lip ;
116 residual = twinCalibration.residual;
117 cMo = twinCalibration.
cMo;
118 residual_dist = twinCalibration.residual_dist;
121 cam = twinCalibration.
cam ;
124 rMe = twinCalibration.
rMe;
126 eMc = twinCalibration.
eMc;
178 std::list<double>::const_iterator it_LoX = LoX.begin();
179 std::list<double>::const_iterator it_LoY = LoY.begin();
180 std::list<double>::const_iterator it_LoZ = LoZ.begin();
181 std::list<vpImagePoint>::const_iterator it_Lip = Lip.begin();
183 for (
unsigned int i =0 ; i < npt ; i++)
214 if (residual_lagrange < residual_dementhon)
215 cMo_est = cMo_lagrange;
217 cMo_est = cMo_dementhon;
234 double residual_ = 0 ;
236 std::list<double>::const_iterator it_LoX = LoX.begin();
237 std::list<double>::const_iterator it_LoY = LoY.begin();
238 std::list<double>::const_iterator it_LoZ = LoZ.begin();
239 std::list<vpImagePoint>::const_iterator it_Lip = Lip.begin();
241 double u0 = camera.
get_u0() ;
242 double v0 = camera.
get_v0() ;
243 double px = camera.
get_px() ;
244 double py = camera.
get_py() ;
247 for (
unsigned int i =0 ; i < npt ; i++)
253 double cX = oX*cMo_est[0][0]+oY*cMo_est[0][1]+oZ*cMo_est[0][2] + cMo_est[0][3];
254 double cY = oX*cMo_est[1][0]+oY*cMo_est[1][1]+oZ*cMo_est[1][2] + cMo_est[1][3];
255 double cZ = oX*cMo_est[2][0]+oY*cMo_est[2][1]+oZ*cMo_est[2][2] + cMo_est[2][3];
261 double u = ip.
get_u() ;
262 double v = ip.
get_v() ;
264 double xp = u0 + x*px;
265 double yp = v0 + y*py;
274 this->residual = residual_ ;
275 return sqrt(residual_/npt) ;
287 double residual_ = 0 ;
289 std::list<double>::const_iterator it_LoX = LoX.begin();
290 std::list<double>::const_iterator it_LoY = LoY.begin();
291 std::list<double>::const_iterator it_LoZ = LoZ.begin();
292 std::list<vpImagePoint>::const_iterator it_Lip = Lip.begin();
294 double u0 = camera.
get_u0() ;
295 double v0 = camera.
get_v0() ;
296 double px = camera.
get_px() ;
297 double py = camera.
get_py() ;
298 double kud = camera.
get_kud() ;
299 double kdu = camera.
get_kdu() ;
301 double inv_px = 1/px;
302 double inv_py = 1/px;
305 for (
unsigned int i =0 ; i < npt ; i++)
311 double cX = oX*cMo_est[0][0]+oY*cMo_est[0][1]+oZ*cMo_est[0][2] + cMo_est[0][3];
312 double cY = oX*cMo_est[1][0]+oY*cMo_est[1][1]+oZ*cMo_est[1][2] + cMo_est[1][3];
313 double cZ = oX*cMo_est[2][0]+oY*cMo_est[2][1]+oZ*cMo_est[2][2] + cMo_est[2][3];
319 double u = ip.
get_u() ;
320 double v = ip.
get_v() ;
324 double xp = u0 + x*px*r2ud;
325 double yp = v0 + y*py*r2ud;
331 xp = u0 + x*px - kdu*(u-u0)*r2du;
332 yp = v0 + y*py - kdu*(v-v0)*r2du;
342 this->residual_dist = residual_;
343 return sqrt(residual_/npt) ;
377 computePose(cam_est,cMo_est);
383 calibLagrange(cam_est, cMo_est);
400 if (verbose){std::cout <<
"start calibration without distortion"<< std::endl;}
401 calibVVS(cam_est, cMo_est, verbose);
424 if (verbose){std::cout <<
"start calibration with distortion"<< std::endl;}
425 calibVVSWithDistortion(cam_est, cMo_est, verbose);
465 std::vector<vpCalibration> &table_cal,
467 double &globalReprojectionError,
471 unsigned int nbPose = (
unsigned int) table_cal.size();
472 for(
unsigned int i=0;i<nbPose;i++){
474 table_cal[i].computePose(cam_est,table_cal[i].
cMo);
479 std::cout <<
"this calibration method is not available in" << std::endl
480 <<
"vpCalibration::computeCalibrationMulti()" << std::endl;
484 table_cal[0].calibLagrange(cam_est,table_cal[0].
cMo);
485 table_cal[0].cam = cam_est ;
486 table_cal[0].cam_dist = cam_est ;
487 table_cal[0].cMo_dist = table_cal[0].cMo ;
493 std::cout <<
"this calibration method is not available in" << std::endl
494 <<
"vpCalibration::computeCalibrationMulti()" << std::endl
495 <<
"with several images." << std::endl;
499 table_cal[0].calibLagrange(cam_est,table_cal[0].
cMo);
500 table_cal[0].cam = cam_est ;
501 table_cal[0].cam_dist = cam_est ;
502 table_cal[0].cMo_dist = table_cal[0].cMo ;
507 calibVVSMulti(table_cal, cam_est, globalReprojectionError, verbose);
528 std::cout <<
"Compute camera parameters with distortion"<<std::endl;
530 calibVVSWithDistortionMulti(table_cal, cam_est, globalReprojectionError, verbose);
537 table_cal[0].cam.printParameters();
540 std::cout<<std::endl;
567 unsigned int nbPose = (
unsigned int)table_cal.size();
569 std::vector<vpHomogeneousMatrix> table_cMo(nbPose);
570 std::vector<vpHomogeneousMatrix> table_cMo_dist(nbPose);
571 std::vector<vpHomogeneousMatrix> table_rMe(nbPose);
573 for(
unsigned int i=0;i<nbPose;i++){
574 table_cMo[i] = table_cal[i].cMo;
575 table_cMo_dist[i] = table_cal[i].cMo_dist;
576 table_rMe[i] = table_cal[i].rMe;
584 vpERROR_TRACE(
"Three images are needed to compute Tsai calibration !\n");
603 std::ofstream f(filename) ;
606 std::list<double>::const_iterator it_LoX = LoX.begin();
607 std::list<double>::const_iterator it_LoY = LoY.begin();
608 std::list<double>::const_iterator it_LoZ = LoZ.begin();
609 std::list<vpImagePoint>::const_iterator it_Lip = Lip.begin();
612 f.setf(std::ios::fixed,std::ios::floatfield);
613 f << LoX.size() << std::endl ;
615 for (
unsigned int i =0 ; i < LoX.size() ; i++)
623 double u = ip.
get_u() ;
624 double v = ip.
get_v() ;
626 f << oX <<
" " << oY <<
" " << oZ <<
" " << u <<
" " << v <<std::endl ;
653 std::cout <<
"There are "<< n <<
" point on the calibration grid " << std::endl ;
660 for (
unsigned int i=0 ; i < n ; i++)
662 double x, y, z, u, v ;
663 f >> x >> y >> z >> u >> v ;
664 std::cout << x <<
" "<<y <<
" "<<z<<
" "<<u<<
" "<<v <<std::endl ;
694 std::list<double> &oX, std::list<double> &oY, std::list<double> &oZ,
bool verbose)
703 std::cout <<
"There are "<< n <<
" points on the calibration grid " << std::endl ;
715 for (
unsigned int i=0 ; i < n ; i++)
717 f >> no_pt >> x >> y >> z ;
719 std::cout << no_pt <<std::endl ;
720 std::cout << x <<
" "<< y <<
" "<< z <<std::endl ;
733 catch(...){
return -1;}
745 unsigned int thickness)
748 for (std::list<vpImagePoint>::const_iterator it = Lip.begin(); it != Lip.end(); ++ it) {
762 unsigned int thickness)
776 std::list<double>::const_iterator it_LoX = LoX.begin();
777 std::list<double>::const_iterator it_LoY = LoY.begin();
778 std::list<double>::const_iterator it_LoZ = LoZ.begin();
780 for (
unsigned int i =0 ; i < npt ; i++)
786 double cX = oX*
cMo[0][0]+oY*
cMo[0][1]+oZ*
cMo[0][2] +
cMo[0][3];
787 double cY = oX*cMo[1][0]+oY*cMo[1][1]+oZ*cMo[1][2] + cMo[1][3];
788 double cZ = oX*cMo[2][0]+oY*cMo[2][1]+oZ*cMo[2][2] + cMo[2][3];
800 cY = oX*cMo_dist[1][0]+oY*cMo_dist[1][1]+oZ*cMo_dist[1][2]+cMo_dist[1][3];
801 cZ = oX*cMo_dist[2][0]+oY*cMo_dist[2][1]+oZ*cMo_dist[2][2]+cMo_dist[2][3];
809 ip.
set_u( u0_dist + x*px_dist*r2 );
810 ip.set_v( v0_dist + y*py_dist*r2 );
824 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
848 for(
unsigned int i=0;i<nbPose;i++){
850 table_cal[i].computePose(cam_est,table_cal[i].
cMo);
855 std::cout <<
"this calibration method is not available in" << std::endl
856 <<
"vpCalibration::computeCalibrationMulti()" << std::endl;
860 table_cal[0].calibLagrange(cam_est,table_cal[0].
cMo);
861 table_cal[0].
cam = cam_est ;
869 std::cout <<
"this calibration method is not available in" << std::endl
870 <<
"vpCalibration::computeCalibrationMulti()" << std::endl
871 <<
"with several images." << std::endl;
875 table_cal[0].calibLagrange(cam_est,table_cal[0].
cMo);
876 table_cal[0].
cam = cam_est ;
883 calibVVSMulti(nbPose, table_cal, cam_est, verbose);
904 std::cout <<
"Compute camera parameters with distortion"<<std::endl;
906 calibVVSWithDistortionMulti(nbPose, table_cal, cam_est, verbose);
916 std::cout<<std::endl;
953 for(
unsigned int i=0;i<nbPose;i++){
954 table_cMo[i] = table_cal[i].
cMo;
955 table_cMo_dist[i] = table_cal[i].
cMo_dist;
956 table_rMe[i] = table_cal[i].
rMe;
962 delete [] table_cMo_dist;
968 vpERROR_TRACE(
"Three images are needed to compute Tsai calibration !\n");
1006 std::cout <<
"There are "<< n <<
" points on the calibration grid " << std::endl ;
1017 for (
unsigned int i=0 ; i < n ; i++)
1019 f >> no_pt >> x >> y >> z ;
1021 std::cout << no_pt <<std::endl ;
1022 std::cout << x <<
" "<< y <<
" "<< z <<std::endl ;
1035 catch(...){
return -1;}
1039 #endif // VISP_BUILD_DEPRECATED_FUNCTIONS
int displayGrid(vpImage< unsigned char > &I, vpColor color=vpColor::yellow, unsigned int thickness=1)
int computeCalibration(vpCalibrationMethodType method, vpHomogeneousMatrix &cMo_est, vpCameraParameters &cam_est, bool verbose=false)
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
Provide simple list management.
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 displayData(vpImage< unsigned char > &I, vpColor color=vpColor::red, unsigned int thickness=1)
int clearPoint()
Suppress all the point in the array of point.
void set_u(const double u)
static double sqr(double x)
void front(void)
Position the current element on the first element of the list.
vpHomogeneousMatrix cMo_dist
virtual void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)=0
void set_v(const double v)
Class used for pose computation from N points (pose from point only).
Generic class defining intrinsic camera parameters.
void addRight(const type &el)
add a new element in the list, at the right of the current one
vpHomogeneousMatrix eMc_dist
void set_y(const double y)
Set the point y coordinate in the image plane.
unsigned int get_npt() const
get the number of points
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 .
vpCameraParameters cam_dist
projection model with distortion
int writeData(const char *filename)
vpHomogeneousMatrix eMc
position of the camera in relation to the effector
void computePose(vpPoseMethodType methode, vpHomogeneousMatrix &cMo)
compute the pose for a given method
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)
Add a new point in this array.
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)
void setWorldCoordinates(const double ox, const double oy, const double oz)
Set the point world coordinates. We mean here the coordinates of the point in the object frame...
void clearPoint()
suppress all the point in the array of point