From 44a266629fda86456b0c5f8e0499a2ce87d843d7 Mon Sep 17 00:00:00 2001 From: TimZnr Date: Wed, 7 Dec 2022 20:06:54 +0100 Subject: [PATCH] Show calculated boxes like tested in spielwiese --- AutonomousMode/autonomous_mode_main.cpp | 4 +-- AutonomousMode/lfr.cpp | 44 +++++++++++++++---------- AutonomousMode/lfr.h | 3 +- 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/AutonomousMode/autonomous_mode_main.cpp b/AutonomousMode/autonomous_mode_main.cpp index fb17b25..18f2f56 100644 --- a/AutonomousMode/autonomous_mode_main.cpp +++ b/AutonomousMode/autonomous_mode_main.cpp @@ -15,8 +15,8 @@ int main(void) const int apertureSizeCanny = 3; LFR lfr(videoHeight, videoWidth, thresholdBinary, gaussKernelSize, thresholdCanny1, thresholdCanny2, apertureSizeCanny); - lfr.saveOutputFlag = true; - lfr.outputFileName = "/home/pi/Line-Following-Robot/AutonomousMode/tmp/test.jpg"; + lfr.saveOutputFlag = false; + lfr.videoFlag = true; lfr.startLoop(); //To end the video stream, write any char in the console. char a; diff --git a/AutonomousMode/lfr.cpp b/AutonomousMode/lfr.cpp index ae95cf2..50da73f 100644 --- a/AutonomousMode/lfr.cpp +++ b/AutonomousMode/lfr.cpp @@ -2,7 +2,7 @@ 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() + : iAmLooping(false), input(videoHeight, videoWidth), processing(), controlModule(), interpreter(), intersectionHandler() { this->iAmLooping = false; this->thresholdBinary = thresholdBinary; @@ -14,10 +14,6 @@ LFR::LFR(int videoHeight, int videoWidth, int thresholdBinary, int gaussKernelSi 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() @@ -34,10 +30,14 @@ void LFR::loop() while(iAmLooping) { Mat originalImage = input.readWebcam(); - Mat processedImage = originalImage; + + Point roiOrigin(0, int(originalImage.rows*(7.5/12.0))); + Rect roi(roiOrigin.x, roiOrigin.y, originalImage.cols, originalImage.rows/12); + Mat processedImage = originalImage(roi); + processing.processImage(processedImage, this->thresholdBinary, this->gaussKernelSize, this->thresholdCanny1, thresholdCanny2, this->apertureSizeCanny); - FrameData data = processing.calculateLineSegments(processedImage, this->roi); - this->provideOutput(processedImage); + FrameData data = processing.calculateLineSegments(processedImage, roi); + this->provideOutput(originalImage, data, roi); } if(this->videoFlag) {destroyWindow("Display window");} input.freeWebcam(); @@ -56,15 +56,25 @@ void LFR::endLoop() return; } -void LFR::provideOutput(const Mat& image) +void LFR::provideOutput(Mat image, const FrameData& frameData, const Rect& roi) { + for(int i = 0; i < frameData.contours.size(); i++) + { + drawContours(image, frameData.contours, i, Scalar(0,255,255), 1, 8, noArray(), 0, Point(roi.x, roi.y)); + + rectangle(image, frameData.boundingBoxes[i], Scalar(0,255,0)); + Rect center(Point(frameData.middlePoints[i].x-2, frameData.middlePoints[i].y-2), Point(frameData.middlePoints[i].x+2, frameData.middlePoints[i].y+2)); + rectangle(image, center, Scalar(0,0,255)); + Rect leftRect(Point(frameData.leftEdges[i].x-2, frameData.leftEdges[i].y-2), Point(frameData.leftEdges[i].x+2, frameData.leftEdges[i].y+2)); + rectangle(image, leftRect, Scalar(0,0,255)); + } if(this->videoFlag) - { - imshow("Display window", image); - char c = (char)waitKey(1); - } - if (this->saveOutputFlag && !(this->outputFileName.empty())) - { - imwrite(this->outputFileName, image); - } + { + imshow("Display window", image); + char c = (char)waitKey(25); + } + if (this->saveOutputFlag && !(this->outputFileName.empty())) + { + imwrite(this->outputFileName, image); + } } diff --git a/AutonomousMode/lfr.h b/AutonomousMode/lfr.h index 76460ec..238b9e6 100644 --- a/AutonomousMode/lfr.h +++ b/AutonomousMode/lfr.h @@ -30,9 +30,8 @@ class LFR int thresholdCanny1; int thresholdCanny2; int apertureSizeCanny; - cv::Rect roi; - void provideOutput(const Mat& image); + void provideOutput(Mat image,const FrameData& frameData, const Rect& roi); public: