Move from async to threading
This commit is contained in:
parent
63745d0446
commit
3e7c057ae0
17
lfr.cpp
17
lfr.cpp
@ -1,9 +1,9 @@
|
|||||||
#include "lfr.h"
|
#include "lfr.h"
|
||||||
|
|
||||||
const int threshold_binary = 110;
|
const int threshold_binary = 110;
|
||||||
|
|
||||||
LFR::LFR() : iAmLooping(false), input(), processing(), controlModule(), interpreter(), intersectionHandler()
|
LFR::LFR() : iAmLooping(false), input(), processing(), controlModule(), interpreter(), intersectionHandler()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LFR::~LFR()
|
LFR::~LFR()
|
||||||
@ -16,26 +16,27 @@ LFR::~LFR()
|
|||||||
|
|
||||||
void LFR::loop()
|
void LFR::loop()
|
||||||
{
|
{
|
||||||
//while(iAmLooping)
|
namedWindow("Display window");
|
||||||
for(int i = 0; i < 3; i++)
|
while(iAmLooping)
|
||||||
{
|
{
|
||||||
Mat image = input.readWebcam();
|
Mat image = input.readWebcam();
|
||||||
processing.calculate_binaray(image, threshold_binary);
|
processing.calculate_binaray(image, threshold_binary);
|
||||||
imshow("Display window", image);
|
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;
|
iAmLooping = true;
|
||||||
std::cout<<"Loop start\n";
|
this->loopThread=thread(&LFR::loop, this);
|
||||||
return std::async(&LFR::loop, this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LFR::endLoop()
|
void LFR::endLoop()
|
||||||
{
|
{
|
||||||
iAmLooping = false;
|
iAmLooping = false;
|
||||||
std::cout<<"loop ende\n";
|
this->loopThread.join();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
10
lfr.h
10
lfr.h
@ -1,11 +1,15 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <future>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
#include <opencv2/opencv.hpp>
|
#include <opencv2/opencv.hpp>
|
||||||
|
|
||||||
#include <input.h>
|
#include <input.h>
|
||||||
#include <processing.h>
|
#include <processing.h>
|
||||||
#include <control_module.h>
|
#include <control_module.h>
|
||||||
#include <interpreter.h>
|
#include <interpreter.h>
|
||||||
#include <intersection_handler.h>
|
#include <intersection_handler.h>
|
||||||
#include <future>
|
|
||||||
|
|
||||||
using namespace cv;
|
using namespace cv;
|
||||||
|
|
||||||
@ -18,14 +22,14 @@ class LFR
|
|||||||
IntersectionHandler intersectionHandler;
|
IntersectionHandler intersectionHandler;
|
||||||
volatile bool iAmLooping;
|
volatile bool iAmLooping;
|
||||||
void loop();
|
void loop();
|
||||||
|
thread loopThread;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
LFR();
|
LFR();
|
||||||
~LFR();
|
~LFR();
|
||||||
|
|
||||||
std::future<void> startLoop();
|
void startLoop();
|
||||||
void endLoop();
|
void endLoop();
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
Loading…
x
Reference in New Issue
Block a user