Skip to content
Snippets Groups Projects
Commit 51570f47 authored by Sebastian Hahta's avatar Sebastian Hahta
Browse files

calculate depth at different resoltuion

parent 4ece34db
No related branches found
No related tags found
1 merge request!196High resolution colour
Pipeline #16755 passed
......@@ -8,7 +8,6 @@
#include "ftl/operators/opticalflow.hpp"
#endif
#include "ftl/operators/smoothing.hpp"
#include "ftl/operators/colours.hpp"
#include "ftl/operators/normals.hpp"
......@@ -69,10 +68,10 @@ void StereoVideoSource::init(const string &file) {
lsrc_ = ftl::create<LocalSource>(host_, "feed");
}
cv::Size size = cv::Size(lsrc_->width(), lsrc_->height());
color_size_ = cv::Size(lsrc_->width(), lsrc_->height());
frames_ = std::vector<Frame>(2);
calib_ = ftl::create<Calibrate>(host_, "calibration", size, stream_);
calib_ = ftl::create<Calibrate>(host_, "calibration", color_size_, stream_);
if (!calib_->isCalibrated()) LOG(WARNING) << "Cameras are not calibrated!";
// Generate camera parameters from camera matrix
......@@ -131,6 +130,9 @@ void StereoVideoSource::init(const string &file) {
pipeline_input_->append<ftl::operators::NVOpticalFlow>("optflow");
#endif
depth_size_ = cv::Size( host_->value("width", color_size_.width),
host_->value("height", color_size_.height));
pipeline_depth_ = ftl::config::create<ftl::operators::Graph>(host_, "disparity");
pipeline_depth_->append<ftl::operators::FixstarsSGM>("algorithm");
......@@ -205,8 +207,28 @@ bool StereoVideoSource::compute(int n, int b) {
}
if (chan == Channel::Depth) {
pipeline_depth_->apply(frame, frame, host_, cv::cuda::StreamAccessor::getStream(stream_));
// stereo algorithms assume input same size as output, resize if
// necessary
bool resize = (depth_size_ != color_size_);
if (resize) {
cv::cuda::GpuMat &left = frame.get<cv::cuda::GpuMat>(Channel::Left);
cv::cuda::GpuMat &right = frame.get<cv::cuda::GpuMat>(Channel::Right);
std::swap(fullres_left_, left);
std::swap(fullres_right_, right);
cv::cuda::resize(fullres_left_, left, depth_size_, 0.0, 0.0, cv::INTER_CUBIC, stream_);
cv::cuda::resize(fullres_right_, right, depth_size_, 0.0, 0.0, cv::INTER_CUBIC, stream_);
}
pipeline_depth_->apply(frame, frame, host_, cv::cuda::StreamAccessor::getStream(stream_));
stream_.waitForCompletion();
if (resize) {
cv::cuda::GpuMat &left = frame.get<cv::cuda::GpuMat>(Channel::Left);
cv::cuda::GpuMat &right = frame.get<cv::cuda::GpuMat>(Channel::Right);
std::swap(fullres_left_, left);
std::swap(fullres_right_, right);
}
host_->notify(timestamp_,
frame.get<cv::cuda::GpuMat>(Channel::Left),
frame.get<cv::cuda::GpuMat>(Channel::Depth));
......
......@@ -38,9 +38,15 @@ class StereoVideoSource : public detail::Source {
LocalSource *lsrc_;
Calibrate *calib_;
cv::Size color_size_;
cv::Size depth_size_;
ftl::operators::Graph *pipeline_input_;
ftl::operators::Graph *pipeline_depth_;
cv::cuda::GpuMat fullres_left_;
cv::cuda::GpuMat fullres_right_;
bool ready_;
cv::cuda::Stream stream_;
......
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