From cf9b2961683f527a71842a72d73677d94e40a18b Mon Sep 17 00:00:00 2001
From: Nicolas Pope <nwpope@utu.fi>
Date: Tue, 7 May 2019 08:09:21 +0300
Subject: [PATCH] Add simple img show to display

---
 renderer/cpp/include/ftl/display.hpp |  7 +++++++
 renderer/cpp/src/display.cpp         | 21 +++++++++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/renderer/cpp/include/ftl/display.hpp b/renderer/cpp/include/ftl/display.hpp
index c6d63ca4f..e7642b8ac 100644
--- a/renderer/cpp/include/ftl/display.hpp
+++ b/renderer/cpp/include/ftl/display.hpp
@@ -17,6 +17,11 @@ namespace ftl {
  * Multiple local display options for disparity or point clouds.
  */
 class Display {
+	public:
+	enum style_t {
+		STYLE_NORMAL, STYLE_DISPARITY, STYLE_DEPTH
+	};
+
 	public:
 	explicit Display(nlohmann::json &config);
 	~Display();
@@ -25,6 +30,8 @@ class Display {
 
 	bool render(const cv::Mat &rgb, const cv::Mat &depth);
 
+	bool render(const cv::Mat &img, style_t s=STYLE_NORMAL);
+
 	bool active() const;
 	
 	void wait(int ms);
diff --git a/renderer/cpp/src/display.cpp b/renderer/cpp/src/display.cpp
index 7ee8efe3c..aa5449dfd 100644
--- a/renderer/cpp/src/display.cpp
+++ b/renderer/cpp/src/display.cpp
@@ -84,6 +84,27 @@ bool Display::render(const cv::Mat &rgb, const cv::Mat &depth) {
 	return true;
 }
 
+bool Display::render(const cv::Mat &img, style_t s) {
+	if (s == STYLE_NORMAL) {
+		cv::imshow("Image", img);
+	} else if (s = STYLE_DISPARITY) {
+		Mat idepth;
+
+		if ((bool)config_["flip_vert"]) {
+			cv::flip(img, idepth, 0);
+		} else {
+			idepth = img;
+		}
+
+    	idepth.convertTo(idepth, CV_8U, 255.0f / 256.0f);
+
+    	applyColorMap(idepth, idepth, cv::COLORMAP_JET);
+		cv::imshow("Disparity", idepth);
+	}
+
+	return true;
+}
+
 void Display::wait(int ms) {
 	if (config_["points"] && q_.rows != 0) {
 		#if defined HAVE_VIZ
-- 
GitLab