Browse Source

Move from async to threading

pull/1/head
Tim Zeuner 2 years ago
parent
commit
3e7c057ae0
2 changed files with 17 additions and 12 deletions
  1. 9
    8
      lfr.cpp
  2. 8
    4
      lfr.h

+ 9
- 8
lfr.cpp View File

#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()


void LFR::loop() void LFR::loop()
{ {
//while(iAmLooping)
for(int i = 0; i < 3; i++)
namedWindow("Display window");
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";
return std::async(&LFR::loop, this);
this->loopThread=thread(&LFR::loop, this);
} }


void LFR::endLoop() void LFR::endLoop()
{ {
iAmLooping = false; iAmLooping = false;
std::cout<<"loop ende\n";
this->loopThread.join();
return; return;
} }

+ 8
- 4
lfr.h View File

#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;


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…
Cancel
Save