2022-10-30 17:03:37 +01:00
|
|
|
#include "input.h"
|
|
|
|
|
|
|
|
Input::Input(/* args */)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Input::~Input()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Mat Input::readFile(String filePath)
|
|
|
|
{
|
2022-11-01 16:34:51 +01:00
|
|
|
std::srand(std::time(0));
|
|
|
|
// Read all .jpg files from the specified folder
|
|
|
|
std::string folder = filePath;
|
|
|
|
std::vector<std::string> filenames;
|
|
|
|
cv::glob(folder, filenames);
|
|
|
|
|
|
|
|
// Random shuffle
|
|
|
|
std::random_shuffle(filenames.begin(), filenames.end());
|
|
|
|
|
|
|
|
Mat image = imread(filenames[0], IMREAD_COLOR);
|
|
|
|
|
2022-10-30 17:03:37 +01:00
|
|
|
if(image.empty())
|
|
|
|
{
|
|
|
|
std::cout << "Could not read the image: " << filePath << std::endl;
|
|
|
|
return Mat();
|
|
|
|
//To do:Exception handeling
|
|
|
|
}
|
2022-11-01 16:34:51 +01:00
|
|
|
|
2022-10-30 17:03:37 +01:00
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
2022-10-31 00:58:41 +01:00
|
|
|
Mat Input::readWebcam()
|
2022-10-30 17:03:37 +01:00
|
|
|
{
|
2022-11-01 14:18:02 +01:00
|
|
|
const int VID_HEIGHT = 240;
|
|
|
|
const int VID_WIDTH = 320;
|
2022-10-31 00:58:41 +01:00
|
|
|
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";
|
|
|
|
return Mat();
|
|
|
|
}
|
|
|
|
|
|
|
|
cap.read(image);
|
2022-11-01 16:34:51 +01:00
|
|
|
|
2022-10-31 00:58:41 +01:00
|
|
|
return image;
|
2022-10-30 17:03:37 +01:00
|
|
|
}
|