exception handling

This commit is contained in:
2023-01-04 16:52:42 +01:00
parent 7fe6850da4
commit f55ebb6b3f
4 changed files with 23 additions and 12 deletions
+12 -8
View File
@@ -22,15 +22,17 @@ Mat Input::readFile(String filePath)
cv::glob(folder, filenames);
// Random shuffle
std::random_shuffle(filenames.begin(), filenames.end());
std::random_device rd;
std::mt19937 g(rd());
std::shuffle(filenames.begin(), filenames.end(), g);
Mat image = imread(filePath, IMREAD_COLOR);
if(image.empty())
{
std::cout << "Could not read the image: " << filePath << std::endl;
return Mat();
//To do:Exception handeling
stringstream sstream;
sstream << "Could not read the image: " << filePath << std::endl;
throw std::runtime_error(sstream.str());
}
resize(image, image, Size(this->videoWidth, this->videoHeight));
return image;
@@ -41,13 +43,15 @@ Mat Input::readWebcam()
Mat image;
if(!cap.isOpened()) {
cout << "Video capture not opened" << std::endl;
return Mat();
stringstream sstream;
sstream << "Video capture not opened" << std::endl;
throw std::runtime_error(sstream.str());
}
if(!cap.grab()) {
cout << "Could not grab frame from camera" << std::endl;
return Mat();
stringstream sstream;
sstream << "Could not grab frame from camera" << std::endl;
throw std::runtime_error(sstream.str());
}
cap.retrieve(image);
return image;
+1
View File
@@ -4,6 +4,7 @@
#include <vector>
#include <string>
#include <algorithm>
#include <random>
#include <opencv2/opencv.hpp>
#include <opencv2/core/utils/logger.hpp>