exception handling
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
#include <random>
|
||||
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include <opencv2/core/utils/logger.hpp>
|
||||
|
||||
Reference in New Issue
Block a user