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(),
m_aspect_ratio(-1), npt(0), LoX(), LoY(), LoZ(),
76 Lip(), residual(1000.), residual_dist(1000.)
85 :
cMo(),
cMo_dist(),
cam(),
cam_dist(),
rMe(),
eMc(),
eMc_dist(),
m_aspect_ratio(-1), npt(0), LoX(), LoY(), LoZ(),
86 Lip(), residual(1000.), residual_dist(1000.)
103 npt = twinCalibration.npt;
104 LoX = twinCalibration.LoX;
105 LoY = twinCalibration.LoY;
106 LoZ = twinCalibration.LoZ;
107 Lip = twinCalibration.Lip;
109 residual = twinCalibration.residual;
110 cMo = twinCalibration.
cMo;
111 residual_dist = twinCalibration.residual_dist;
114 cam = twinCalibration.
cam;
117 rMe = twinCalibration.
rMe;
119 eMc = twinCalibration.
eMc;
173 std::list<double>::const_iterator it_LoX = LoX.begin();
174 std::list<double>::const_iterator it_LoY = LoY.begin();
175 std::list<double>::const_iterator it_LoZ = LoZ.begin();
176 std::list<vpImagePoint>::const_iterator it_Lip = Lip.begin();
178 for (
unsigned int i = 0; i < npt; i++) {
179 vpPoint P(*it_LoX, *it_LoY, *it_LoZ);
197 double residual_lagrange = std::numeric_limits<double>::max();
198 double residual_dementhon = std::numeric_limits<double>::max();
203 std::cout <<
"Pose from Lagrange exception: " << e.
getMessage() << std::endl;
213 std::cout <<
"Pose from Dementhon exception: " << e.
getMessage() << std::endl;
217 if (residual_lagrange < residual_dementhon)
218 cMo_est = cMo_lagrange;
220 cMo_est = cMo_dementhon;
236 double residual_ = 0;
238 std::list<double>::const_iterator it_LoX = LoX.begin();
239 std::list<double>::const_iterator it_LoY = LoY.begin();
240 std::list<double>::const_iterator it_LoZ = LoZ.begin();
241 std::list<vpImagePoint>::const_iterator it_Lip = Lip.begin();
243 double u0 = camera.
get_u0();
244 double v0 = camera.
get_v0();
245 double px = camera.
get_px();
246 double py = camera.
get_py();
249 for (
unsigned int i = 0; i < npt; i++) {
254 double cX = oX * cMo_est[0][0] + oY * cMo_est[0][1] + oZ * cMo_est[0][2] + cMo_est[0][3];
255 double cY = oX * cMo_est[1][0] + oY * cMo_est[1][1] + oZ * cMo_est[1][2] + cMo_est[1][3];
256 double cZ = oX * cMo_est[2][0] + oY * cMo_est[2][1] + oZ * cMo_est[2][2] + cMo_est[2][3];
262 double u = ip.
get_u();
263 double v = ip.
get_v();
265 double xp = u0 + x * px;
266 double yp = v0 + y * py;
275 this->residual = residual_;
276 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();
301 double inv_px = 1 / px;
302 double inv_py = 1 / px;
305 for (
unsigned int i = 0; i < npt; i++) {
310 double cX = oX * cMo_est[0][0] + oY * cMo_est[0][1] + oZ * cMo_est[0][2] + cMo_est[0][3];
311 double cY = oX * cMo_est[1][0] + oY * cMo_est[1][1] + oZ * cMo_est[1][2] + cMo_est[1][3];
312 double cZ = oX * cMo_est[2][0] + oY * cMo_est[2][1] + oZ * cMo_est[2][2] + cMo_est[2][3];
318 double u = ip.
get_u();
319 double v = ip.
get_v();
323 double xp = u0 + x * px * r2ud;
324 double yp = v0 + y * py * r2ud;
330 xp = u0 + x * px - kdu * (u - u0) * r2du;
331 yp = v0 + y * py - kdu * (v - v0) * r2du;
341 this->residual_dist = residual_;
342 return sqrt(residual_ / npt);
373 computePose(cam_est, cMo_est);
377 calibLagrange(cam_est, cMo_est);
392 std::cout <<
"start calibration without distortion" << std::endl;
394 calibVVS(cam_est, cMo_est, verbose);
416 std::cout <<
"start calibration with distortion" << std::endl;
418 calibVVSWithDistortion(cam_est, cMo_est, verbose);
442 std::cout <<
"Unable to calibrate the camera. Estimated parameters are negative." << std::endl;
471 unsigned int nbPose = (
unsigned int)table_cal.size();
472 for (
unsigned int i = 0; i < nbPose; i++) {
473 if (table_cal[i].
get_npt() > 3)
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;
483 table_cal[0].calibLagrange(cam_est, table_cal[0].
cMo);
484 table_cal[0].cam = cam_est;
485 table_cal[0].cam_dist = cam_est;
486 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;
498 table_cal[0].calibLagrange(cam_est, table_cal[0].
cMo);
499 table_cal[0].cam = cam_est;
500 table_cal[0].cam_dist = cam_est;
501 table_cal[0].cMo_dist = table_cal[0].cMo;
503 calibVVSMulti(table_cal, cam_est, globalReprojectionError, verbose, table_cal[0].
m_aspect_ratio);
508 calibVVSMulti(table_cal, cam_est, globalReprojectionError, verbose, table_cal[0].
m_aspect_ratio);
528 std::cout <<
"Compute camera parameters with distortion" << std::endl;
530 calibVVSWithDistortionMulti(table_cal, cam_est, globalReprojectionError, verbose, table_cal[0].
m_aspect_ratio);
537 table_cal[0].cam.printParameters();
540 std::cout << std::endl;
545 std::cout <<
"Unable to calibrate the camera. Estimated parameters are negative." << std::endl;
565 std::ofstream f(filename);
568 std::list<double>::const_iterator it_LoX = LoX.begin();
569 std::list<double>::const_iterator it_LoY = LoY.begin();
570 std::list<double>::const_iterator it_LoZ = LoZ.begin();
571 std::list<vpImagePoint>::const_iterator it_Lip = Lip.begin();
574 f.setf(std::ios::fixed, std::ios::floatfield);
575 f << LoX.size() << std::endl;
577 for (
unsigned int i = 0; i < LoX.size(); i++) {
584 double u = ip.
get_u();
585 double v = ip.
get_v();
587 f << oX <<
" " << oY <<
" " << oZ <<
" " << u <<
" " << v << std::endl;
613 std::cout <<
"There are " << n <<
" point on the calibration grid " << std::endl;
620 for (
unsigned int i = 0; i < n; i++) {
621 double x, y, z, u, v;
622 f >> x >> y >> z >> u >> v;
623 std::cout << x <<
" " << y <<
" " << z <<
" " << u <<
" " << v << std::endl;
652 std::list<double> &oZ,
bool verbose)
661 std::cout <<
"There are " << n <<
" points on the calibration grid " << std::endl;
673 for (
unsigned int i = 0; i < n; i++) {
674 f >> no_pt >> x >> y >> z;
676 std::cout << no_pt << std::endl;
677 std::cout << x <<
" " << y <<
" " << z << std::endl;
707 for (std::list<vpImagePoint>::const_iterator it = Lip.begin(); it != Lip.end(); ++it) {
709 if (subsampling_factor > 1.) {
742 std::list<double>::const_iterator it_LoX = LoX.begin();
743 std::list<double>::const_iterator it_LoY = LoY.begin();
744 std::list<double>::const_iterator it_LoZ = LoZ.begin();
746 for (
unsigned int i = 0; i < npt; i++) {
766 double cY = oX * cMo_dist[1][0] + oY * cMo_dist[1][1] + oZ * cMo_dist[1][2] + cMo_dist[1][3];
767 double cZ = oX * cMo_dist[2][0] + oY * cMo_dist[2][1] + oZ * cMo_dist[2][2] + cMo_dist[2][3];
775 ip.
set_u(u0_dist + x * px_dist * r2);
776 ip.set_v(v0_dist + y * py_dist * r2);
797 if (aspect_ratio > 0.) {
Used to indicate that a value is not in the allowed range.
bool computePose(vpPoseMethodType method, vpHomogeneousMatrix &cMo, bool(*func)(const vpHomogeneousMatrix &)=NULL)
double m_aspect_ratio
Fix aspect ratio (px/py)
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.
void setAspectRatio(double aspect_ratio)
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)
const char * getMessage() const
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
unsigned int get_npt() const
get the number of points
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.
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)
double computeResidual(const vpHomogeneousMatrix &cMo) const
Compute and return the sum of squared residuals expressed in meter^2 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)