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);
194 double residual_lagrange = std::numeric_limits<double>::max();
195 double residual_dementhon = std::numeric_limits<double>::max();
201 std::cout <<
"Pose from Lagrange exception: " << e.
getMessage() << std::endl;
212 std::cout <<
"Pose from Dementhon exception: " << e.
getMessage() << std::endl;
216 if (residual_lagrange < residual_dementhon)
217 cMo_est = cMo_lagrange;
219 cMo_est = cMo_dementhon;
235 double residual_ = 0;
237 std::list<double>::const_iterator it_LoX = LoX.begin();
238 std::list<double>::const_iterator it_LoY = LoY.begin();
239 std::list<double>::const_iterator it_LoZ = LoZ.begin();
240 std::list<vpImagePoint>::const_iterator it_Lip = Lip.begin();
242 double u0 = camera.
get_u0();
243 double v0 = camera.
get_v0();
244 double px = camera.
get_px();
245 double py = camera.
get_py();
248 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);
286 double residual_ = 0;
288 std::list<double>::const_iterator it_LoX = LoX.begin();
289 std::list<double>::const_iterator it_LoY = LoY.begin();
290 std::list<double>::const_iterator it_LoZ = LoZ.begin();
291 std::list<vpImagePoint>::const_iterator it_Lip = Lip.begin();
293 double u0 = camera.
get_u0();
294 double v0 = camera.
get_v0();
295 double px = camera.
get_px();
296 double py = camera.
get_py();
300 double inv_px = 1 / px;
301 double inv_py = 1 / px;
304 for (
unsigned int i = 0; i < npt; i++) {
309 double cX = oX * cMo_est[0][0] + oY * cMo_est[0][1] + oZ * cMo_est[0][2] + cMo_est[0][3];
310 double cY = oX * cMo_est[1][0] + oY * cMo_est[1][1] + oZ * cMo_est[1][2] + cMo_est[1][3];
311 double cZ = oX * cMo_est[2][0] + oY * cMo_est[2][1] + oZ * cMo_est[2][2] + cMo_est[2][3];
317 double u = ip.
get_u();
318 double v = ip.
get_v();
322 double xp = u0 + x * px * r2ud;
323 double yp = v0 + y * py * r2ud;
329 xp = u0 + x * px - kdu * (u - u0) * r2du;
330 yp = v0 + y * py - kdu * (v - v0) * r2du;
340 this->residual_dist = residual_;
341 return sqrt(residual_ / npt);
372 computePose(cam_est, cMo_est);
376 calibLagrange(cam_est, cMo_est);
391 std::cout <<
"start calibration without distortion" << std::endl;
393 calibVVS(cam_est, cMo_est, verbose);
415 std::cout <<
"start calibration with distortion" << std::endl;
417 calibVVSWithDistortion(cam_est, cMo_est, verbose);
441 std::cout <<
"Unable to calibrate the camera. Estimated parameters are negative." << std::endl;
470 unsigned int nbPose = (
unsigned int)table_cal.size();
471 for (
unsigned int i = 0; i < nbPose; i++) {
472 if (table_cal[i].
get_npt() > 3)
473 table_cal[i].computePose(cam_est, table_cal[i].
cMo);
478 std::cout <<
"this calibration method is not available in" << std::endl
479 <<
"vpCalibration::computeCalibrationMulti()" << std::endl;
482 table_cal[0].calibLagrange(cam_est, table_cal[0].
cMo);
483 table_cal[0].cam = cam_est;
484 table_cal[0].cam_dist = cam_est;
485 table_cal[0].cMo_dist = table_cal[0].cMo;
492 std::cout <<
"this calibration method is not available in" << std::endl
493 <<
"vpCalibration::computeCalibrationMulti()" << std::endl
494 <<
"with several images." << std::endl;
497 table_cal[0].calibLagrange(cam_est, table_cal[0].
cMo);
498 table_cal[0].cam = cam_est;
499 table_cal[0].cam_dist = cam_est;
500 table_cal[0].cMo_dist = table_cal[0].cMo;
502 calibVVSMulti(table_cal, cam_est, globalReprojectionError, verbose);
507 calibVVSMulti(table_cal, cam_est, globalReprojectionError, verbose);
527 std::cout <<
"Compute camera parameters with distortion" << std::endl;
529 calibVVSWithDistortionMulti(table_cal, cam_est, globalReprojectionError, verbose);
536 table_cal[0].cam.printParameters();
539 std::cout << std::endl;
544 std::cout <<
"Unable to calibrate the camera. Estimated parameters are negative." << std::endl;
564 std::ofstream f(filename);
567 std::list<double>::const_iterator it_LoX = LoX.begin();
568 std::list<double>::const_iterator it_LoY = LoY.begin();
569 std::list<double>::const_iterator it_LoZ = LoZ.begin();
570 std::list<vpImagePoint>::const_iterator it_Lip = Lip.begin();
573 f.setf(std::ios::fixed, std::ios::floatfield);
574 f << LoX.size() << std::endl;
576 for (
unsigned int i = 0; i < LoX.size(); i++) {
583 double u = ip.
get_u();
584 double v = ip.
get_v();
586 f << oX <<
" " << oY <<
" " << oZ <<
" " << u <<
" " << v << std::endl;
612 std::cout <<
"There are " << n <<
" point on the calibration grid " << std::endl;
619 for (
unsigned int i = 0; i < n; i++) {
620 double x, y, z, u, v;
621 f >> x >> y >> z >> u >> v;
622 std::cout << x <<
" " << y <<
" " << z <<
" " << u <<
" " << v << std::endl;
651 std::list<double> &oZ,
bool verbose)
660 std::cout <<
"There are " << n <<
" points on the calibration grid " << std::endl;
672 for (
unsigned int i = 0; i < n; i++) {
673 f >> no_pt >> x >> y >> z;
675 std::cout << no_pt << std::endl;
676 std::cout << x <<
" " << y <<
" " << z << std::endl;
706 for (std::list<vpImagePoint>::const_iterator it = Lip.begin(); it != Lip.end(); ++it) {
708 if (subsampling_factor > 1.) {
741 std::list<double>::const_iterator it_LoX = LoX.begin();
742 std::list<double>::const_iterator it_LoY = LoY.begin();
743 std::list<double>::const_iterator it_LoZ = LoZ.begin();
745 for (
unsigned int i = 0; i < npt; i++) {
765 double cY = oX * cMo_dist[1][0] + oY * cMo_dist[1][1] + oZ * cMo_dist[1][2] + cMo_dist[1][3];
766 double cZ = oX * cMo_dist[2][0] + oY * cMo_dist[2][1] + oZ * cMo_dist[2][2] + cMo_dist[2][3];
774 ip.
set_u(u0_dist + x * px_dist * r2);
775 ip.set_v(v0_dist + y * py_dist * r2);
Used to indicate that a value is not in the allowed range.
bool computePose(vpPoseMethodType method, vpHomogeneousMatrix &cMo, bool(*func)(const vpHomogeneousMatrix &)=NULL)
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 RGB 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)
Tools for perspective camera calibration.
vpHomogeneousMatrix cMo
(as a 3x4 matrix [R T])
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
void set_x(double x)
Set the point x coordinate in the image plane.
void set_y(double y)
Set the point y coordinate in the image plane.
vpCalibration & operator=(const vpCalibration &twinCalibration)
int clearPoint()
Suppress all the point in the array of point.
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
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
Position of the camera in end-effector frame using camera parameters with distorsion.
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 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 end-effector frame using camera parameters without distorsion.
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)
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)
const char * getMessage() const
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 sum of squared residuals expressed in meter^2 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)