From f1ce8ede6332f6c22263a199db6186b35e2d5637 Mon Sep 17 00:00:00 2001 From: Nicolas Pope <nwpope@utu.fi> Date: Wed, 20 May 2020 08:13:32 +0300 Subject: [PATCH] Remove old files --- applications/groupview/CMakeLists.txt | 11 - applications/groupview/src/main.cpp | 328 --------------------- applications/player/CMakeLists.txt | 11 - applications/player/src/main.cpp | 218 -------------- applications/recorder/CMakeLists.txt | 16 - applications/recorder/src/main.cpp | 221 -------------- applications/recorder/src/registration.cpp | 69 ----- applications/recorder/src/registration.hpp | 22 -- 8 files changed, 896 deletions(-) delete mode 100644 applications/groupview/CMakeLists.txt delete mode 100644 applications/groupview/src/main.cpp delete mode 100644 applications/player/CMakeLists.txt delete mode 100644 applications/player/src/main.cpp delete mode 100644 applications/recorder/CMakeLists.txt delete mode 100644 applications/recorder/src/main.cpp delete mode 100644 applications/recorder/src/registration.cpp delete mode 100644 applications/recorder/src/registration.hpp diff --git a/applications/groupview/CMakeLists.txt b/applications/groupview/CMakeLists.txt deleted file mode 100644 index 25370e7b0..000000000 --- a/applications/groupview/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -set(GVIEWSRC - src/main.cpp -) - -add_executable(ftl-view ${GVIEWSRC}) - -target_include_directories(ftl-view PRIVATE src) - -target_link_libraries(ftl-view ftlcommon ftlnet ftlrgbd Threads::Threads ${OpenCV_LIBS}) - - diff --git a/applications/groupview/src/main.cpp b/applications/groupview/src/main.cpp deleted file mode 100644 index f9d763fb6..000000000 --- a/applications/groupview/src/main.cpp +++ /dev/null @@ -1,328 +0,0 @@ -#include <loguru.hpp> -#include <ftl/configuration.hpp> -#include <ftl/net/universe.hpp> -#include <ftl/rgbd/source.hpp> -#include <ftl/rgbd/group.hpp> - -#ifdef HAVE_LIBARCHIVE -#include <ftl/rgbd/snapshot.hpp> -#endif - -#include <fstream> - -using Eigen::Matrix4d; -using std::map; -using std::string; -using std::vector; -using cv::Size; -using cv::Mat; -using ftl::codecs::Channel; - -// TODO: remove code duplication (function from reconstruction) -static void from_json(nlohmann::json &json, map<string, Matrix4d> &transformations) { - for (auto it = json.begin(); it != json.end(); ++it) { - Eigen::Matrix4d m; - auto data = m.data(); - for(size_t i = 0; i < 16; i++) { data[i] = it.value()[i]; } - transformations[it.key()] = m; - } -} - -// TODO: remove code duplication (function from reconstruction) -static bool loadTransformations(const string &path, map<string, Matrix4d> &data) { - std::ifstream file(path); - if (!file.is_open()) { - LOG(ERROR) << "Error loading transformations from file " << path; - return false; - } - - nlohmann::json json_registration; - file >> json_registration; - from_json(json_registration, data); - return true; -} - -// TODO: remove code duplication (function from calibrate-multi) -void stack(const vector<Mat> &img, Mat &out, const int rows, const int cols) { - Size size = img[0].size(); - Size size_out = Size(size.width * cols, size.height * rows); - if (size_out != out.size() || out.type() != CV_8UC3) { - out = Mat(size_out, CV_8UC3, cv::Scalar(0, 0, 0)); - } - - for (size_t i = 0; i < img.size(); i++) { - int row = i % rows; - int col = i / rows; - auto rect = cv::Rect(size.width * col, size.height * row, size.width, size.height); - img[i].copyTo(out(rect)); - } -} - -// TODO: remove code duplication (function from calibrate-multi) -void stack(const vector<Mat> &img, Mat &out) { - // TODO - int rows = 2; - int cols = (img.size() + 1) / 2; - stack(img, out, rows, cols); -} - -void modeLeftRight(ftl::Configurable *root) { - ftl::net::Universe *net = ftl::create<ftl::net::Universe>(root, "net"); - - net->start(); - net->waitConnections(); - - auto sources = ftl::createArray<ftl::rgbd::Source>(root, "sources", net); - const string path = root->value<string>("save_to", "./"); - const string file_type = root->value<string>("file_type", "jpg"); - - const size_t n_cameras = sources.size() * 2; - ftl::rgbd::Group group; - - for (auto* src : sources) { - src->setChannel(Channel::Right); - group.addSource(src); - } - - std::mutex mutex; - std::atomic<bool> new_frames = false; - vector<Mat> rgb(n_cameras), rgb_new(n_cameras); - - group.onFrameSet([&mutex, &new_frames, &rgb_new](ftl::rgbd::FrameSet &frames) { - mutex.lock(); - bool good = true; - for (size_t i = 0; i < frames.frames.size(); i ++) { - auto &chan1 = frames.frames[i].get<cv::Mat>(Channel::Colour); - auto &chan2 = frames.frames[i].get<cv::Mat>(frames.sources[i]->getChannel()); - if (chan1.empty()) good = false; - if (chan2.empty()) good = false; - if (chan1.channels() != 3) good = false; // ASSERT - if (chan2.channels() != 3) good = false; - if (!good) break; - - chan1.copyTo(rgb_new[2 * i]); - chan2.copyTo(rgb_new[2 * i + 1]); - } - - new_frames = good; - mutex.unlock(); - return true; - }); - - int idx = 0; - - Mat show; - - while (ftl::running) { - int key; - - while (!new_frames) { - for (auto src : sources) { src->grab(30); } - key = cv::waitKey(10); - } - - mutex.lock(); - rgb.swap(rgb_new); - new_frames = false; - mutex.unlock(); - - stack(rgb, show); - cv::namedWindow("Cameras", cv::WINDOW_KEEPRATIO | cv::WINDOW_NORMAL); - cv::imshow("Cameras", show); - - key = cv::waitKey(100); - // TODO: fix - if (key == 's') { - for (size_t c = 0; c < n_cameras; c++ ) { - cv::imwrite(path + "camera" + std::to_string(c) + "_" + std::to_string(idx) + "." + file_type, rgb[c]); - } - LOG(INFO) << "Saved (" << idx << ")"; - idx++; - } - if (key == 27) break; - } -} - -void modeFrame(ftl::Configurable *root, int frames=1) { - ftl::net::Universe *net = ftl::create<ftl::net::Universe>(root, "net"); - - net->start(); - net->waitConnections(); - - auto sources = ftl::createArray<ftl::rgbd::Source>(root, "sources", net); - - std::map<std::string, Eigen::Matrix4d> transformations; - if (loadTransformations(string(FTL_LOCAL_CONFIG_ROOT) + "/registration.json", transformations)) { - LOG(INFO) << "Loaded camera trasformations from file"; - } - else { - LOG(ERROR) << "Error loading camera transformations from file"; - } - - ftl::rgbd::Group group; - for (auto s : sources) { - string uri = s->getURI(); - auto T = transformations.find(uri); - if (T == transformations.end()) { - LOG(ERROR) << "Camera pose for " + uri + " not found in transformations"; - } else { - s->setPose(T->second); - } - s->setChannel(Channel::Depth); - group.addSource(s); - } - - std::atomic<bool> grab = false; - std::atomic<bool> video = false; - - vector<cv::Mat> rgb(sources.size()); - vector<cv::Mat> depth(sources.size()); - MUTEX mtx; - - group.onFrameSet([&grab,&rgb,&depth,&mtx](ftl::rgbd::FrameSet &fs) { - UNIQUE_LOCK(mtx, lk); - //LOG(INFO) << "Complete set: " << fs.timestamp; - if (!ftl::running) { return false; } - - std::vector<cv::Mat> frames; - - for (size_t i=0; i<fs.sources.size(); ++i) { - auto &chan1 = fs.frames[i].get<cv::Mat>(Channel::Colour); - auto &chan2 = fs.frames[i].get<cv::Mat>(fs.sources[i]->getChannel()); - if (chan1.empty() || chan2.empty()) return true; - - frames.push_back(chan1); - } - - cv::Mat show; - - stack(frames, show); - - cv::resize(show, show, cv::Size(1280,720)); - cv::namedWindow("Cameras", cv::WINDOW_KEEPRATIO | cv::WINDOW_NORMAL); - cv::imshow("Cameras", show); - - auto key = cv::waitKey(1); - if (key == 27) ftl::running = false; - if (key == 'g') grab = true; - -#ifdef HAVE_LIBARCHIVE - if (grab) { - grab = false; - char timestamp[18]; - std::time_t t=std::time(NULL); - std::strftime(timestamp, sizeof(timestamp), "%F-%H%M%S", std::localtime(&t)); - auto writer = ftl::rgbd::SnapshotWriter(std::string(timestamp) + ".tar.gz"); - - for (size_t i=0; i<fs.sources.size(); ++i) { - auto &chan1 = fs.frames[i].get<cv::Mat>(Channel::Colour); - auto &chan2 = fs.frames[i].get<cv::Mat>(fs.sources[i]->getChannel()); - - writer.addSource(fs.sources[i]->getURI(), fs.sources[i]->parameters(), fs.sources[i]->getPose()); - //LOG(INFO) << "SAVE: " << fs.channel1[i].cols << ", " << fs.channel2[i].type(); - writer.addRGBD(i, chan1, chan2); - } - } -#endif // HAVE_LIBARCHIVE - return true; - }); - - /*cv::Mat show; - - while (ftl::running) { - for (auto s : sources) s->grab(30); - for (size_t i = 0; i < sources.size(); i++) { - //do { sources[i]->getFrames(rgb[i], depth[i]); } - while(rgb[i].empty()); - } - - { - UNIQUE_LOCK(mtx, lk); - stack(rgb, show); - } - cv::resize(show, show, cv::Size(1280,720)); - cv::namedWindow("Cameras", cv::WINDOW_KEEPRATIO | cv::WINDOW_NORMAL); - cv::imshow("Cameras", show); - - auto key = cv::waitKey(20); - if (key == 27) break; - if (key == 'g') grab = true; - }*/ -} - -void modeVideo(ftl::Configurable *root) { - - ftl::net::Universe *net = ftl::create<ftl::net::Universe>(root, "net"); - - net->start(); - net->waitConnections(); - - auto sources = ftl::createArray<ftl::rgbd::Source>(root, "sources", net); - const string path = root->value<string>("save_to", "./"); - - for (auto* src : sources) { src->setChannel(Channel::Depth); } - - cv::Mat show; - vector<cv::Mat> rgb(sources.size()); - vector<cv::Mat> depth(sources.size()); - -#ifdef HAVE_LIBARCHIVE - char timestamp[18]; - std::time_t t=std::time(NULL); - std::strftime(timestamp, sizeof(timestamp), "%F-%H%M%S", std::localtime(&t)); - ftl::rgbd::SnapshotWriter writer = ftl::rgbd::SnapshotWriter(std::string(timestamp) + ".tar.gz"); - - for (size_t i = 0; i < sources.size(); i++) { - writer.addSource(sources[i]->getURI(), sources[i]->parameters(), sources[i]->getPose()); - } -#endif // HAVE_LIBARCHIVE - - bool save = false; - - while (ftl::running) { - for (auto s : sources) s->grab(30); - for (size_t i = 0; i < sources.size(); i++) { - do { sources[i]->getFrames(rgb[i], depth[i]); } - while(rgb[i].empty() || depth[i].empty()); - } - -#ifdef HAVE_LIBARCHIVE - if (save) { - for (size_t i = 0; i < sources.size(); i++) { - writer.addRGBD(i, rgb[i], depth[i]); - } - } -#endif // HAVE_LIBARCHIVE - - stack(rgb, show); - cv::namedWindow("Cameras", cv::WINDOW_KEEPRATIO | cv::WINDOW_NORMAL); - cv::imshow("Cameras", show); - - auto key = cv::waitKey(20); - if (key == 'r') { - save = true; - } - if (key == 's') { - save = false; - } - if (key == 27) break; - } -} - -int main(int argc, char **argv) { - auto root = ftl::configure(argc, argv, "viewer_default"); - - if (root->value("stereo", false)) { - LOG(INFO) << "Stereo images mode"; - modeLeftRight(root); - } else if (root->value("video", false)) { - LOG(INFO) << "Video mode"; - modeVideo(root); - } else { - //modeVideo(root); - modeFrame(root); - } - - ftl::running = false; - return 0; -} diff --git a/applications/player/CMakeLists.txt b/applications/player/CMakeLists.txt deleted file mode 100644 index c501c8824..000000000 --- a/applications/player/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -set(PLAYERSRC - src/main.cpp -) - -add_executable(ftl-player ${PLAYERSRC}) - -target_include_directories(ftl-player PRIVATE src) - -target_link_libraries(ftl-player ftlcommon ftlcodecs ftlrgbd Threads::Threads ${OpenCV_LIBS}) - - diff --git a/applications/player/src/main.cpp b/applications/player/src/main.cpp deleted file mode 100644 index 6fd7c54ce..000000000 --- a/applications/player/src/main.cpp +++ /dev/null @@ -1,218 +0,0 @@ -#include <loguru.hpp> -#include <ftl/configuration.hpp> -#include <ftl/codecs/reader.hpp> -#include <ftl/codecs/decoder.hpp> -#include <ftl/codecs/packet.hpp> -#include <ftl/rgbd/camera.hpp> -#include <ftl/timer.hpp> - -#include <fstream> -#include <bitset> - -#include <Eigen/Eigen> - -const static std::string help[] = { - "Esc", "close", - "0-9", "change source", - "D", "toggle depth", - "S", "save screenshot", -}; - -std::string time_now_string() { - char timestamp[18]; - std::time_t t=std::time(NULL); - std::strftime(timestamp, sizeof(timestamp), "%F-%H%M%S", std::localtime(&t)); - return std::string(timestamp); -} - -using ftl::codecs::codec_t; -using ftl::codecs::Channel; - -static std::map<Channel, ftl::codecs::Decoder*> decoders; - -static void createDecoder(const Channel channel, const ftl::codecs::Packet &pkt) { - if (decoders[channel]) { - if (!decoders[channel]->accepts(pkt)) { - ftl::codecs::free(decoders[channel]); - } else { - return; - } - } - - decoders[channel] = ftl::codecs::allocateDecoder(pkt); -} - -static void visualizeDepthMap( const cv::Mat &depth, cv::Mat &out, - const float max_depth) -{ - depth.convertTo(out, CV_8U, 255.0f / max_depth); - out = 255 - out; - //cv::Mat mask = (depth >= 39.0f); // TODO (mask for invalid pixels) - - applyColorMap(out, out, cv::COLORMAP_JET); - //out.setTo(cv::Scalar(255, 255, 255), mask); -} - -static std::string nameForCodec(ftl::codecs::codec_t c) { - switch(c) { - case codec_t::JPG : return "JPEG"; - case codec_t::PNG : return "PNG"; - case codec_t::H264 : return "H264"; - case codec_t::HEVC : return "HEVC"; - case codec_t::JSON : return "JSON"; - case codec_t::POSE : return "POSE"; - case codec_t::RAW : return "RAW"; - case codec_t::CALIBRATION : return "CALIBRATION"; - case codec_t::MSGPACK : return "MSGPACK"; - default: return std::string("UNKNOWN (") + std::to_string((int)c) + std::string(")"); - } -} - -int main(int argc, char **argv) { - std::string filename(argv[1]); - LOG(INFO) << "Playing: " << filename; - - auto root = ftl::configure(argc, argv, "player_default"); - - std::ifstream f; - f.open(filename); - if (!f.is_open()) LOG(ERROR) << "Could not open file"; - - ftl::codecs::Reader r(f); - if (!r.begin()) LOG(ERROR) << "Bad ftl file"; - - LOG(INFO) << "Playing..."; - - int current_stream = 0; - int current_channel = 0; - - int stream_mask = 0; - - static volatile bool screenshot; - static int64_t screenshot_ts; - static cv::Mat screenshot_color; - static cv::Mat screenshot_depth; - - std::vector<std::bitset<128>> channel_mask; - - ftl::timer::add(ftl::timer::kTimerMain, [¤t_stream,¤t_channel,&r,&stream_mask,&channel_mask](int64_t ts) { - bool res = r.read(ts, [ts, ¤t_stream,¤t_channel,&r,&stream_mask,&channel_mask](const ftl::codecs::StreamPacket &spkt, const ftl::codecs::Packet &pkt) { - if (!(stream_mask & (1 << spkt.streamID))) { - stream_mask |= 1 << spkt.streamID; - LOG(INFO) << " - Stream found (" << (int)spkt.streamID << ")"; - - channel_mask.push_back(0); - } - - if (!(channel_mask[spkt.streamID][(int)spkt.channel])) { - channel_mask[spkt.streamID].set((int)spkt.channel); - LOG(INFO) << " - Channel " << (int)spkt.channel << " found (" << (int)spkt.streamID << ")"; - LOG(INFO) << " - Codec = " << nameForCodec(pkt.codec); - LOG(INFO) << " - Width = " << ftl::codecs::getWidth(pkt.definition); - LOG(INFO) << " - Height = " << ftl::codecs::getHeight(pkt.definition); - LOG(INFO) << " - Start Time = " << float(spkt.timestamp - r.getStartTime()) / 1000.0f << "(s)"; - LOG(INFO) << " - Blocks = " << (int)pkt.block_total; - } - - if (spkt.streamID != current_stream) { return; } - - if (pkt.codec == codec_t::POSE) { - Eigen::Matrix4d p = Eigen::Map<Eigen::Matrix4d>((double*)pkt.data.data()); - LOG(INFO) << "Have pose: " << p; - return; - } - - if (pkt.codec == codec_t::CALIBRATION) { - ftl::rgbd::Camera *camera = (ftl::rgbd::Camera*)pkt.data.data(); - LOG(INFO) << "Have calibration: " << camera->fx; - return; - } - - auto channel = static_cast<ftl::codecs::Channel>(current_channel); - if (pkt.codec == ftl::codecs::codec_t::MSGPACK) { return; } - //LOG(INFO) << "Reading packet: (" << (int)spkt.streamID << "," << (int)spkt.channel << ") " << (int)pkt.codec << ", " << (int)pkt.definition; - - cv::cuda::GpuMat gframe(cv::Size(ftl::codecs::getWidth(pkt.definition),ftl::codecs::getHeight(pkt.definition)), (spkt.channel == Channel::Depth) ? CV_32F : CV_8UC3); - cv::Mat frame; - createDecoder(spkt.channel, pkt); - - try { - decoders[spkt.channel]->decode(pkt, gframe); - gframe.download(frame); - } catch (std::exception &e) { - LOG(INFO) << "Decoder exception: " << e.what(); - } - - if (screenshot) { - if (!screenshot_depth.empty() && !screenshot_color.empty()) { - std::string fname = time_now_string(); - LOG(INFO) << "Screenshot saved: " << fname; - cv::imwrite(fname + "-depth.tiff", screenshot_depth); - cv::imwrite(fname + "-color.tiff", screenshot_color); - screenshot = false; - screenshot_color = cv::Mat(); - screenshot_depth = cv::Mat(); - screenshot_ts = 0; - } - else { - if (screenshot_ts != ts) { - screenshot_ts = ts; - screenshot_color = cv::Mat(); - screenshot_depth = cv::Mat(); - } - if (spkt.channel == Channel::Colour) { - frame.copyTo(screenshot_color); - } - else if (spkt.channel == Channel::Depth) { - frame.copyTo(screenshot_depth); - } - } - } - - if (spkt.channel != channel) return; - - if (!frame.empty()) { - if (spkt.channel == Channel::Depth) { - visualizeDepthMap(frame, frame, 8.0f); - } - double time = (double)(spkt.timestamp - r.getStartTime()) / 1000.0; - cv::putText(frame, std::string("Time: ") + std::to_string(time) + std::string("s"), cv::Point(10,20), cv::FONT_HERSHEY_PLAIN, 1, cv::Scalar(0,0,255)); - - // hotkey help text - for (int i = 0; i < std::size(help); i += 2) { - cv::putText(frame, help[i], cv::Point(10, 40+(i/2)*14), cv::FONT_HERSHEY_PLAIN, 1, cv::Scalar(64,64,255)); - cv::putText(frame, help[i+1], cv::Point(50, 40+(i/2)*14), cv::FONT_HERSHEY_PLAIN, 1, cv::Scalar(64,64,255)); - } - - cv::imshow("Player", frame); - } else { - frame.create(cv::Size(600,600), CV_8UC3); - cv::imshow("Player", frame); - } - int key = cv::waitKey(1); - if (key >= 48 && key <= 57) { - int new_stream = key - 48; - if ((0 <= new_stream) && (new_stream < channel_mask.size())) { - current_stream = new_stream; - } - } else if (key == 'd') { - current_channel = (current_channel == 0) ? 1 : 0; - } else if (key == 'r') { - current_channel = (current_channel == 0) ? 2 : 0; - } else if (key == 27) { - ftl::timer::stop(false); - } else if (key == 115) { - screenshot = true; - } - }); - if (!res) ftl::timer::stop(false); - return res; - }); - - ftl::timer::start(true); - - r.end(); - - ftl::running = false; - return 0; -} diff --git a/applications/recorder/CMakeLists.txt b/applications/recorder/CMakeLists.txt deleted file mode 100644 index 0d7b668c8..000000000 --- a/applications/recorder/CMakeLists.txt +++ /dev/null @@ -1,16 +0,0 @@ -set(RECSRC - src/main.cpp - src/registration.cpp -) - -add_executable(ftl-record ${RECSRC}) - -target_include_directories(ftl-record PUBLIC - $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> - $<INSTALL_INTERFACE:include> - PRIVATE src) - -#target_include_directories(cv-node PUBLIC ${PROJECT_SOURCE_DIR}/include) -target_link_libraries(ftl-record ftlcommon ftlrgbd Threads::Threads ${OpenCV_LIBS} ftlctrl ftlnet) - - diff --git a/applications/recorder/src/main.cpp b/applications/recorder/src/main.cpp deleted file mode 100644 index 267c03feb..000000000 --- a/applications/recorder/src/main.cpp +++ /dev/null @@ -1,221 +0,0 @@ -/* - * Copyright 2019 Nicolas Pope. All rights reserved. - * - * See LICENSE. - */ - -#define LOGURU_WITH_STREAMS 1 -#include <loguru.hpp> -#include <ftl/config.h> -#include <ftl/configuration.hpp> -#include <ftl/rgbd.hpp> -#include <ftl/rgbd/virtual.hpp> -#include <ftl/rgbd/streamer.hpp> -#include <ftl/master.hpp> -#include <ftl/rgbd/group.hpp> -#include <ftl/threads.hpp> -#include <ftl/codecs/writer.hpp> - - -#include <fstream> -#include <string> -#include <vector> -#include <thread> -#include <chrono> - -#include <opencv2/opencv.hpp> -#include <ftl/net/universe.hpp> - -#include "registration.hpp" - -#include <cuda_profiler_api.h> - -#ifdef WIN32 -#pragma comment(lib, "Rpcrt4.lib") -#endif - -using ftl::net::Universe; -using std::string; -using std::vector; -using ftl::rgbd::Source; -using ftl::config::json_t; -using ftl::codecs::Channel; - -using json = nlohmann::json; -using std::this_thread::sleep_for; -using std::chrono::milliseconds; -//using std::mutex; -//using std::unique_lock; - -//using cv::Mat; - -using ftl::registration::loadTransformations; -using ftl::registration::saveTransformations; - -static Eigen::Affine3d create_rotation_matrix(float ax, float ay, float az) { - Eigen::Affine3d rx = - Eigen::Affine3d(Eigen::AngleAxisd(ax, Eigen::Vector3d(1, 0, 0))); - Eigen::Affine3d ry = - Eigen::Affine3d(Eigen::AngleAxisd(ay, Eigen::Vector3d(0, 1, 0))); - Eigen::Affine3d rz = - Eigen::Affine3d(Eigen::AngleAxisd(az, Eigen::Vector3d(0, 0, 1))); - return rz * rx * ry; -} - -static void run(ftl::Configurable *root) { - Universe *net = ftl::create<Universe>(root, "net"); - ftl::ctrl::Master ctrl(root, net); - - // Controls - auto *controls = ftl::create<ftl::Configurable>(root, "controls"); - - net->start(); - net->waitConnections(); - - // Create a vector of all input RGB-Depth sources - auto sources = ftl::createArray<Source>(root, "sources", net); - - if (sources.size() == 0) { - LOG(ERROR) << "No sources configured!"; - return; - } - - // Create scene transform, intended for axis aligning the walls and floor - Eigen::Matrix4d transform; - if (root->getConfig()["transform"].is_object()) { - auto &c = root->getConfig()["transform"]; - float rx = c.value("pitch", 0.0f); - float ry = c.value("yaw", 0.0f); - float rz = c.value("roll", 0.0f); - float x = c.value("x", 0.0f); - float y = c.value("y", 0.0f); - float z = c.value("z", 0.0f); - - Eigen::Affine3d r = create_rotation_matrix(rx, ry, rz); - Eigen::Translation3d trans(Eigen::Vector3d(x,y,z)); - Eigen::Affine3d t(trans); - transform = t.matrix() * r.matrix(); - LOG(INFO) << "Set transform: " << transform; - } else { - transform.setIdentity(); - } - - // Must find pose for each source... - if (sources.size() > 1) { - std::map<std::string, Eigen::Matrix4d> transformations; - - if (loadTransformations(string(FTL_LOCAL_CONFIG_ROOT) + "/registration.json", transformations)) { - LOG(INFO) << "Loaded camera trasformations from file"; - } - else { - LOG(ERROR) << "Error loading camera transformations from file"; - } - - for (auto &input : sources) { - string uri = input->getURI(); - auto T = transformations.find(uri); - if (T == transformations.end()) { - LOG(ERROR) << "Camera pose for " + uri + " not found in transformations"; - //LOG(WARNING) << "Using only first configured source"; - // TODO: use target source if configured and found - //sources = { sources[0] }; - //sources[0]->setPose(Eigen::Matrix4d::Identity()); - //break; - input->setPose(transform * input->getPose()); - continue; - } - input->setPose(transform * T->second); - } - } - - ftl::rgbd::FrameSet scene_A; // Output of align process - ftl::rgbd::FrameSet scene_B; // Input of render process - - ftl::rgbd::Streamer *stream = ftl::create<ftl::rgbd::Streamer>(root, "stream", net); - ftl::rgbd::Group *group = new ftl::rgbd::Group; - - for (size_t i=0; i<sources.size(); i++) { - Source *in = sources[i]; - in->setChannel(Channel::Right); - group->addSource(in); - } - - // ---- Recording code ----------------------------------------------------- - - std::ofstream fileout; - ftl::codecs::Writer writer(fileout); - auto recorder = [&writer,&group](ftl::rgbd::Source *src, const ftl::codecs::StreamPacket &spkt, const ftl::codecs::Packet &pkt) { - ftl::codecs::StreamPacket s = spkt; - // Patch stream ID to match order in group - s.streamID = group->streamID(src); - - - //LOG(INFO) << "Record packet: " << (int)s.streamID << "," << s.timestamp; - writer.write(s, pkt); - }; - group->addRawCallback(std::function(recorder)); - - root->set("record", false); - - // Allow stream recording - root->on("record", [&group,&fileout,&writer,&recorder](const ftl::config::Event &e) { - if (e.entity->value("record", false)) { - char timestamp[18]; - std::time_t t=std::time(NULL); - std::strftime(timestamp, sizeof(timestamp), "%F-%H%M%S", std::localtime(&t)); - fileout.open(std::string(timestamp) + ".ftl"); - - writer.begin(); - LOG(INFO) << "Writer begin"; - - // TODO: Write pose+calibration+config packets - auto sources = group->sources(); - for (int i=0; i<sources.size(); ++i) { - //writeSourceProperties(writer, i, sources[i]); - sources[i]->inject(Channel::Calibration, sources[i]->parameters(), Channel::Left, sources[i]->getCapabilities()); - sources[i]->inject(sources[i]->getPose()); - } - } else { - //group->removeRawCallback(recorder); - LOG(INFO) << "Writer end"; - writer.end(); - fileout.close(); - } - }); - - // ------------------------------------------------------------------------- - - stream->add(group); - stream->run(); - - bool busy = false; - - group->setName("ReconGroup"); - group->onFrameSet([](ftl::rgbd::FrameSet &fs) -> bool { - return true; - }); - - LOG(INFO) << "Start timer"; - ftl::timer::start(true); - - LOG(INFO) << "Shutting down..."; - ftl::timer::stop(); - ctrl.stop(); - net->shutdown(); - ftl::pool.stop(); - - cudaProfilerStop(); - - LOG(INFO) << "Deleting..."; - - delete stream; - delete net; - delete group; - - ftl::config::cleanup(); // Remove any last configurable objects. - LOG(INFO) << "Done."; -} - -int main(int argc, char **argv) { - run(ftl::configure(argc, argv, "reconstruction_default")); -} diff --git a/applications/recorder/src/registration.cpp b/applications/recorder/src/registration.cpp deleted file mode 100644 index a86f2b3d1..000000000 --- a/applications/recorder/src/registration.cpp +++ /dev/null @@ -1,69 +0,0 @@ -#include "registration.hpp" -#include <fstream> -#define LOGURU_WITH_STREAMS 1 -#include <loguru.hpp> - - -namespace ftl { -namespace registration { - -using ftl::rgbd::Camera; -using ftl::rgbd::Source; - -using std::string; -using std::vector; -using std::pair; -using std::map; -using std::optional; - -using cv::Mat; -using Eigen::Matrix4f; -using Eigen::Matrix4d; - -void from_json(nlohmann::json &json, map<string, Matrix4d> &transformations) { - for (auto it = json.begin(); it != json.end(); ++it) { - Eigen::Matrix4d m; - auto data = m.data(); - for(size_t i = 0; i < 16; i++) { data[i] = it.value()[i]; } - transformations[it.key()] = m; - } -} - -void to_json(nlohmann::json &json, map<string, Matrix4d> &transformations) { - for (auto &item : transformations) { - auto val = nlohmann::json::array(); - for(size_t i = 0; i < 16; i++) { val.push_back((float) item.second.data()[i]); } - json[item.first] = val; - } -} - -bool loadTransformations(const string &path, map<string, Matrix4d> &data) { - std::ifstream file(path); - if (!file.is_open()) { - LOG(ERROR) << "Error loading transformations from file " << path; - return false; - } - - nlohmann::json json_registration; - file >> json_registration; - from_json(json_registration, data); - return true; -} - -bool saveTransformations(const string &path, map<string, Matrix4d> &data) { - nlohmann::json data_json; - to_json(data_json, data); - std::ofstream file(path); - - if (!file.is_open()) { - LOG(ERROR) << "Error writing transformations to file " << path; - return false; - } - - file << std::setw(4) << data_json; - return true; -} - - -} // namespace registration -} // namespace ftl diff --git a/applications/recorder/src/registration.hpp b/applications/recorder/src/registration.hpp deleted file mode 100644 index 1af4de8a5..000000000 --- a/applications/recorder/src/registration.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef _FTL_RECONSTRUCT_REGISTRATION_HPP_ -#define _FTL_RECONSTRUCT_REGISTRATION_HPP_ - -#include <ftl/config.h> -#include <ftl/configurable.hpp> -#include <ftl/rgbd.hpp> -#include <opencv2/opencv.hpp> - - -namespace ftl { -namespace registration { - -void to_json(nlohmann::json &json, std::map<std::string, Eigen::Matrix4d> &transformations); -void from_json(nlohmann::json &json, std::map<std::string, Eigen::Matrix4d> &transformations); - -bool loadTransformations(const std::string &path, std::map<std::string, Eigen::Matrix4d> &data); -bool saveTransformations(const std::string &path, std::map<std::string, Eigen::Matrix4d> &data); - -} -} - -#endif // _FTL_RECONSTRUCT_REGISTRATION_HPP_ \ No newline at end of file -- GitLab