From 17a14d5b10140f9c5675eceac9dfbd9512ac2eaa Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Sun, 29 Jan 2023 01:34:35 +0000 Subject: [PATCH] t/cli: Add calib-dump command --- src/xrt/targets/cli/CMakeLists.txt | 5 ++ .../targets/cli/cli_cmd_calibration_dump.c | 48 +++++++++++++++++++ src/xrt/targets/cli/cli_common.h | 3 ++ src/xrt/targets/cli/cli_main.c | 6 ++- 4 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 src/xrt/targets/cli/cli_cmd_calibration_dump.c diff --git a/src/xrt/targets/cli/CMakeLists.txt b/src/xrt/targets/cli/CMakeLists.txt index b3679c35b..6527b5c5d 100644 --- a/src/xrt/targets/cli/CMakeLists.txt +++ b/src/xrt/targets/cli/CMakeLists.txt @@ -6,6 +6,7 @@ add_executable( cli + cli_cmd_calibration_dump.c cli_cmd_lighthouse.c cli_cmd_probe.c cli_cmd_slambatch.c @@ -20,6 +21,10 @@ if(NOT WIN32) target_sources(cli PRIVATE cli_cmd_calibrate.c) endif() +if(XRT_HAVE_OPENCV) + target_link_libraries(cli PRIVATE aux_tracking) +endif() + set_target_properties(cli PROPERTIES OUTPUT_NAME monado-cli PREFIX "") target_link_libraries( diff --git a/src/xrt/targets/cli/cli_cmd_calibration_dump.c b/src/xrt/targets/cli/cli_cmd_calibration_dump.c new file mode 100644 index 000000000..03bf50305 --- /dev/null +++ b/src/xrt/targets/cli/cli_cmd_calibration_dump.c @@ -0,0 +1,48 @@ +// Copyright 2019-2023, Collabora, Ltd. +// SPDX-License-Identifier: BSL-1.0 +/*! + * @file + * @brief Loads and dumps a calibration file. + * @author Jakob Bornecrantz + */ + +#include "xrt/xrt_compiler.h" +#include "xrt/xrt_config_have.h" + +#include "cli_common.h" + +#ifdef XRT_HAVE_OPENCV +#include "tracking/t_tracking.h" +#endif + +#include +#include + +#define P(...) fprintf(stderr, __VA_ARGS__) + +int +cli_cmd_calibration_dump(int argc, const char **argv) +{ +#ifdef XRT_HAVE_OPENCV + if (argc < 3) { + P("Must be given a file path\n"); + return 1; + } + + const char *filename = argv[2]; + + struct t_stereo_camera_calibration *data = NULL; + if (!t_stereo_camera_calibration_load(filename, &data)) { + P("Could not load '%s'!\n", filename); + return 1; + } + + t_stereo_camera_calibration_dump(data); + t_stereo_camera_calibration_reference(&data, NULL); + + return 0; +#else + P("Not compiled with XRT_HAVE_OPENCV, so can't load calibration files!\n"); + return 1; +#endif +} diff --git a/src/xrt/targets/cli/cli_common.h b/src/xrt/targets/cli/cli_common.h index 793d67108..47e2298d8 100644 --- a/src/xrt/targets/cli/cli_common.h +++ b/src/xrt/targets/cli/cli_common.h @@ -17,6 +17,9 @@ extern "C" { int cli_cmd_calibrate(int argc, const char **argv); +int +cli_cmd_calibration_dump(int argc, const char **argv); + int cli_cmd_lighthouse(int argc, const char **argv); diff --git a/src/xrt/targets/cli/cli_main.c b/src/xrt/targets/cli/cli_main.c index 2d5ad52e0..f6359c5a2 100644 --- a/src/xrt/targets/cli/cli_main.c +++ b/src/xrt/targets/cli/cli_main.c @@ -24,13 +24,14 @@ cli_print_help(int argc, const char **argv) } P("Monado-CLI 0.0.1\n"); - P("Usage: %s command [options]\n", argv[0]); + P("Usage: %s command [options] [file]\n", argv[0]); P("\n"); P("Commands:\n"); P(" test - List found devices, for prober testing.\n"); P(" probe - Just probe and then exit.\n"); P(" lighthouse - Control the power of lighthouses [on|off].\n"); P(" calibrate - Calibrate a camera and save config (not implemented yet).\n"); + P(" calib-dumb - Load and dump a calibration to stdout.\n"); P(" slambatch - Runs a sequence of EuRoC datasets with the SLAM tracker.\n"); return 1; @@ -54,6 +55,9 @@ main(int argc, const char **argv) return cli_cmd_calibrate(argc, argv); } #endif // !XRT_OS_WINDOWS + if (strcmp(argv[1], "calib-dump") == 0) { + return cli_cmd_calibration_dump(argc, argv); + } if (strcmp(argv[1], "lighthouse") == 0) { return cli_cmd_lighthouse(argc, argv); }