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 ;
494 std::cout <<
"this calibration method is not available in" << std::endl
495 <<
"vpCalibration::computeCalibrationMulti()" << std::endl
496 <<
"with several images." << std::endl;
500 table_cal[0].calibLagrange(cam_est,table_cal[0].
cMo);
501 table_cal[0].cam = cam_est ;
502 table_cal[0].cam_dist = cam_est ;
503 table_cal[0].cMo_dist = table_cal[0].cMo ;
505 calibVVSMulti(table_cal, cam_est, globalReprojectionError, verbose);
510 calibVVSMulti(table_cal, cam_est, globalReprojectionError, verbose);
531 std::cout <<
"Compute camera parameters with distortion"<<std::endl;
533 calibVVSWithDistortionMulti(table_cal, cam_est, globalReprojectionError, verbose);
540 table_cal[0].cam.printParameters();
543 std::cout<<std::endl;
570 unsigned int nbPose = (
unsigned int)table_cal.size();
572 std::vector<vpHomogeneousMatrix> table_cMo(nbPose);
573 std::vector<vpHomogeneousMatrix> table_cMo_dist(nbPose);
574 std::vector<vpHomogeneousMatrix> table_rMe(nbPose);
576 for(
unsigned int i=0;i<nbPose;i++){
577 table_cMo[i] = table_cal[i].cMo;
578 table_cMo_dist[i] = table_cal[i].cMo_dist;
579 table_rMe[i] = table_cal[i].rMe;
587 vpERROR_TRACE(
"Three images are needed to compute Tsai calibration !\n");
606 std::ofstream f(filename) ;
609 std::list<double>::const_iterator it_LoX = LoX.begin();
610 std::list<double>::const_iterator it_LoY = LoY.begin();
611 std::list<double>::const_iterator it_LoZ = LoZ.begin();
612 std::list<vpImagePoint>::const_iterator it_Lip = Lip.begin();
615 f.setf(std::ios::fixed,std::ios::floatfield);
616 f << LoX.size() << std::endl ;
618 for (
unsigned int i =0 ; i < LoX.size() ; i++)
626 double u = ip.
get_u() ;
627 double v = ip.
get_v() ;
629 f << oX <<
" " << oY <<
" " << oZ <<
" " << u <<
" " << v <<std::endl ;
656 std::cout <<
"There are "<< n <<
" point on the calibration grid " << std::endl ;
663 for (
unsigned int i=0 ; i < n ; i++)
665 double x, y, z, u, v ;
666 f >> x >> y >> z >> u >> v ;
667 std::cout << x <<
" "<<y <<
" "<<z<<
" "<<u<<
" "<<v <<std::endl ;
697 std::list<double> &oX, std::list<double> &oY, std::list<double> &oZ,
bool verbose)
706 std::cout <<
"There are "<< n <<
" points on the calibration grid " << std::endl ;
718 for (
unsigned int i=0 ; i < n ; i++)
720 f >> no_pt >> x >> y >> z ;
722 std::cout << no_pt <<std::endl ;
723 std::cout << x <<
" "<< y <<
" "<< z <<std::endl ;
736 catch(...){
return -1;}
751 unsigned int thickness,
int subsampling_factor)
754 for (std::list<vpImagePoint>::const_iterator it = Lip.begin(); it != Lip.end(); ++ it) {
756 if (subsampling_factor > 1.) {
776 unsigned int thickness,
int subsampling_factor)
790 std::list<double>::const_iterator it_LoX = LoX.begin();
791 std::list<double>::const_iterator it_LoY = LoY.begin();
792 std::list<double>::const_iterator it_LoZ = LoZ.begin();
794 for (
unsigned int i =0 ; i < npt ; i++)
800 double cX = oX*
cMo[0][0]+oY*
cMo[0][1]+oZ*
cMo[0][2] +
cMo[0][3];
801 double cY = oX*cMo[1][0]+oY*cMo[1][1]+oZ*cMo[1][2] + cMo[1][3];
802 double cZ = oX*cMo[2][0]+oY*cMo[2][1]+oZ*cMo[2][2] + cMo[2][3];
814 cY = oX*cMo_dist[1][0]+oY*cMo_dist[1][1]+oZ*cMo_dist[1][2]+cMo_dist[1][3];
815 cZ = oX*cMo_dist[2][0]+oY*cMo_dist[2][1]+oZ*cMo_dist[2][2]+cMo_dist[2][3];
823 ip.
set_u( u0_dist + x*px_dist*r2 );
824 ip.set_v( v0_dist + y*py_dist*r2 );
838 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
862 for(
unsigned int i=0;i<nbPose;i++){
864 table_cal[i].computePose(cam_est,table_cal[i].
cMo);
869 std::cout <<
"this calibration method is not available in" << std::endl
870 <<
"vpCalibration::computeCalibrationMulti()" << std::endl;
874 table_cal[0].calibLagrange(cam_est,table_cal[0].
cMo);
875 table_cal[0].
cam = cam_est ;
884 std::cout <<
"this calibration method is not available in" << std::endl
885 <<
"vpCalibration::computeCalibrationMulti()" << std::endl
886 <<
"with several images." << std::endl;
890 table_cal[0].calibLagrange(cam_est,table_cal[0].
cMo);
891 table_cal[0].
cam = cam_est ;
895 calibVVSMulti(nbPose, table_cal, cam_est, verbose);
900 calibVVSMulti(nbPose, table_cal, cam_est, verbose);
921 std::cout <<
"Compute camera parameters with distortion"<<std::endl;
923 calibVVSWithDistortionMulti(nbPose, table_cal, cam_est, verbose);
933 std::cout<<std::endl;
970 for(
unsigned int i=0;i<nbPose;i++){
971 table_cMo[i] = table_cal[i].
cMo;
972 table_cMo_dist[i] = table_cal[i].
cMo_dist;
973 table_rMe[i] = table_cal[i].
rMe;
979 delete [] table_cMo_dist;
985 vpERROR_TRACE(
"Three images are needed to compute Tsai calibration !\n");
1023 std::cout <<
"There are "<< n <<
" points on the calibration grid " << std::endl ;
1034 for (
unsigned int i=0 ; i < n ; i++)
1036 f >> no_pt >> x >> y >> z ;
1038 std::cout << no_pt <<std::endl ;
1039 std::cout << x <<
" "<< y <<
" "<< z <<std::endl ;
1052 catch(...){
return -1;}
1056 #endif // VISP_BUILD_DEPRECATED_FUNCTIONS
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 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.
bool computePose(vpPoseMethodType methode, vpHomogeneousMatrix &cMo, bool(*func)(vpHomogeneousMatrix *)=NULL)
compute the pose for a given method
int displayGrid(vpImage< unsigned char > &I, vpColor color=vpColor::yellow, unsigned int thickness=1, int subsampling_factor=1)
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
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.
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)
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