diff --git a/CMakeLists.txt b/CMakeLists.txt index a98a227..118ff77 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,8 @@ pkg_check_modules(LIBCAMERA REQUIRED libcamera) find_package(Modelec COMPONENTS TCPClient + Utils + CLParser REQUIRED ) @@ -50,7 +52,7 @@ add_executable(arucoDetector ${arucoDetectionSources}) target_link_libraries( arucoDetector -llccv ${OpenCV_LIBS} ) -target_link_libraries( arucoDetector Modelec::TCPClient ) +target_link_libraries( arucoDetector Modelec::TCPClient Modelec::CLParser Modelec::Utils ) set(photo ${COMMON_SOURCES} diff --git a/arucoDetector.cpp b/arucoDetector.cpp index 7dd6f38..5fb5008 100644 --- a/arucoDetector.cpp +++ b/arucoDetector.cpp @@ -1,6 +1,8 @@ #include "aruco/ArucoDetector.h" #include "tcp/MyClient.h" +#include + #include #include #include @@ -23,32 +25,32 @@ int main(int argc, char *argv[]) bool stopRequested = false; - for (int i = 0; i < argc; i++) - { - if (std::string(argv[i]) == "--help") - { - std::cout << "Usage: " << argv[0] << " " << std::endl; - std::cout << "video capture device: The ID of the video capture device to use. Usually 0 for the built-in camera." << std::endl; - std::cout << "path/to/calibration_results.yaml: The path to the calibration results file." << std::endl; - std::cout << "to run the program in headless mode, add the --headless flag." << std::endl; - return 0; - } + CLParser clParser(argc, argv); - if (std::string(argv[i]) == "--headless") - { - std::cout << "Running in headless mode." << std::endl; - headless = true; - } + if (clParser.hasOption("--help")) + { + std::cout << "Usage: " << argv[0] << " " << std::endl; + std::cout << "video capture device: The ID of the video capture device to use. Usually 0 for the built-in camera." << std::endl; + std::cout << "path/to/calibration_results.yaml: The path to the calibration results file." << std::endl; + std::cout << "to run the program in headless mode, add the --headless flag." << std::endl; + return 0; } - if (argc < 3) { + if (clParser.hasOption("headless")) { + std::cout << "Running in headless mode." << std::endl; + headless = true; + } + + int port = std::stoi(clParser.getOption("port", "8080")); + + std::optional calibrationPath = clParser.getOption("calib-file"); + + if (!calibrationPath.has_value()) { std::cout << "Usage: " << argv[0] << " " << std::endl; return 1; } - const std::string calibrationPath = argv[1]; - - ArucoDetector detector(calibrationPath, BLUE, headless); + ArucoDetector detector(calibrationPath.value(), BLUE, headless); auto whiteFlower = ArucoTag(36, "White_flower", 18.3, FLOWER); // whiteFlower.setFlowerObjectRepresentation(); @@ -59,8 +61,6 @@ int main(int argc, char *argv[]) int code; - int port = std::stoi(argv[2]); - MyClient client("127.0.0.1", port); client.start();