diff --git a/AutonomousMode/Input/input.cpp b/AutonomousMode/Input/input.cpp index fee41a1..7dd90cf 100644 --- a/AutonomousMode/Input/input.cpp +++ b/AutonomousMode/Input/input.cpp @@ -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; diff --git a/AutonomousMode/Input/input.h b/AutonomousMode/Input/input.h index c4accac..c87191a 100644 --- a/AutonomousMode/Input/input.h +++ b/AutonomousMode/Input/input.h @@ -4,6 +4,7 @@ #include #include #include +#include #include #include diff --git a/AutonomousMode/autonomous_mode_main.cpp b/AutonomousMode/autonomous_mode_main.cpp index dbd44a7..ca229bc 100644 --- a/AutonomousMode/autonomous_mode_main.cpp +++ b/AutonomousMode/autonomous_mode_main.cpp @@ -17,7 +17,7 @@ int main(void) { std::unique_lock lock(mutex); std::cerr<<"camera exception:"< 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::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 lock(mutex); if(!img.empty()){ cv::imshow("frame", img); diff --git a/AutonomousMode/lfr.cpp b/AutonomousMode/lfr.cpp index 28feaa6..d445464 100644 --- a/AutonomousMode/lfr.cpp +++ b/AutonomousMode/lfr.cpp @@ -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)