From 01f29ca9cd4ee46fd610ed9d295c7b8e75351cee Mon Sep 17 00:00:00 2001 From: Tim Zeuner Date: Wed, 30 Nov 2022 21:25:56 +0100 Subject: [PATCH] Choose between showing img and saving it --- AutonomousMode/autonomous_mode_main.cpp | 2 ++ AutonomousMode/lfr.cpp | 23 +++++++++++++++++------ AutonomousMode/lfr.h | 6 ++++++ 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/AutonomousMode/autonomous_mode_main.cpp b/AutonomousMode/autonomous_mode_main.cpp index e4256e7..fb17b25 100644 --- a/AutonomousMode/autonomous_mode_main.cpp +++ b/AutonomousMode/autonomous_mode_main.cpp @@ -15,6 +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.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 45b1058..dc6abd1 100644 --- a/AutonomousMode/lfr.cpp +++ b/AutonomousMode/lfr.cpp @@ -10,6 +10,10 @@ LFR::LFR(int videoHeight, int videoWidth, int thresholdBinary, int gaussKernelSi this->thresholdCanny1 = thresholdCanny1; this->thresholdCanny2 = thresholdCanny2; this->apertureSizeCanny = apertureSizeCanny; + + this->videoFlag = false; + this->saveOutputFlag = false; + this->outputFileName = ""; } LFR::~LFR() @@ -22,7 +26,7 @@ LFR::~LFR() void LFR::loop() { - namedWindow("Display window"); + if(this->videoFlag) {namedWindow("Display window");} while(iAmLooping) { Mat image = input.readWebcam(); @@ -32,11 +36,18 @@ void LFR::loop() { line( image, Point(lines[i][0], lines[i][1]), Point( lines[i][2], lines[i][3]), (0,0,255), 1, 8 ); - } - imshow("Display window", image); - char c = (char)waitKey(1); + } + if(this->videoFlag) + { + imshow("Display window", image); + char c = (char)waitKey(1); + } + if (this->saveOutputFlag && !(this->outputFileName.empty())) + { + imwrite(this->outputFileName, image); + } } - destroyWindow("Display window"); + if(this->videoFlag) {destroyWindow("Display window");} input.freeWebcam(); } @@ -51,4 +62,4 @@ void LFR::endLoop() iAmLooping = false; this->loopThread.join(); return; -} \ No newline at end of file +} diff --git a/AutonomousMode/lfr.h b/AutonomousMode/lfr.h index acbb0b5..c8ea635 100644 --- a/AutonomousMode/lfr.h +++ b/AutonomousMode/lfr.h @@ -39,5 +39,11 @@ public: void startLoop(); void endLoop(); + + + bool videoFlag; + bool saveOutputFlag; + + std::string outputFileName; }; \ No newline at end of file