From 3e7c057ae0729521ec07435b48ff836b92df16e8 Mon Sep 17 00:00:00 2001 From: TimZnr Date: Thu, 10 Nov 2022 14:41:27 +0100 Subject: [PATCH] Move from async to threading --- lfr.cpp | 17 +++++++++-------- lfr.h | 12 ++++++++---- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/lfr.cpp b/lfr.cpp index 05ca96a..05d7b55 100644 --- a/lfr.cpp +++ b/lfr.cpp @@ -1,9 +1,9 @@ #include "lfr.h" + const int threshold_binary = 110; LFR::LFR() : iAmLooping(false), input(), processing(), controlModule(), interpreter(), intersectionHandler() { - } LFR::~LFR() @@ -16,26 +16,27 @@ LFR::~LFR() void LFR::loop() { - //while(iAmLooping) - for(int i = 0; i < 3; i++) + namedWindow("Display window"); + while(iAmLooping) { Mat image = input.readWebcam(); processing.calculate_binaray(image, threshold_binary); imshow("Display window", image); - waitKey(0); + char c = (char)waitKey(1); } + destroyWindow("Display window"); + input.freeWebcam(); } -std::future LFR::startLoop() +void LFR::startLoop() { iAmLooping = true; - std::cout<<"Loop start\n"; - return std::async(&LFR::loop, this); + this->loopThread=thread(&LFR::loop, this); } void LFR::endLoop() { iAmLooping = false; - std::cout<<"loop ende\n"; + this->loopThread.join(); return; } \ No newline at end of file diff --git a/lfr.h b/lfr.h index 0471bd1..9497024 100644 --- a/lfr.h +++ b/lfr.h @@ -1,11 +1,15 @@ #include +#include +#include + #include + #include #include #include #include #include -#include + using namespace cv; @@ -18,14 +22,14 @@ class LFR IntersectionHandler intersectionHandler; volatile bool iAmLooping; void loop(); + thread loopThread; public: LFR(); ~LFR(); - std::future startLoop(); + void startLoop(); void endLoop(); - - + }; \ No newline at end of file