From ebd010b3b8ce2693c0193a4504d42fabdbcb1609 Mon Sep 17 00:00:00 2001
From: Nicolas Pope <nwpope@utu.fi>
Date: Fri, 12 Apr 2019 08:45:27 +0300
Subject: [PATCH] Send calibration data over network

---
 reconstruct/src/main.cpp | 10 +++++++++-
 vision/src/main.cpp      | 13 +++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/reconstruct/src/main.cpp b/reconstruct/src/main.cpp
index 806e17bb9..8b7035dfc 100644
--- a/reconstruct/src/main.cpp
+++ b/reconstruct/src/main.cpp
@@ -115,7 +115,7 @@ static void process_options(const map<string, string> &opts) {
 
 static void run(const string &file) {
 	Universe net(config["net"]);
-	Mat rgb, depth;
+	Mat rgb, depth, Q;
 	mutex m;
 	
 	// Make sure connections are complete
@@ -152,6 +152,14 @@ static void run(const string &file) {
 			cv::imshow("RGB", rgb);
 		}
 		if (depth.cols > 0) {
+			if (Q.rows == 0) {
+				auto buf = net.findOne<vector<unsigned char>>((string)config["source"]+"/calibration");
+				if (buf) {
+					Q = Mat(cv::Size(4,4), CV_32F);
+					memcpy((*buf).data(), Q.data, (*buf).size());
+					LOG(INFO) << "Have calibration";
+				}
+			}
 			depth.convertTo(idepth, CV_8U, 255.0f / 256.0f);  // TODO(nick)
     		applyColorMap(idepth, idepth, cv::COLORMAP_JET);
 			cv::imshow("Depth", idepth);
diff --git a/vision/src/main.cpp b/vision/src/main.cpp
index 31e1c4100..16e1bc6ae 100644
--- a/vision/src/main.cpp
+++ b/vision/src/main.cpp
@@ -139,9 +139,21 @@ static void run(const string &file) {
 	Calibrate calibrate(lsrc, config["calibration"]);
 	if (config["calibrate"]) calibrate.recalibrate();
 	if (!calibrate.isCalibrated()) LOG(WARNING) << "Cameras are not calibrated!";
+	
+	// Allow remote users to access camera calibration matrix
+	net.bind(string("ftl://utu.fi/")+(string)config["stream"]["name"]+string("/rgb-d/calibration"), [&calibrate]() -> vector<unsigned char> {
+		vector<unsigned char> buf;
+		cv::Mat Q_32F;
+		calibrate.getQ().convertTo(Q_32F, CV_32F);
+		
+		buf.resize(Q_32F.step*Q_32F.rows);
+		memcpy(Q_32F.data, buf.data(), buf.size());
+		return buf;
+	});
 
     // Choose and configure disparity algorithm
     auto disparity = Disparity::create(config["disparity"]);
+    if (!disparity) LOG(FATAL) << "Unknown disparity algorithm : " << config["disparity"];
 
 	Mat l, r, disp;
 
@@ -160,6 +172,7 @@ static void run(const string &file) {
 		sync->get(ftl::LEFT, l);
 		sync->get(ftl::RIGHT, r);
 
+		// TODO(nick) Pipeline this
         disparity->compute(l, r, disp);
 
 		// Send RGB+Depth images for local rendering
-- 
GitLab