From 1657cb028299eb5fea319fa6af12dcc277b944f5 Mon Sep 17 00:00:00 2001
From: Nicolas Pope <nwpope@utu.fi>
Date: Tue, 12 Mar 2019 11:25:25 +0200
Subject: [PATCH] Small fix for stereo video input reading bug

---
 cv-node/src/calibrate.cpp | 11 ++++-------
 cv-node/src/local.cpp     |  4 ++++
 cv-node/src/main.cpp      |  3 ++-
 3 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/cv-node/src/calibrate.cpp b/cv-node/src/calibrate.cpp
index a659e659f..16f71b403 100644
--- a/cv-node/src/calibrate.cpp
+++ b/cv-node/src/calibrate.cpp
@@ -191,7 +191,7 @@ Calibrate::Calibrate(ftl::LocalSource *s, const std::string &cal) : local_(s) {
 
 bool Calibrate::recalibrate() {
 	bool r = _recalibrate(0);
-	if (local_->isStereo()) r |= _recalibrate(1);
+	if (local_->isStereo()) r &= _recalibrate(1);
 	
 	if (r) calibrated_ = true;
 	
@@ -335,15 +335,12 @@ bool Calibrate::_recalibrate(size_t cam) {
         //! [output_undistorted]
         //------------------------------ Show image and check for input commands -------------------
         //! [await_input]
-        /*imshow("Image View", view);
-        char key = (char)waitKey(s.inputCapture.isOpened() ? 50 : s.delay);
+        imshow("Image View", view);
+        char key = (char)waitKey(settings_.delay);
 
-        if( key  == ESC_KEY )
+        if( key  == 27 )
             break;
 
-        if( key == 'u' && mode == CALIBRATED )
-           s.showUndistorsed = !s.showUndistorsed;*/
-
         /*if( s.inputCapture.isOpened() && key == 'g' )
         {
             mode = CAPTURING;
diff --git a/cv-node/src/local.cpp b/cv-node/src/local.cpp
index 1a4618210..677c07729 100644
--- a/cv-node/src/local.cpp
+++ b/cv-node/src/local.cpp
@@ -100,6 +100,10 @@ bool LocalSource::left(cv::Mat &l) {
 }
 
 bool LocalSource::right(cv::Mat &r) {
+	if (!camera_a_->grab()) {
+		LOG(ERROR) << "Unable to grab from camera A";
+		return false;
+	}
 	if (camera_b_ && !camera_b_->grab()) {
 		LOG(ERROR) << "Unable to grab from camera B";
 		return false;
diff --git a/cv-node/src/main.cpp b/cv-node/src/main.cpp
index b7d32c6d2..82961d6c2 100644
--- a/cv-node/src/main.cpp
+++ b/cv-node/src/main.cpp
@@ -79,6 +79,7 @@ int main(int argc, char **argv) {
 		Mat l, r;
 		
 		calibrate.undistort(l,r);
+		//lsrc->get(l,r);
 		
 		// Feed into sync buffer and network forward
 		sync->feed(LEFT, l,lsrc->getTimestamp());
@@ -96,7 +97,7 @@ int main(int argc, char **argv) {
 		cv::imshow("Left",l);
 		if (lsrc->isStereo()) cv::imshow("Right",r);
 		
-		if(cv::waitKey(1) == 27){
+		if(cv::waitKey(10000) == 27){
             //exit if ESC is pressed
             break;
         }
-- 
GitLab