2022-11-03 09:23:30 +01:00
|
|
|
#include "lfr.h"
|
2022-11-10 14:41:27 +01:00
|
|
|
|
2022-10-30 20:01:47 +01:00
|
|
|
|
2022-11-16 11:18:56 +01:00
|
|
|
LFR::LFR(int videoHeight, int videoWidth, int thresholdBinary, int gaussKernelSize, int thresholdCanny1, int thresholdCanny2, int apertureSizeCanny)
|
2022-11-30 22:50:50 +01:00
|
|
|
: iAmLooping(false), input(videoHeight, videoWidth), processing(), controlModule(), interpreter(), intersectionHandler(), roi()
|
2022-11-03 09:23:30 +01:00
|
|
|
{
|
2022-11-10 20:55:23 +01:00
|
|
|
this->iAmLooping = false;
|
2022-11-10 21:08:35 +01:00
|
|
|
this->thresholdBinary = thresholdBinary;
|
|
|
|
this->gaussKernelSize = gaussKernelSize;
|
2022-11-16 11:18:56 +01:00
|
|
|
this->thresholdCanny1 = thresholdCanny1;
|
|
|
|
this->thresholdCanny2 = thresholdCanny2;
|
|
|
|
this->apertureSizeCanny = apertureSizeCanny;
|
2022-11-30 21:25:56 +01:00
|
|
|
|
|
|
|
this->videoFlag = false;
|
|
|
|
this->saveOutputFlag = false;
|
|
|
|
this->outputFileName = "";
|
2022-11-30 22:50:50 +01:00
|
|
|
|
|
|
|
cv::Point roiOrigin(0, videoHeight*(7.5/12.0));
|
|
|
|
roi = Rect(roiOrigin.x, roiOrigin.y, videoWidth, videoHeight/12);
|
|
|
|
|
2022-11-03 09:23:30 +01:00
|
|
|
}
|
2022-11-01 16:34:51 +01:00
|
|
|
|
2022-11-03 09:23:30 +01:00
|
|
|
LFR::~LFR()
|
2022-10-30 20:01:47 +01:00
|
|
|
{
|
2022-11-03 11:18:18 +01:00
|
|
|
if(iAmLooping)
|
|
|
|
{
|
|
|
|
this->endLoop();
|
|
|
|
}
|
2022-11-03 09:23:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void LFR::loop()
|
|
|
|
{
|
2022-11-30 21:25:56 +01:00
|
|
|
if(this->videoFlag) {namedWindow("Display window");}
|
2022-11-10 14:41:27 +01:00
|
|
|
while(iAmLooping)
|
2022-11-03 09:23:30 +01:00
|
|
|
{
|
2022-11-30 22:50:50 +01:00
|
|
|
Mat originalImage = input.readWebcam();
|
|
|
|
Mat processedImage = originalImage;
|
|
|
|
processing.processImage(processedImage, this->thresholdBinary, this->gaussKernelSize, this->thresholdCanny1, thresholdCanny2, this->apertureSizeCanny);
|
|
|
|
FrameData data = processing.calculateLineSegments(processedImage, this->roi);
|
|
|
|
this->provideOutput(processedImage);
|
2022-11-03 09:23:30 +01:00
|
|
|
}
|
2022-11-30 21:25:56 +01:00
|
|
|
if(this->videoFlag) {destroyWindow("Display window");}
|
2022-11-10 14:41:27 +01:00
|
|
|
input.freeWebcam();
|
2022-11-03 09:23:30 +01:00
|
|
|
}
|
2022-11-03 08:54:35 +01:00
|
|
|
|
2022-11-10 14:41:27 +01:00
|
|
|
void LFR::startLoop()
|
2022-11-03 09:23:30 +01:00
|
|
|
{
|
2022-11-03 11:18:18 +01:00
|
|
|
iAmLooping = true;
|
2022-11-10 14:41:27 +01:00
|
|
|
this->loopThread=thread(&LFR::loop, this);
|
2022-11-03 09:23:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void LFR::endLoop()
|
|
|
|
{
|
2022-11-03 11:18:18 +01:00
|
|
|
iAmLooping = false;
|
2022-11-10 14:41:27 +01:00
|
|
|
this->loopThread.join();
|
2022-11-03 11:18:18 +01:00
|
|
|
return;
|
2022-11-30 21:25:56 +01:00
|
|
|
}
|
2022-11-30 22:50:50 +01:00
|
|
|
|
|
|
|
void LFR::provideOutput(const Mat& image)
|
|
|
|
{
|
|
|
|
if(this->videoFlag)
|
|
|
|
{
|
|
|
|
imshow("Display window", image);
|
|
|
|
char c = (char)waitKey(1);
|
|
|
|
}
|
|
|
|
if (this->saveOutputFlag && !(this->outputFileName.empty()))
|
|
|
|
{
|
|
|
|
imwrite(this->outputFileName, image);
|
|
|
|
}
|
|
|
|
}
|