#include "input.h" Input::Input(int video_height, int video_width) : cap(0), video_height(video_height), video_width(video_width) { this->cap.set(CAP_PROP_FRAME_HEIGHT, video_height); this->cap.set(CAP_PROP_FRAME_WIDTH, video_width); } Input::~Input() { this->freeWebcam(); } Mat Input::readFile(String filePath) { std::srand(std::time(0)); // Read all .jpg files from the specified folder std::string folder = filePath; std::vector filenames; cv::glob(folder, filenames); // Random shuffle std::random_shuffle(filenames.begin(), filenames.end()); Mat image = imread(filenames[0], IMREAD_COLOR); if(image.empty()) { std::cout << "Could not read the image: " << filePath << std::endl; return Mat(); //To do:Exception handeling } return image; } Mat Input::readWebcam() { Mat image; if(!cap.isOpened()) { cout << "Fehler"; return Mat(); } cap.read(image); return image; } void Input::freeWebcam() { this->cap.release(); }