From 63745d0446ea886cf4457a1a9e4354e5db513060 Mon Sep 17 00:00:00 2001 From: TimZnr Date: Thu, 10 Nov 2022 14:40:28 +0100 Subject: [PATCH] Shift VideoCapture stuff to Input class instead of readWebcam method; Add freeWebcam method --- Input/input.cpp | 19 ++++++++++++------- Input/input.h | 4 ++++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Input/input.cpp b/Input/input.cpp index 9e1001f..890c40a 100644 --- a/Input/input.cpp +++ b/Input/input.cpp @@ -1,11 +1,17 @@ #include "input.h" -Input::Input(/* args */) +Input::Input(/* args */) : cap(0) { + const int VID_HEIGHT = 240; + const int VID_WIDTH = 320; + + this->cap.set(CAP_PROP_FRAME_HEIGHT, VID_HEIGHT); + this->cap.set(CAP_PROP_FRAME_WIDTH, VID_WIDTH); } Input::~Input() { + this->freeWebcam(); } Mat Input::readFile(String filePath) @@ -33,13 +39,7 @@ Mat Input::readFile(String filePath) Mat Input::readWebcam() { - const int VID_HEIGHT = 240; - const int VID_WIDTH = 320; Mat image; - VideoCapture cap(0); - - cap.set(CAP_PROP_FRAME_HEIGHT, VID_HEIGHT); - cap.set(CAP_PROP_FRAME_WIDTH, VID_WIDTH); if(!cap.isOpened()) { cout << "Fehler"; @@ -49,4 +49,9 @@ Mat Input::readWebcam() cap.read(image); return image; +} + +void Input::freeWebcam() +{ + this->cap.release(); } \ No newline at end of file diff --git a/Input/input.h b/Input/input.h index 888ba60..b035858 100644 --- a/Input/input.h +++ b/Input/input.h @@ -2,7 +2,9 @@ #include #include #include + #include +#include using namespace std; using namespace cv; @@ -10,10 +12,12 @@ using namespace cv; class Input { private: + VideoCapture cap; public: Input(/* args */); ~Input(); Mat readFile(String filePath); Mat readWebcam(); + void freeWebcam(); }; \ No newline at end of file