12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- #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(), roi()
- {
- 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 = "";
-
- cv::Point roiOrigin(0, videoHeight*(7.5/12.0));
- roi = Rect(roiOrigin.x, roiOrigin.y, videoWidth, videoHeight/12);
-
- }
-
- LFR::~LFR()
- {
- if(iAmLooping)
- {
- this->endLoop();
- }
- }
-
- void LFR::loop()
- {
- if(this->videoFlag) {namedWindow("Display window");}
- while(iAmLooping)
- {
- 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);
- }
- 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;
- }
-
- 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);
- }
- }
|