From 3c1ef54b36a0b81ddff46f52ef236d0acb0efa8a Mon Sep 17 00:00:00 2001
From: Nicolas Pope <nwpope@utu.fi>
Date: Wed, 13 Mar 2019 09:32:54 +0200
Subject: [PATCH] Add delay between calibration frame capture

---
 cv-node/src/calibrate.cpp | 7 ++++---
 cv-node/src/main.cpp      | 2 +-
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/cv-node/src/calibrate.cpp b/cv-node/src/calibrate.cpp
index 0808fa00c..50df9d6c0 100644
--- a/cv-node/src/calibrate.cpp
+++ b/cv-node/src/calibrate.cpp
@@ -349,7 +349,7 @@ bool Calibrate::_recalibrate(vector<vector<Point2f>> *imagePoints,
     //Mat cameraMatrix, distCoeffs;
     //Size imageSize;
     int mode = CAPTURING;
-    clock_t prevTimestamp = 0;
+    double prevTimestamp = 0.0;
     const Scalar RED(0,0,255), GREEN(0,255,0);
     
     int chessBoardFlags = CALIB_CB_ADAPTIVE_THRESH | CALIB_CB_NORMALIZE_IMAGE;
@@ -405,8 +405,9 @@ bool Calibrate::_recalibrate(vector<vector<Point2f>> *imagePoints,
 		found1 = findChessboardCorners( view[0], settings_.boardSize, pointBuf[0], chessBoardFlags);
 		found2 = !local_->isStereo() || findChessboardCorners( view[1], settings_.boardSize, pointBuf[1], chessBoardFlags);
       
-        if (found1 && found2)                // If done with success,
+        if (found1 && found2 && local_->getTimestamp()-prevTimestamp > 0.5)                // If done with success,
         {
+			prevTimestamp = local_->getTimestamp();
               // improve the found corners' coordinate accuracy for chessboard
                     Mat viewGray;
                     cvtColor(view[0], viewGray, COLOR_BGR2GRAY);
@@ -431,7 +432,7 @@ bool Calibrate::_recalibrate(vector<vector<Point2f>> *imagePoints,
 
         imshow("Left", view[0]);
         if (local_->isStereo()) imshow("Right", view[1]);
-        char key = (char)waitKey(settings_.delay);
+        char key = (char)waitKey(50);
 
         if( key  == 27 )
             break;
diff --git a/cv-node/src/main.cpp b/cv-node/src/main.cpp
index fb535deec..026a5da7f 100644
--- a/cv-node/src/main.cpp
+++ b/cv-node/src/main.cpp
@@ -111,7 +111,7 @@ int main(int argc, char **argv) {
 		cv::imshow("Left",l);
 		if (lsrc->isStereo()) cv::imshow("Right",r);
 		
-		if(cv::waitKey(100) == 27){
+		if(cv::waitKey(20) == 27){
             //exit if ESC is pressed
             break;
         }
-- 
GitLab