From 55a9cd7f8795a45ccf24310372daa39d4263599b Mon Sep 17 00:00:00 2001 From: Florent Lamiraux Date: Thu, 28 Sep 2023 09:41:35 +0200 Subject: [PATCH] [tutorial/calibration] Add option to make executable non interactive in tutorial-chessboard-pose. Install programs tutorial-chessboard-pose and tutorial-hand-eye-calibration and rename them "tutorial-" -> "compute-". --- tutorial/calibration/CMakeLists.txt | 12 ++++ .../calibration/tutorial-chessboard-pose.cpp | 59 +++++++++++++------ 2 files changed, 54 insertions(+), 17 deletions(-) diff --git a/tutorial/calibration/CMakeLists.txt b/tutorial/calibration/CMakeLists.txt index 61f0e08016..5005fafe93 100644 --- a/tutorial/calibration/CMakeLists.txt +++ b/tutorial/calibration/CMakeLists.txt @@ -20,6 +20,18 @@ foreach(cpp ${tutorial_cpp}) endif() endforeach() +install(PROGRAMS + ${CMAKE_CURRENT_BINARY_DIR}/tutorial-chessboard-pose + DESTINATION bin + RENAME compute-chessboard-poses + ) + +install(PROGRAMS + ${CMAKE_CURRENT_BINARY_DIR}/tutorial-hand-eye-calibration + DESTINATION bin + RENAME compute-hand-eye-calibration + ) + if(VISP_HAVE_REALSENSE2) # Add specific build flag to turn off warnings coming from librealsense 3rd party and its dependencies list(APPEND CXX_FLAGS_MUTE_WARNINGS "/wd4244") diff --git a/tutorial/calibration/tutorial-chessboard-pose.cpp b/tutorial/calibration/tutorial-chessboard-pose.cpp index 35e65de975..cdeb7df04b 100644 --- a/tutorial/calibration/tutorial-chessboard-pose.cpp +++ b/tutorial/calibration/tutorial-chessboard-pose.cpp @@ -73,6 +73,8 @@ void usage(const char **argv, int error) << std::endl << " Example: \"pose_cPo_%d.yaml\"." << std::endl << std::endl + << " --no_interactive To compute the chessboard poses without interactive validation by the user." + << std::endl << " --help, -h Print this helper message." << std::endl << std::endl; if (error) { @@ -91,6 +93,7 @@ int main(int argc, const char **argv) std::string opt_intrinsic_file = "camera.xml"; std::string opt_camera_name = "Camera"; std::string opt_output_pose_files = "pose_cPo_%d.yaml"; + bool interactive = true; for (int i = 1; i < argc; i++) { if (std::string(argv[i]) == "-w" && i + 1 < argc) { @@ -121,6 +124,9 @@ int main(int argc, const char **argv) opt_camera_name = std::string(argv[i + 1]); i++; } + else if (std::string(argv[i]) == "--no_interactive") { + interactive = false; + } else if (std::string(argv[i]) == "--help" || std::string(argv[i]) == "-h") { usage(argv, 0); return EXIT_SUCCESS; @@ -159,12 +165,22 @@ int main(int argc, const char **argv) reader.open(I); #ifdef VISP_HAVE_X11 - vpDisplayX d(I); + vpDisplayX* d; +#elif defined(VISP_HAVE_GDI) + vpDisplayGDI* d; +#elif defined(HAVE_OPENCV_HIGHGUI) + vpDisplayOpenCV* d=0x0; +#endif + + if (interactive) { +#ifdef VISP_HAVE_X11 + d = new vpDisplayX(I); #elif defined(VISP_HAVE_GDI) - vpDisplayGDI d(I); + d = new vpDisplayGDI(I); #elif defined(HAVE_OPENCV_HIGHGUI) - vpDisplayOpenCV d(I); + d = new vpDisplayOpenCV(I); #endif + } std::vector corners_pts; calcChessboardCorners(opt_chessboard_width, opt_chessboard_height, opt_chessboard_square_size, corners_pts); @@ -239,13 +255,15 @@ int main(int argc, const char **argv) vpImageConvert::convert(matImg, I); } - vpDisplay::display(I); + if (interactive) { + vpDisplay::display(I); - vpDisplay::displayText(I, 20, 20, "Left click for the next image, right click to quit.", vpColor::red); - if (found) - vpDisplay::displayFrame(I, cMo, cam, 0.05, vpColor::none, 3); + vpDisplay::displayText(I, 20, 20, "Left click for the next image, right click to quit.", vpColor::red); + if (found) + vpDisplay::displayFrame(I, cMo, cam, 0.05, vpColor::none, 3); - vpDisplay::flush(I); + vpDisplay::flush(I); + } if (found) { vpPoseVector pose_vec(cMo); @@ -256,18 +274,25 @@ int main(int argc, const char **argv) pose_vec.saveYAML(s, pose_vec); } - vpMouseButton::vpMouseButtonType button; - if (vpDisplay::getClick(I, button, true)) { - switch (button) { - case vpMouseButton::button3: - quit = true; - break; - - default: + if (interactive) { + vpMouseButton::vpMouseButtonType button; + if (vpDisplay::getClick(I, button, true)) { + switch (button) { + case vpMouseButton::button3: + quit = true; + break; + + default: + break; + } + } else { break; } } - } while (!quit && !reader.end()); + } while (!quit && !reader.end()); + if (interactive){ + if (d) delete d; + } } catch (const vpException &e) { std::cout << "Catch an exception: " << e.getMessage() << std::endl;