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

Move display code to render lib and add to reconstructor

parent ebd010b3
No related branches found
No related tags found
No related merge requests found
Pipeline #9753 failed
......@@ -114,6 +114,7 @@ endif()
SET(CMAKE_USE_RELATIVE_PATHS ON)
add_subdirectory(renderer)
add_subdirectory(net)
add_subdirectory(vision)
add_subdirectory(reconstruct)
......
......@@ -66,7 +66,15 @@
"net": {
"peers": ["tcp://localhost:9001"]
},
"source": "ftl://utu.fi/dummy/rgb-d"
"source": "ftl://utu.fi/dummy/rgb-d",
"display": {
"flip_vert": false,
"disparity": false,
"points": true,
"depth": false,
"left": false,
"right": false
}
}
}
......@@ -129,7 +129,7 @@ void ftl::net::Dispatcher::dispatch_notification(Peer &s, msgpack::object const
auto &&name = std::get<1>(the_call);
auto &&args = std::get<2>(the_call);
LOG(INFO) << "NOTIFICATION " << name << "() <- " << s.getURI();
//LOG(INFO) << "NOTIFICATION " << name << "() <- " << s.getURI();
auto binding = _locateHandler(name);
......
......@@ -12,6 +12,6 @@ add_executable(ftl-reconstruct ${REPSRC})
add_dependencies(ftl-reconstruct ftlnet)
#target_include_directories(cv-node PUBLIC ${PROJECT_SOURCE_DIR}/include)
target_link_libraries(ftl-reconstruct Threads::Threads ZLIB::ZLIB ${OpenCV_LIBS} glog::glog ftlnet)
target_link_libraries(ftl-reconstruct Threads::Threads ZLIB::ZLIB ${OpenCV_LIBS} glog::glog ftlnet ftlrender)
......@@ -18,6 +18,7 @@
#include <opencv2/opencv.hpp>
#include <ftl/net/universe.hpp>
#include <ftl/display.hpp>
#include <nlohmann/json.hpp>
#include "opencv2/imgproc.hpp"
......@@ -30,6 +31,7 @@
#endif
using ftl::net::Universe;
using ftl::Display;
using std::string;
using std::vector;
using std::map;
......@@ -118,6 +120,8 @@ static void run(const string &file) {
Mat rgb, depth, Q;
mutex m;
Display disp(config["display"]);
// Make sure connections are complete
sleep_for(milliseconds(500));
......@@ -144,13 +148,10 @@ static void run(const string &file) {
inflateEnd(&infstream);
});
while (true) {
while (disp.active()) {
Mat idepth;
unique_lock<mutex> lk(m);
if (rgb.cols > 0) {
cv::imshow("RGB", rgb);
}
if (depth.cols > 0) {
if (Q.rows == 0) {
auto buf = net.findOne<vector<unsigned char>>((string)config["source"]+"/calibration");
......@@ -158,14 +159,23 @@ static void run(const string &file) {
Q = Mat(cv::Size(4,4), CV_32F);
memcpy((*buf).data(), Q.data, (*buf).size());
LOG(INFO) << "Have calibration";
if (Q.step*Q.rows != (*buf).size()) LOG(ERROR) << "Corrupted calibration";
disp.setCalibration(Q);
}
}
depth.convertTo(idepth, CV_8U, 255.0f / 256.0f); // TODO(nick)
applyColorMap(idepth, idepth, cv::COLORMAP_JET);
cv::imshow("Depth", idepth);
//depth.convertTo(idepth, CV_8U, 255.0f / 256.0f); // TODO(nick)
//applyColorMap(idepth, idepth, cv::COLORMAP_JET);
//cv::imshow("Depth", idepth);
}
if (rgb.cols > 0) {
//cv::imshow("RGB", rgb);
disp.render(rgb,depth);
}
lk.unlock();
if (cv::waitKey(40) == 27) break;
//if (cv::waitKey(40) == 27) break;
disp.wait(40);
}
}
......
add_subdirectory(cpp)
# Need to include staged files and libs
#include_directories(${PROJECT_SOURCE_DIR}/net/cpp/include)
#include_directories(${PROJECT_BINARY_DIR})
add_library(ftlrender
src/display.cpp
)
target_include_directories(ftlrender PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
PRIVATE src)
target_link_libraries(ftlrender Threads::Threads glog::glog ${OpenCV_LIBS})
#ADD_SUBDIRECTORY(test)
......@@ -9,7 +9,6 @@
#include <nlohmann/json.hpp>
#include <opencv2/opencv.hpp>
#include <ftl/calibrate.hpp>
#include "opencv2/highgui.hpp"
namespace ftl {
......@@ -19,15 +18,19 @@ namespace ftl {
*/
class Display {
public:
Display(const Calibrate &cal, nlohmann::json &config);
Display(nlohmann::json &config);
~Display();
void setCalibration(const cv::Mat &q) { q_ = q; }
bool render(const cv::Mat &rgb, const cv::Mat &depth);
bool active() const;
void wait(int ms);
private:
const ftl::Calibrate &calibrate_;
cv::Mat q_;
nlohmann::json config_;
#if defined HAVE_VIZ
......
......@@ -7,12 +7,10 @@
#include <ftl/display.hpp>
using ftl::Display;
using ftl::Calibrate;
using cv::Mat;
using cv::Vec3f;
Display::Display(const Calibrate &cal, nlohmann::json &config) :
calibrate_(cal), config_(config) {
Display::Display(nlohmann::json &config) : config_(config) {
#if defined HAVE_VIZ
window_ = new cv::viz::Viz3d("FTL");
window_->setBackgroundColor(cv::viz::Color::white());
......@@ -29,12 +27,12 @@ Display::~Display() {
bool Display::render(const cv::Mat &rgb, const cv::Mat &depth) {
Mat idepth;
if (config_["points"]) {
if (config_["points"] && q_.rows != 0) {
#if defined HAVE_VIZ
cv::Mat Q_32F;
calibrate_.getQ().convertTo(Q_32F, CV_32F);
//cv::Mat Q_32F;
//calibrate_.getQ().convertTo(Q_32F, CV_32F);
cv::Mat_<cv::Vec3f> XYZ(depth.rows, depth.cols); // Output point cloud
reprojectImageTo3D(depth+20.0f, XYZ, Q_32F, true);
reprojectImageTo3D(depth+20.0f, XYZ, q_, true);
// Remove all invalid pixels from point cloud
XYZ.setTo(Vec3f(NAN, NAN, NAN), depth == 0.0f);
......@@ -45,7 +43,7 @@ bool Display::render(const cv::Mat &rgb, const cv::Mat &depth) {
window_->showWidget("coosys", cv::viz::WCoordinateSystem());
window_->showWidget("Depth", cloud_widget);
window_->spinOnce(1, true);
//window_->spinOnce(40, true);
#else // HAVE_VIZ
......@@ -77,15 +75,30 @@ bool Display::render(const cv::Mat &rgb, const cv::Mat &depth) {
applyColorMap(idepth, idepth, cv::COLORMAP_JET);
cv::imshow("Disparity", idepth);
if(cv::waitKey(10) == 27) {
//if(cv::waitKey(40) == 27) {
// exit if ESC is pressed
active_ = false;
}
// active_ = false;
//}
}
return true;
}
void Display::wait(int ms) {
if (config_["points"] && q_.rows != 0) {
#if defined HAVE_VIZ
window_->spinOnce(1, true);
#endif // HAVE_VIZ
}
if (config_["disparity"]) {
if(cv::waitKey(ms) == 27) {
// exit if ESC is pressed
active_ = false;
}
}
}
bool Display::active() const {
#if defined HAVE_VIZ
return active_ && !window_->wasStopped();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment