4 #include <visp3/core/vpIoTools.h> 5 #include <visp3/vision/vpHandEyeCalibration.h> 7 void usage(
const char *argv[],
int error)
9 std::cout <<
"Synopsis" << std::endl
10 <<
" " << argv[0] <<
" [--data-path <path>] [--help] [-h]" << std::endl << std::endl;
11 std::cout <<
"Description" << std::endl
12 <<
" --data-path <path> Path to the folder containing" << std::endl
13 <<
" pose_fPe_%d.yaml and pose_cPo_%d.yaml data files." << std::endl
14 <<
" Default: \"./\"" << std::endl << std::endl
15 <<
" --help, -h Print this helper message." << std::endl << std::endl;
17 std::cout <<
"Error" << std::endl
18 <<
" " <<
"Unsupported parameter " << argv[error] << std::endl;
22 int main(
int argc,
const char *argv[])
24 std::string data_path =
"./";
25 for (
int i = 1; i < argc; i++) {
26 if (std::string(argv[i]) ==
"--data-path" && i+1 < argc) {
27 data_path = std::string(argv[i+1]);
30 else if (std::string(argv[i]) ==
"--help" || std::string(argv[i]) ==
"-h") {
40 std::vector<vpHomogeneousMatrix> cMo;
41 std::vector<vpHomogeneousMatrix> wMe;
44 std::map<long, std::string> map_fPe_files;
45 std::map<long, std::string> map_cPo_files;
47 for (
unsigned int i = 0; i < files.size(); i++) {
50 if (index_fPe != -1) {
51 map_fPe_files[index_fPe] = files[i];
53 if (index_cPo != -1) {
54 map_cPo_files[index_cPo] = files[i];
58 if (map_fPe_files.size() == 0) {
59 std::cout <<
"No pose_fPe_%d.yaml files found. Use --data-path <path> option to modify data path." << std::endl;
62 if (map_cPo_files.size() == 0) {
63 std::cout <<
"No pose_cPo_%d.yaml files found. Use --data-path <path> option to modify data path." << std::endl;
67 for (std::map<long, std::string>::const_iterator it_fPe = map_fPe_files.begin(); it_fPe != map_fPe_files.end(); ++ it_fPe) {
68 std::string file_fPe = it_fPe->second;
69 std::map<long, std::string>::const_iterator it_cPo = map_cPo_files.find(it_fPe->first);
70 if (it_cPo != map_cPo_files.end()) {
71 std::string file_cPo = it_cPo->second;
73 if (wPe.
loadYAML(file_fPe, wPe) ==
false) {
74 std::cout <<
"Unable to read data from " << data_path <<
"/" << file_fPe <<
". Skip data" << std::endl;
79 if (cPo.
loadYAML(file_cPo, cPo) ==
false) {
80 std::cout <<
"Unable to read data from " << data_path <<
"/" << file_cPo <<
". Skip data" << std::endl;
83 std::cout <<
"Use data from " << data_path <<
"/" << file_fPe <<
" and from " << data_path <<
"/" << file_cPo << std::endl;
90 std::cout <<
"Not enough data pairs found." << std::endl;
97 std::cout << std::endl <<
"** Hand-eye calibration succeed" << std::endl;
98 std::cout << std::endl <<
"** Hand-eye (eMc) transformation estimated:" << std::endl;
99 std::cout << eMc << std::endl;
100 std::cout <<
"** Corresponding pose vector: " <<
vpPoseVector(eMc).
t() << std::endl;
103 std::cout << std::endl <<
"** Translation [m]: " << eMc[0][3] <<
" " << eMc[1][3] <<
" " << eMc[2][3] << std::endl;
104 std::cout <<
"** Rotation (theta-u representation) [rad]: " << erc.t() << std::endl;
107 std::cout <<
"** Rotation (quaternion representation) [rad]: " << quaternion.
t() << std::endl;
110 std::ofstream file_eMc(
"eMc.txt");
114 std::string output_filename(
"eMc.yaml");
115 std::cout << std::endl <<
"Save transformation matrix eMc as a vpPoseVector in " << output_filename << std::endl;
116 pose_vec.saveYAML(output_filename, pose_vec);
119 std::cout << std::endl <<
"** Hand-eye calibration failed" << std::endl;
120 std::cout << std::endl <<
"Check your input data and ensure they are covering the half sphere over the chessboard." << std::endl;
121 std::cout << std::endl <<
"See https://visp-doc.inria.fr/doxygen/visp-daily/tutorial-calibration-extrinsic.html" << std::endl;
static bool loadYAML(const std::string &filename, vpArray2D< Type > &A, char *header=NULL)
Implementation of an homogeneous matrix and operations on such kind of matrices.
static int calibrate(const std::vector< vpHomogeneousMatrix > &cMo, const std::vector< vpHomogeneousMatrix > &rMe, vpHomogeneousMatrix &eMc)
Implementation of a rotation vector as quaternion angle minimal representation.
static double deg(double rad)
Implementation of a pose vector and operations on poses.
void save(std::ofstream &f) const
Implementation of a rotation vector as axis-angle minimal representation.
vpRotationMatrix getRotationMatrix() const