Move from async to threading

This commit is contained in:
Tim Zeuner 2022-11-10 14:41:27 +01:00
parent 63745d0446
commit 3e7c057ae0
2 changed files with 17 additions and 12 deletions

17
lfr.cpp
View File

@ -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<void> 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;
}

12
lfr.h
View File

@ -1,11 +1,15 @@
#include <iostream>
#include <future>
#include <thread>
#include <opencv2/opencv.hpp>
#include <input.h>
#include <processing.h>
#include <control_module.h>
#include <interpreter.h>
#include <intersection_handler.h>
#include <future>
using namespace cv;
@ -18,14 +22,14 @@ class LFR
IntersectionHandler intersectionHandler;
volatile bool iAmLooping;
void loop();
thread loopThread;
public:
LFR();
~LFR();
std::future<void> startLoop();
void startLoop();
void endLoop();
};