@@ -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> |
@@ -17,7 +17,7 @@ int main(void) | |||
{ | |||
std::unique_lock<std::mutex> lock(mutex); | |||
std::cerr<<"camera exception:"<<ex.what()<<std::endl; | |||
return true; | |||
return false; | |||
}); | |||
//To calculate the frame rate | |||
@@ -30,7 +30,9 @@ int main(void) | |||
std::unique_lock<std::mutex> lock(mutex); | |||
if (!result.rawImage.empty()) | |||
{ | |||
cv::resize(result.rawImage, img, cv::Size(128, 64+32)); | |||
img = result.rawImage; | |||
//Resize to minimize latency using raspi over ssh | |||
//cv::resize(result.rawImage, img, cv::Size(128, 64+32)); | |||
//Calculate frame rate | |||
now = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()); | |||
@@ -46,7 +48,7 @@ int main(void) | |||
lfr.startLoop(); | |||
for(int finished = false; finished != 'q';){ | |||
finished = std::tolower(cv::waitKey(66)); | |||
finished = std::tolower(cv::waitKey(1)); | |||
std::unique_lock<std::mutex> lock(mutex); | |||
if(!img.empty()){ | |||
cv::imshow("frame", img); |
@@ -76,7 +76,11 @@ void LFR::createThread() | |||
} | |||
catch(std::exception const &ex) | |||
{ | |||
cb(ex); | |||
if(!cb(ex)) | |||
{ | |||
//callback returned false -> exception not handled -> exit | |||
exit(EXIT_FAILURE); | |||
} | |||
} | |||
//Invoke the callback method (ListenerPair second -> ListenerCallback) |