From 7e67e5a652794a7e29b87e62050ab3ae496d74dc Mon Sep 17 00:00:00 2001
From: Nicolas Pope <nwpope@utu.fi>
Date: Sun, 18 Aug 2019 14:59:14 +0300
Subject: [PATCH] Fix for thumbnails

---
 applications/gui/src/camera.cpp     | 8 ++++++++
 applications/gui/src/camera.hpp     | 2 ++
 applications/gui/src/src_window.cpp | 2 +-
 3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/applications/gui/src/camera.cpp b/applications/gui/src/camera.cpp
index 7f93add71..f44521b3a 100644
--- a/applications/gui/src/camera.cpp
+++ b/applications/gui/src/camera.cpp
@@ -289,6 +289,14 @@ static void drawEdges(	const cv::Mat &in, cv::Mat &out,
 	cv::addWeighted(edges, weight, out, 1.0, 0.0, out, CV_8UC3);
 }
 
+bool ftl::gui::Camera::thumbnail(cv::Mat &thumb) {
+	UNIQUE_LOCK(mutex_, lk);
+	src_->grab(1,9);
+	if (rgb_.empty()) return false;
+	cv::resize(rgb_, thumb, cv::Size(320,180));
+	return true;
+}
+
 const GLTexture &ftl::gui::Camera::captureFrame() {
 	float now = (float)glfwGetTime();
 	delta_ = now - ftime_;
diff --git a/applications/gui/src/camera.hpp b/applications/gui/src/camera.hpp
index 89fcff188..f412d9c43 100644
--- a/applications/gui/src/camera.hpp
+++ b/applications/gui/src/camera.hpp
@@ -40,6 +40,8 @@ class Camera {
 
 	const GLTexture &captureFrame();
 
+	bool thumbnail(cv::Mat &thumb);
+
 	nlohmann::json getMetaData();
 
 	StatisticsImage *stats_ = nullptr;
diff --git a/applications/gui/src/src_window.cpp b/applications/gui/src/src_window.cpp
index e98ec081b..e7ffc4b1e 100644
--- a/applications/gui/src/src_window.cpp
+++ b/applications/gui/src/src_window.cpp
@@ -116,7 +116,7 @@ void SourceWindow::draw(NVGcontext *ctx) {
 			cv::Mat t;
 			auto *cam = cameras_[available_[i]];
 			if (cam) {
-				if (cam->source()->thumbnail(t)) {
+				if (cam->thumbnail(t)) {
 					thumbs_[i].update(t);
 				} else {
 					refresh_thumbs_ = true;
-- 
GitLab