properly quit the program

This commit is contained in:
ackimixs
2024-04-11 19:17:52 +02:00
parent 4f8f6d38b9
commit 70dda1c8d2
2 changed files with 4 additions and 24 deletions

View File

@@ -50,6 +50,7 @@ ArucoDetector::~ArucoDetector()
{
cam->stopVideo();
cv::destroyAllWindows();
delete cam;
}

View File

@@ -6,21 +6,14 @@
#include <atomic>
#include <optional>
std::atomic<bool> stopRequested(false);
void userInputThread() {
// Wait for the user to press Enter
std::cout << "Press Enter to stop the program..." << std::endl;
std::cin.ignore();
stopRequested = true;
}
int main(int argc, char *argv[])
{
// Settup argument parser
bool headless = false;
bool stopRequested = false;
for (int i = 0; i < argc; i++)
{
if (std::string(argv[i]) == "--help")
@@ -46,14 +39,6 @@ int main(int argc, char *argv[])
const std::string calibrationPath = argv[1];
// End argument parser
std::optional<std::thread> userInput;
if (headless)
{
userInput = std::thread(userInputThread);
}
ArucoDetector detector(calibrationPath, BLUE, headless);
auto whiteFlower = ArucoTag(36, "White_flower", 19.6, FLOWER);
@@ -109,17 +94,11 @@ int main(int argc, char *argv[])
}
}
if (stopRequested)
if (client.shouldStop() || stopRequested)
{
break;
}
}
// Wait for the user input thread to finish
if (userInput.has_value())
{
userInput.value().join();
}
return 0;
}