From 3f58c84b2bddee36bccd0ae765253f86c7dbb482 Mon Sep 17 00:00:00 2001 From: Nicolas Pope <nwpope@utu.fi> Date: Thu, 11 Apr 2019 21:07:30 +0300 Subject: [PATCH] Missing streamer files --- cv-node/include/ftl/streamer.hpp | 27 +++++++++++++++++++++++++++ cv-node/src/streamer.cpp | 29 +++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 cv-node/include/ftl/streamer.hpp create mode 100644 cv-node/src/streamer.cpp diff --git a/cv-node/include/ftl/streamer.hpp b/cv-node/include/ftl/streamer.hpp new file mode 100644 index 000000000..0987633e4 --- /dev/null +++ b/cv-node/include/ftl/streamer.hpp @@ -0,0 +1,27 @@ +#ifndef _FTL_STREAMER_HPP_ +#define _FTL_STREAMER_HPP_ + +#include <ftl/net/universe.hpp> +#include <nlohmann/json.hpp> +#include <opencv2/opencv.hpp> +#include <string> + +namespace ftl { + +class Streamer { + public: + Streamer(ftl::net::Universe &net, nlohmann::json &config); + ~Streamer(); + + void send(const cv::Mat &rgb, const cv::Mat &depth); + + private: + ftl::net::Universe &net_; + nlohmann::json config_; + std::string uri_; +}; + +}; + +#endif // _FTL_STREAMER_HPP_ + diff --git a/cv-node/src/streamer.cpp b/cv-node/src/streamer.cpp new file mode 100644 index 000000000..79ef05b6b --- /dev/null +++ b/cv-node/src/streamer.cpp @@ -0,0 +1,29 @@ +#include <glog/logging.h> +#include <ftl/streamer.hpp> +#include <vector> + +using ftl::Streamer; +using ftl::net::Universe; +using cv::Mat; +using nlohmann::json; +using std::string; +using std::vector; + +Streamer::Streamer(Universe &net, json &config) : net_(net), config_(config) { + uri_ = string("ftl://utu.fi/")+(string)config["name"]+string("/rgb-d"); + net.createResource(uri_); +} + +Streamer::~Streamer() { + +} + +void Streamer::send(const Mat &rgb, const Mat &depth) { + // Compress the rgb as jpeg. + vector<unsigned char> rgb_buf; + cv::imencode(".jpg", rgb, rgb_buf); + net_.publish(uri_, rgb_buf); + + LOG(INFO) << "JPG Size = " << ((float)rgb_buf.size() / (1024.0f*1024.0f)) << "Mb"; +} + -- GitLab