From 6053c5f5c3ab0b1e93e6e18d361b158578aa2219 Mon Sep 17 00:00:00 2001 From: Sebastian Hahta <joseha@utu.fi> Date: Mon, 20 Jan 2020 15:30:17 +0200 Subject: [PATCH] RPC: set_intrinsics --- applications/calibration-multi/src/main.cpp | 30 ++++++++++--------- .../src/sources/stereovideo/stereovideo.cpp | 8 ++--- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/applications/calibration-multi/src/main.cpp b/applications/calibration-multi/src/main.cpp index 7256c48fe..d8f20041f 100644 --- a/applications/calibration-multi/src/main.cpp +++ b/applications/calibration-multi/src/main.cpp @@ -126,7 +126,6 @@ bool setRectifyRPC(ftl::net::Universe* net, ftl::stream::Net* nstream, bool enab bool setIntrinsicsRPC(ftl::net::Universe* net, ftl::stream::Net* nstream, Size size, vector<Mat> K, vector<Mat> D) { Mat K0 = K[0].t(); Mat K1 = K[1].t(); - return net->call<bool>( nstream->getPeer(), "set_intrinsics", vector<int>{size.width, size.height}, vector<double>(K0.begin<double>(), K0.end<double>()), @@ -208,19 +207,19 @@ void calibrateRPC( ftl::net::Universe* net, auto *nstream = nstreams[c/2]; while(true) { try { - /*setIntrinsicsRPC(net, nstream, + setIntrinsicsRPC(net, nstream, params.size, vector<Mat>{calib.getCameraMat(c), calib.getCameraMat(c+1)}, vector<Mat>{calib.getDistCoeffs(c), calib.getDistCoeffs(c+1)} - );*/ + ); setExtrinsicsRPC(net, nstream, R_c1c2, T_c1c2); setPoseRPC(net, nstream, Rt_out[c]); saveCalibrationRPC(net, nstream); LOG(INFO) << "CALIBRATION SENT"; break; } - catch (...) { - LOG(ERROR) << "RPC failed!"; + catch (std::exception ex) { + LOG(ERROR) << "RPC failed: " << ex.what(); sleep(1); } } @@ -315,15 +314,18 @@ void runCameraCalibration( ftl::Configurable* root, } for (auto *nstream: nstreams) { - bool res = false; - try { res = setRectifyRPC(net, nstream, false); } - catch (...) {} - - if (!res) { - LOG(ERROR) << "set_rectify() failed for " << *(nstream->get<string>("uri")); - } - else { - LOG(INFO) << "rectification disabled for " << *(nstream->get<string>("uri")); + bool res = true; + while(res) { + try { res = setRectifyRPC(net, nstream, false); } + catch (...) {} + + if (res) { + LOG(ERROR) << "set_rectify() failed for " << *(nstream->get<string>("uri")); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + } + else { + LOG(INFO) << "rectification disabled for " << *(nstream->get<string>("uri")); + } } } diff --git a/components/rgbd-sources/src/sources/stereovideo/stereovideo.cpp b/components/rgbd-sources/src/sources/stereovideo/stereovideo.cpp index b5b2ae2db..b28fed8de 100644 --- a/components/rgbd-sources/src/sources/stereovideo/stereovideo.cpp +++ b/components/rgbd-sources/src/sources/stereovideo/stereovideo.cpp @@ -123,8 +123,8 @@ void StereoVideoSource::init(const string &file) { host_->getNet()->bind("set_intrinsics", [this]( std::vector<int> size, - std::vector<double> camera_l, std::vector<double> d_left, - std::vector<double> camera_r, std::vector<double> d_right) { + std::vector<double> camera_l, std::vector<double> dist_l, + std::vector<double> camera_r, std::vector<double> dist_r) { if ((size.size() != 2) || (camera_l.size() != 9) || (camera_r.size() != 9)) { LOG(ERROR) << "bad intrinsic parameters (wrong size)"; return false; @@ -132,8 +132,8 @@ void StereoVideoSource::init(const string &file) { cv::Size calib_size(size[0], size[1]); cv::Mat K_l = cv::Mat(camera_l).reshape(1, 3).t(); cv::Mat K_r = cv::Mat(camera_r).reshape(1, 3).t(); - cv::Mat D_l = cv::Mat(D_l); - cv::Mat D_r = cv::Mat(D_r); + cv::Mat D_l = cv::Mat(dist_l); + cv::Mat D_r = cv::Mat(dist_r); if (!calib_->setIntrinsics(calib_size, {K_l, K_r}, {D_l, D_r})) { LOG(ERROR) << "bad intrinsic parameters (bad values)"; -- GitLab