#include "lfr.h" LFR::LFR(int videoHeight, int videoWidth, int thresholdBinary, int gaussKernelSize, int thresholdCanny1, int thresholdCanny2, int apertureSizeCanny) : iAmLooping(false), input(videoHeight, videoWidth), processing(), controlModule(), interpreter(), intersectionHandler() { this->iAmLooping = false; this->thresholdBinary = thresholdBinary; this->gaussKernelSize = gaussKernelSize; this->thresholdCanny1 = thresholdCanny1; this->thresholdCanny2 = thresholdCanny2; this->apertureSizeCanny = apertureSizeCanny; this->videoFlag = false; this->saveOutputFlag = false; this->outputFileName = ""; } LFR::~LFR() { if(iAmLooping) { this->endLoop(); } } void LFR::loop() { if(this->videoFlag) {namedWindow("Display window");} while(iAmLooping) { Mat image = input.readWebcam(); processing.processImage(image, this->thresholdBinary, this->gaussKernelSize, this->thresholdCanny1, thresholdCanny2, this->apertureSizeCanny); std::vector lines = processing.calculateLineSegments(image); for( size_t i = 0; i < lines.size(); i++ ) { line( image, Point(lines[i][0], lines[i][1]), Point( lines[i][2], lines[i][3]), (0,0,255), 1, 8 ); } if(this->videoFlag) { imshow("Display window", image); char c = (char)waitKey(1); } if (this->saveOutputFlag && !(this->outputFileName.empty())) { imwrite(this->outputFileName, image); } } if(this->videoFlag) {destroyWindow("Display window");} input.freeWebcam(); } void LFR::startLoop() { iAmLooping = true; this->loopThread=thread(&LFR::loop, this); } void LFR::endLoop() { iAmLooping = false; this->loopThread.join(); return; }