diff --git a/cv-node/include/ftl/streamer.hpp b/cv-node/include/ftl/streamer.hpp new file mode 100644 index 0000000000000000000000000000000000000000..0987633e4f679b5ea1ec998963d59a07111f1376 --- /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 0000000000000000000000000000000000000000..79ef05b6bb20f1c0b34485ee71ff95ae9c56c0f4 --- /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"; +} +