2022-10-30 17:03:37 +01:00
|
|
|
#include "input.h"
|
|
|
|
|
2022-11-10 21:08:35 +01:00
|
|
|
Input::Input(int videoHeight, int videoWidth) : cap(0), videoHeight(videoHeight), videoWidth(videoWidth)
|
2022-10-30 17:03:37 +01:00
|
|
|
{
|
2022-11-10 21:08:35 +01:00
|
|
|
this->cap.set(CAP_PROP_FRAME_HEIGHT, videoHeight);
|
|
|
|
this->cap.set(CAP_PROP_FRAME_WIDTH, videoWidth);
|
2022-10-30 17:03:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Input::~Input()
|
|
|
|
{
|
2022-11-10 14:40:28 +01:00
|
|
|
this->freeWebcam();
|
2022-10-30 17:03:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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());
|
|
|
|
|
2022-11-23 17:09:27 +01:00
|
|
|
Mat image = imread(filePath, IMREAD_COLOR);
|
2022-11-01 16:34:51 +01:00
|
|
|
|
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-16 11:08:53 +01:00
|
|
|
resize(image, image, Size(this->videoWidth, this->videoHeight));
|
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-10-31 00:58:41 +01:00
|
|
|
Mat image;
|
|
|
|
|
|
|
|
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-11-10 14:40:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Input::freeWebcam()
|
|
|
|
{
|
|
|
|
this->cap.release();
|
2022-10-30 17:03:37 +01:00
|
|
|
}
|