From 63bff2eb1b5d831dca98959a1e7bbf90a688bcd8 Mon Sep 17 00:00:00 2001
From: Nicolas Pope <nwpope@utu.fi>
Date: Wed, 10 Apr 2019 10:32:29 +0300
Subject: [PATCH] Again fix cmake for windows. Add disparity flip option and
 rgb display.

---
 CMakeLists.txt                |  4 ++--
 cmake/Findglog.cmake          |  1 +
 cv-node/config/config.json    |  3 ++-
 cv-node/include/ftl/local.hpp |  1 +
 cv-node/src/display.cpp       | 12 +++++++++++-
 cv-node/src/local.cpp         | 12 +++++++++++-
 6 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 969acb22d..ac657f104 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -13,8 +13,8 @@ enable_testing()
 set(THREADS_PREFER_PTHREAD_FLAG ON)
 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
 
-#include(Findglog)
-find_package( glog REQUIRED )
+include(Findglog)
+#find_package( glog REQUIRED )
 find_package( OpenCV REQUIRED )
 find_package( Threads REQUIRED )
 find_package( URIParser REQUIRED )
diff --git a/cmake/Findglog.cmake b/cmake/Findglog.cmake
index 9079190dc..6b07e3ba4 100644
--- a/cmake/Findglog.cmake
+++ b/cmake/Findglog.cmake
@@ -9,6 +9,7 @@ set(glog_DIR ${glog_DIR})
 find_package(glog QUIET PATHS "${glog_DIR}/lib/cmake" NO_DEFAULT_PATH)
 
 if (GLOG_FOUND)
+message(STATUS "Found installed glog")
 return()
 endif()
 
diff --git a/cv-node/config/config.json b/cv-node/config/config.json
index a0bf49e50..1979288d6 100644
--- a/cv-node/config/config.json
+++ b/cv-node/config/config.json
@@ -7,7 +7,8 @@
 	"source": {
 		"flip": false,
 		"nostereo": false,
-		"scale": 1.0
+		"scale": 1.0,
+		"flip_vert": false
 	},
 	"calibrate": false,
 	"calibration": {
diff --git a/cv-node/include/ftl/local.hpp b/cv-node/include/ftl/local.hpp
index f4c98f357..cf18b9928 100644
--- a/cv-node/include/ftl/local.hpp
+++ b/cv-node/include/ftl/local.hpp
@@ -31,6 +31,7 @@ class LocalSource {
 	bool stereo_;
 	//float fps_;
 	bool flip_;
+	bool flip_v_;
 	bool nostereo_;
 	float downsize_;
 	cv::VideoCapture *camera_a_;
diff --git a/cv-node/src/display.cpp b/cv-node/src/display.cpp
index 4889b8026..52a8a39fa 100644
--- a/cv-node/src/display.cpp
+++ b/cv-node/src/display.cpp
@@ -54,6 +54,10 @@ bool Display::render(const cv::Mat &rgb, const cv::Mat &depth) {
 		#endif  // HAVE_VIZ
 	}
 
+	if (config_["left"]) {
+		cv::imshow("RGB", rgb);
+	}
+
 	if (config_["depth"]) {
 		/*Mat depth32F = (focal * (float)l.cols * base_line) / depth;
 		normalize(depth32F, depth32F, 0, 255, NORM_MINMAX, CV_8U);
@@ -63,7 +67,13 @@ bool Display::render(const cv::Mat &rgb, const cv::Mat &depth) {
 	       	active_ = false;
 	    }*/
     } else if (config_["disparity"]) {
-    	depth.convertTo(idepth, CV_8U, 255.0f / 208.0f);  // TODO(nick)
+		if ((bool)config_["flip_vert"]) {
+			cv::flip(depth, idepth, 0);
+		} else {
+			idepth = depth;
+		}
+
+    	idepth.convertTo(idepth, CV_8U, 255.0f / 256.0f);  // TODO(nick)
 
     	applyColorMap(idepth, idepth, cv::COLORMAP_JET);
 		cv::imshow("Disparity", idepth);
diff --git a/cv-node/src/local.cpp b/cv-node/src/local.cpp
index cb7ee6484..ea000e1a0 100644
--- a/cv-node/src/local.cpp
+++ b/cv-node/src/local.cpp
@@ -21,8 +21,9 @@ using std::chrono::duration;
 using std::chrono::high_resolution_clock;
 
 LocalSource::LocalSource(nlohmann::json &config)
-	:	timestamp_(0.0),
+		: timestamp_(0.0),
 		flip_(config["flip"]),
+		flip_v_(config["flip_vert"]),
 		nostereo_(config["nostereo"]),
 		downsize_(config.value("scale", 1.0f)) {
 	// Use cameras
@@ -55,6 +56,7 @@ LocalSource::LocalSource(nlohmann::json &config)
 LocalSource::LocalSource(const string &vid, nlohmann::json &config)
 	:	timestamp_(0.0),
 		flip_(config["flip"]),
+		flip_v_(config["flip_vert"]),
 		nostereo_(config["nostereo"]),
 		downsize_(config.value("scale", 1.0f)) {
 	if (vid == "") {
@@ -211,6 +213,14 @@ bool LocalSource::get(cv::Mat &l, cv::Mat &r) {
 				0, 0, cv::INTER_LINEAR);
 	}
 
+	if (flip_v_) {
+		Mat tl, tr;
+		cv::flip(l, tl, 0);
+		cv::flip(r, tr, 0);
+		l = tl;
+		r = tr;
+	}
+
 	return true;
 }
 
-- 
GitLab