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

Merge branch 'master' of gitlab.utu.fi:nicolas.pope/ftl

parents bdbbd2e3 b42a08f3
No related branches found
No related tags found
No related merge requests found
Pipeline #9963 passed
...@@ -20,7 +20,7 @@ find_package( Threads REQUIRED ) ...@@ -20,7 +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 ) #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.
......
...@@ -9,7 +9,8 @@ ...@@ -9,7 +9,8 @@
"flip": false, "flip": false,
"nostereo": false, "nostereo": false,
"scale": 1.0, "scale": 1.0,
"flip_vert": false "flip_vert": false,
"max_fps": 25
}, },
"calibrate": false, "calibrate": false,
"calibration": { "calibration": {
......
...@@ -12,6 +12,6 @@ add_dependencies(ftl-reconstruct ftlnet) ...@@ -12,6 +12,6 @@ add_dependencies(ftl-reconstruct ftlnet)
add_dependencies(ftl-reconstruct ftlcommon) add_dependencies(ftl-reconstruct ftlcommon)
#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 ftlcommon Threads::Threads ZLIB::ZLIB ${OpenCV_LIBS} glog::glog ftlnet ftlrender) target_link_libraries(ftl-reconstruct ftlcommon Threads::Threads ${OpenCV_LIBS} glog::glog ftlnet ftlrender)
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include <glog/logging.h> #include <glog/logging.h>
#include <ftl/config.h> #include <ftl/config.h>
#include <ftl/configuration.hpp> #include <ftl/configuration.hpp>
#include <zlib.h> // #include <zlib.h>
// #include <lz4.h> // #include <lz4.h>
#include <string> #include <string>
......
...@@ -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 ftlcommon ftlrender Threads::Threads ZLIB::ZLIB libelas ${OpenCV_LIBS} ${LIBSGM_LIBRARIES} ${CUDA_LIBRARIES} glog::glog ftlnet) target_link_libraries(ftl-vision ftlcommon ftlrender Threads::Threads libelas ${OpenCV_LIBS} ${LIBSGM_LIBRARIES} ${CUDA_LIBRARIES} glog::glog ftlnet)
...@@ -28,6 +28,7 @@ class LocalSource { ...@@ -28,6 +28,7 @@ class LocalSource {
private: private:
double timestamp_; double timestamp_;
double tps_;
bool stereo_; bool stereo_;
//float fps_; //float fps_;
bool flip_; bool flip_;
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <string> #include <string>
#include <chrono> #include <chrono>
#include <thread>
#include <ftl/local.hpp> #include <ftl/local.hpp>
#include <opencv2/core.hpp> #include <opencv2/core.hpp>
...@@ -19,6 +20,8 @@ using std::string; ...@@ -19,6 +20,8 @@ using std::string;
using std::chrono::duration_cast; using std::chrono::duration_cast;
using std::chrono::duration; using std::chrono::duration;
using std::chrono::high_resolution_clock; using std::chrono::high_resolution_clock;
using std::chrono::milliseconds;
using std::this_thread::sleep_for;
LocalSource::LocalSource(nlohmann::json &config) LocalSource::LocalSource(nlohmann::json &config)
: timestamp_(0.0), : timestamp_(0.0),
...@@ -51,6 +54,8 @@ LocalSource::LocalSource(nlohmann::json &config) ...@@ -51,6 +54,8 @@ LocalSource::LocalSource(nlohmann::json &config)
} else { } else {
stereo_ = true; stereo_ = true;
} }
tps_ = 1.0 / (double)config["max_fps"];
} }
LocalSource::LocalSource(const string &vid, nlohmann::json &config) LocalSource::LocalSource(const string &vid, nlohmann::json &config)
...@@ -89,6 +94,8 @@ LocalSource::LocalSource(const string &vid, nlohmann::json &config) ...@@ -89,6 +94,8 @@ LocalSource::LocalSource(const string &vid, nlohmann::json &config)
LOG(INFO) << "Video size : " << frame.cols << "x" << frame.rows; LOG(INFO) << "Video size : " << frame.cols << "x" << frame.rows;
stereo_ = false; stereo_ = false;
} }
tps_ = 1.0 / (double)config["max_fps"];
} }
bool LocalSource::left(cv::Mat &l) { bool LocalSource::left(cv::Mat &l) {
...@@ -177,8 +184,15 @@ bool LocalSource::get(cv::Mat &l, cv::Mat &r) { ...@@ -177,8 +184,15 @@ bool LocalSource::get(cv::Mat &l, cv::Mat &r) {
} }
// Record timestamp // Record timestamp
timestamp_ = duration_cast<duration<double>>( double timestamp = duration_cast<duration<double>>(
high_resolution_clock::now().time_since_epoch()).count(); high_resolution_clock::now().time_since_epoch()).count();
// Limit max framerate
if (timestamp - timestamp_ < tps_) {
sleep_for(milliseconds((int)std::round((tps_ - (timestamp - timestamp_))*1000)));
}
timestamp_ = timestamp;
if (camera_b_ || !stereo_) { if (camera_b_ || !stereo_) {
if (!camera_a_->retrieve(l)) { if (!camera_a_->retrieve(l)) {
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <glog/logging.h> #include <glog/logging.h>
#include <ftl/configuration.hpp> #include <ftl/configuration.hpp>
#include <ctpl_stl.h> #include <ctpl_stl.h>
#include <zlib.h>
#include <string> #include <string>
#include <map> #include <map>
...@@ -105,6 +106,9 @@ static void run(const string &file) { ...@@ -105,6 +106,9 @@ static void run(const string &file) {
Mat l, r, disp; Mat l, r, disp;
Mat pl, pdisp; Mat pl, pdisp;
vector<unsigned char> rgb_buf;
vector<unsigned char> d_buf;
string uri = string("ftl://utu.fi/")+(string)config["stream"]["name"]+string("/rgb-d");
Display display(config["display"]); Display display(config["display"]);
display.setCalibration(Q_32F); display.setCalibration(Q_32F);
...@@ -116,6 +120,7 @@ static void run(const string &file) { ...@@ -116,6 +120,7 @@ static void run(const string &file) {
condition_variable cv; condition_variable cv;
int jobs = 0; int jobs = 0;
// Pipeline for disparity
pool.push([&](int id) { pool.push([&](int id) {
auto start = std::chrono::high_resolution_clock::now(); auto start = std::chrono::high_resolution_clock::now();
// Read calibrated images. // Read calibrated images.
...@@ -141,6 +146,51 @@ static void run(const string &file) { ...@@ -141,6 +146,51 @@ static void run(const string &file) {
LOG(INFO) << "Disparity in " << elapsed.count() << "s"; LOG(INFO) << "Disparity in " << elapsed.count() << "s";
}); });
// Pipeline for jpeg compression
/*pool.push([&](int id) {
auto start = std::chrono::high_resolution_clock::now();
if (pl.rows != 0) cv::imencode(".jpg", pl, rgb_buf);
unique_lock<mutex> lk(m);
jobs++;
lk.unlock();
cv.notify_one();
std::chrono::duration<double> elapsed =
std::chrono::high_resolution_clock::now() - start;
LOG(INFO) << "JPG in " << elapsed.count() << "s";
});*/
// Pipeline for zlib compression
/*pool.push([&](int id) {
auto start = std::chrono::high_resolution_clock::now();
if (pl.rows != 0) {
d_buf.resize(pdisp.step*pdisp.rows);
z_stream defstream;
defstream.zalloc = Z_NULL;
defstream.zfree = Z_NULL;
defstream.opaque = Z_NULL;
defstream.avail_in = pdisp.step*pdisp.rows;
defstream.next_in = (Bytef *)pdisp.data; // input char array
defstream.avail_out = (uInt)pdisp.step*pdisp.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);
}
unique_lock<mutex> lk(m);
jobs++;
lk.unlock();
cv.notify_one();
std::chrono::duration<double> elapsed =
std::chrono::high_resolution_clock::now() - start;
LOG(INFO) << "ZLIB in " << elapsed.count() << "s";
});*/
// Pipeline for stream compression
pool.push([&](int id) { pool.push([&](int id) {
auto start = std::chrono::high_resolution_clock::now(); auto start = std::chrono::high_resolution_clock::now();
if (pl.rows != 0) stream.send(pl, pdisp); if (pl.rows != 0) stream.send(pl, pdisp);
...@@ -158,11 +208,15 @@ static void run(const string &file) { ...@@ -158,11 +208,15 @@ static void run(const string &file) {
if (pl.rows > 0) display.render(pl, pdisp); if (pl.rows > 0) display.render(pl, pdisp);
display.wait(1); display.wait(1);
// Wait for both pipelines to complete
unique_lock<mutex> lk(m); unique_lock<mutex> lk(m);
cv.wait(lk, [&jobs]{return jobs == 2;}); cv.wait(lk, [&jobs]{return jobs == 2;});
// Store previous frame for next stage compression
l.copyTo(pl); l.copyTo(pl);
disp.copyTo(pdisp); disp.copyTo(pdisp);
//net.publish(uri, rgb_buf, d_buf);
} }
} }
......
#include <glog/logging.h> #include <glog/logging.h>
#include <ftl/streamer.hpp> #include <ftl/streamer.hpp>
#include <vector> #include <vector>
#include <zlib.h> // #include <zlib.h>
// #include <lz4.h> // #include <lz4.h>
using ftl::Streamer; using ftl::Streamer;
...@@ -39,7 +39,7 @@ void Streamer::send(const Mat &rgb, const Mat &depth) { ...@@ -39,7 +39,7 @@ void Streamer::send(const Mat &rgb, const Mat &depth) {
defstream.avail_out = (uInt)d2.step*d2.rows; // size of output defstream.avail_out = (uInt)d2.step*d2.rows; // size of output
defstream.next_out = (Bytef *)d_buf.data(); // output char array defstream.next_out = (Bytef *)d_buf.data(); // output char array
deflateInit(&defstream, 4); // Z_DEFAULT_COMPRESSION deflateInit(&defstream, Z_DEFAULT_COMPRESSION);
deflate(&defstream, Z_FINISH); deflate(&defstream, Z_FINISH);
deflateEnd(&defstream); deflateEnd(&defstream);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment