Skip to content
Snippets Groups Projects
Commit e775bff7 authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Zlib depth stream and publish to network. Deflate in reconstruct and display

parent f9a687d2
Branches
Tags
No related merge requests found
Pipeline #9747 passed
...@@ -20,6 +20,7 @@ find_package( Threads REQUIRED ) ...@@ -20,6 +20,7 @@ find_package( Threads REQUIRED )
find_package( URIParser REQUIRED ) find_package( URIParser REQUIRED )
find_package( MsgPack REQUIRED ) find_package( MsgPack REQUIRED )
find_package( LibSGM ) find_package( LibSGM )
find_package( ZLIB REQUIRED )
# Readline library is not required on Windows # Readline library is not required on Windows
# May also entirely remove dependence on this... it should be optional at least. # May also entirely remove dependence on this... it should be optional at least.
......
...@@ -12,6 +12,6 @@ add_executable(ftl-reconstruct ${REPSRC}) ...@@ -12,6 +12,6 @@ add_executable(ftl-reconstruct ${REPSRC})
add_dependencies(ftl-reconstruct ftlnet) add_dependencies(ftl-reconstruct ftlnet)
#target_include_directories(cv-node PUBLIC ${PROJECT_SOURCE_DIR}/include) #target_include_directories(cv-node PUBLIC ${PROJECT_SOURCE_DIR}/include)
target_link_libraries(ftl-reconstruct Threads::Threads ${OpenCV_LIBS} glog::glog ftlnet) target_link_libraries(ftl-reconstruct Threads::Threads ZLIB::ZLIB ${OpenCV_LIBS} glog::glog ftlnet)
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <glog/logging.h> #include <glog/logging.h>
#include <ftl/config.h> #include <ftl/config.h>
#include <zlib.h>
#include <string> #include <string>
#include <map> #include <map>
...@@ -114,23 +115,47 @@ static void process_options(const map<string, string> &opts) { ...@@ -114,23 +115,47 @@ static void process_options(const map<string, string> &opts) {
static void run(const string &file) { static void run(const string &file) {
Universe net(config["net"]); Universe net(config["net"]);
Mat rgb; Mat rgb, depth;
mutex m; mutex m;
// Make sure connections are complete // Make sure connections are complete
sleep_for(milliseconds(500)); sleep_for(milliseconds(500));
net.subscribe(config["source"], [&rgb,&m](const vector<unsigned char> &jpg) { net.subscribe(config["source"], [&rgb,&m,&depth](const vector<unsigned char> &jpg, const vector<unsigned char> &d) {
unique_lock<mutex> lk(m); unique_lock<mutex> lk(m);
cv::imdecode(jpg, cv::IMREAD_COLOR, &rgb); cv::imdecode(jpg, cv::IMREAD_COLOR, &rgb);
//LOG(INFO) << "Received JPG : " << rgb.cols; //LOG(INFO) << "Received JPG : " << rgb.cols;
depth = Mat(rgb.size(), CV_32FC1);
z_stream infstream;
infstream.zalloc = Z_NULL;
infstream.zfree = Z_NULL;
infstream.opaque = Z_NULL;
// setup "b" as the input and "c" as the compressed output
infstream.avail_in = (uInt)d.size(); // size of input
infstream.next_in = (Bytef *)d.data(); // input char array
infstream.avail_out = (uInt)depth.step*depth.rows; // size of output
infstream.next_out = (Bytef *)depth.data; // output char array
// the actual DE-compression work.
inflateInit(&infstream);
inflate(&infstream, Z_NO_FLUSH);
inflateEnd(&infstream);
}); });
while (true) { while (true) {
Mat idepth;
unique_lock<mutex> lk(m); unique_lock<mutex> lk(m);
if (rgb.cols > 0) { if (rgb.cols > 0) {
cv::imshow("RGB", rgb); cv::imshow("RGB", rgb);
} }
if (depth.cols > 0) {
depth.convertTo(idepth, CV_8U, 255.0f / 256.0f); // TODO(nick)
applyColorMap(idepth, idepth, cv::COLORMAP_JET);
cv::imshow("Depth", idepth);
}
lk.unlock(); lk.unlock();
if (cv::waitKey(40) == 27) break; if (cv::waitKey(40) == 27) break;
} }
......
...@@ -47,6 +47,6 @@ set_property(TARGET ftl-vision PROPERTY CUDA_SEPARABLE_COMPILATION ON) ...@@ -47,6 +47,6 @@ set_property(TARGET ftl-vision PROPERTY CUDA_SEPARABLE_COMPILATION ON)
endif() endif()
#target_include_directories(cv-node PUBLIC ${PROJECT_SOURCE_DIR}/include) #target_include_directories(cv-node PUBLIC ${PROJECT_SOURCE_DIR}/include)
target_link_libraries(ftl-vision Threads::Threads libelas ${OpenCV_LIBS} ${LIBSGM_LIBRARIES} ${CUDA_LIBRARIES} glog::glog ftlnet) target_link_libraries(ftl-vision Threads::Threads ZLIB::ZLIB libelas ${OpenCV_LIBS} ${LIBSGM_LIBRARIES} ${CUDA_LIBRARIES} glog::glog ftlnet)
#include <glog/logging.h> #include <glog/logging.h>
#include <ftl/streamer.hpp> #include <ftl/streamer.hpp>
#include <vector> #include <vector>
#include <zlib.h>
using ftl::Streamer; using ftl::Streamer;
using ftl::net::Universe; using ftl::net::Universe;
...@@ -22,8 +23,25 @@ void Streamer::send(const Mat &rgb, const Mat &depth) { ...@@ -22,8 +23,25 @@ void Streamer::send(const Mat &rgb, const Mat &depth) {
// Compress the rgb as jpeg. // Compress the rgb as jpeg.
vector<unsigned char> rgb_buf; vector<unsigned char> rgb_buf;
cv::imencode(".jpg", rgb, 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"; vector<unsigned char> d_buf;
d_buf.resize(depth.step*depth.rows);
z_stream defstream;
defstream.zalloc = Z_NULL;
defstream.zfree = Z_NULL;
defstream.opaque = Z_NULL;
defstream.avail_in = depth.step*depth.rows;
defstream.next_in = (Bytef *)depth.data; // input char array
defstream.avail_out = (uInt)depth.step*depth.rows; // size of output
defstream.next_out = (Bytef *)d_buf.data(); // output char array
deflateInit(&defstream, Z_BEST_COMPRESSION);
deflate(&defstream, Z_FINISH);
deflateEnd(&defstream);
d_buf.resize(defstream.total_out);
LOG(INFO) << "Depth Size = " << ((float)d_buf.size() / (1024.0f*1024.0f));
net_.publish(uri_, rgb_buf, d_buf);
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment