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

Add colour channels filter

parent f4f498fd
No related branches found
No related tags found
1 merge request!158Implements #228 adaptive MLS and smoothing channel
Pipeline #16129 passed
This commit is part of merge request !158. Comments created here will be created in the context of that merge request.
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include <ftl/net/universe.hpp> #include <ftl/net/universe.hpp>
#include <ftl/filters/smoothing.hpp> #include <ftl/filters/smoothing.hpp>
#include <ftl/filters/colours.hpp>
#include <ftl/cuda/normals.hpp> #include <ftl/cuda/normals.hpp>
#include <ftl/registration.hpp> #include <ftl/registration.hpp>
...@@ -248,6 +249,7 @@ static void run(ftl::Configurable *root) { ...@@ -248,6 +249,7 @@ static void run(ftl::Configurable *root) {
// Create the source depth map filters // Create the source depth map filters
auto *filters = ftl::config::create<ftl::Filters>(root, "filters"); auto *filters = ftl::config::create<ftl::Filters>(root, "filters");
filters->create<ftl::filters::ColourChannels>("colour");
filters->create<ftl::filters::DepthSmoother>("hfnoise"); filters->create<ftl::filters::DepthSmoother>("hfnoise");
filters->create<ftl::filters::MLSSmoother>("mls"); filters->create<ftl::filters::MLSSmoother>("mls");
...@@ -275,51 +277,12 @@ static void run(ftl::Configurable *root) { ...@@ -275,51 +277,12 @@ static void run(ftl::Configurable *root) {
UNIQUE_LOCK(scene_A.mtx, lk); UNIQUE_LOCK(scene_A.mtx, lk);
cv::cuda::GpuMat tmp; // Apply pre-filters to all frames
/*float factor = filter->value("smooth_factor", 0.4f); for (int i=0; i<scene_A.frames.size(); ++i) {
float colour_limit = filter->value("colour_limit", 30.0f); auto &f = scene_A.frames[i];
bool do_smooth = filter->value("pre_smooth", false); auto s = scene_A.sources[i];
int iters = filter->value("iterations", 3); filters->filter(f, s, 0);
int radius = filter->value("radius", 5); }
float var_thesh = filter->value("variance_threshold", 0.02f);*/
//if (do_smooth) {
// Presmooth...
for (int i=0; i<scene_A.frames.size(); ++i) {
auto &f = scene_A.frames[i];
auto s = scene_A.sources[i];
// Convert colour from BGR to BGRA if needed
if (f.get<cv::cuda::GpuMat>(Channel::Colour).type() == CV_8UC3) {
//cv::cuda::Stream cvstream = cv::cuda::StreamAccessor::wrapStream(stream);
// Convert to 4 channel colour
auto &col = f.get<cv::cuda::GpuMat>(Channel::Colour);
tmp.create(col.size(), CV_8UC4);
cv::cuda::swap(col, tmp);
cv::cuda::cvtColor(tmp,col, cv::COLOR_BGR2BGRA, 0);
}
filters->filter(f, s, 0);
/*ftl::cuda::smoothing_factor(
f.createTexture<float>(Channel::Depth),
f.createTexture<float>(Channel::Depth2, ftl::rgbd::Format<float>(f.get<cv::cuda::GpuMat>(Channel::Depth).size())),
f.createTexture<float>(Channel::Energy, ftl::rgbd::Format<float>(f.get<cv::cuda::GpuMat>(Channel::Depth).size())),
//f.createTexture<uchar4>(Channel::Colour),
f.createTexture<float>(Channel::Smoothing, ftl::rgbd::Format<float>(f.get<cv::cuda::GpuMat>(Channel::Depth).size())),
var_thesh,
s->parameters(), 0
);*/
/*ftl::cuda::depth_smooth(
f.createTexture<float>(Channel::Depth),
f.createTexture<uchar4>(Channel::Colour),
f.createTexture<float>(Channel::Depth2, ftl::rgbd::Format<float>(f.get<cv::cuda::GpuMat>(Channel::Depth).size())),
s->parameters(),
radius, factor, colour_limit, iters, 0
);*/
}
//}
// Send all frames to GPU, block until done? // Send all frames to GPU, block until done?
//scene_A.upload(Channel::Colour + Channel::Depth); // TODO: (Nick) Add scene stream. //scene_A.upload(Channel::Colour + Channel::Depth); // TODO: (Nick) Add scene stream.
......
...@@ -2,6 +2,7 @@ add_library(ftlfilter ...@@ -2,6 +2,7 @@ add_library(ftlfilter
src/smoothing.cpp src/smoothing.cpp
src/smoothing.cu src/smoothing.cu
src/filter.cpp src/filter.cpp
src/colours.cpp
) )
# These cause errors in CI build and are being removed from PCL in newer versions # These cause errors in CI build and are being removed from PCL in newer versions
......
#ifndef _FTL_FILTERS_COLOURS_HPP_
#define _FTL_FILTERS_COLOURS_HPP_
#include <ftl/filters/filter.hpp>
namespace ftl {
namespace filters {
class ColourChannels : public ftl::Filter {
public:
explicit ColourChannels(nlohmann::json &config);
~ColourChannels();
void filter(ftl::rgbd::Frame &frame, ftl::rgbd::Source *src, cudaStream_t stream) override;
private:
cv::cuda::GpuMat temp_;
};
}
}
#endif // _FTL_FILTERS_COLOURS_HPP_
#ifndef _FTL_FILTERS_FILTER_HPP_ #ifndef _FTL_FILTERS_FILTER_HPP_
#define _FTL_FILTERS_FILTER_HPP_
#include <list> #include <list>
#include <ftl/configurable.hpp> #include <ftl/configurable.hpp>
......
#include <ftl/filters/colours.hpp>
using ftl::filters::ColourChannels;
using ftl::codecs::Channel;
ColourChannels::ColourChannels(nlohmann::json &config) : ftl::Filter(config) {
}
ColourChannels::~ColourChannels() {
}
void ColourChannels::filter(ftl::rgbd::Frame &f, ftl::rgbd::Source *s, cudaStream_t stream) {
// Convert colour from BGR to BGRA if needed
if (f.get<cv::cuda::GpuMat>(Channel::Colour).type() == CV_8UC3) {
//cv::cuda::Stream cvstream = cv::cuda::StreamAccessor::wrapStream(stream);
// Convert to 4 channel colour
auto &col = f.get<cv::cuda::GpuMat>(Channel::Colour);
temp_.create(col.size(), CV_8UC4);
cv::cuda::swap(col, temp_);
cv::cuda::cvtColor(temp_,col, cv::COLOR_BGR2BGRA, 0);
}
}
...@@ -29,6 +29,7 @@ using ftl::cuda::TextureObject; ...@@ -29,6 +29,7 @@ using ftl::cuda::TextureObject;
float contrib = 0.0f; float contrib = 0.0f;
float d0 = depth_in.tex2D(x, y); float d0 = depth_in.tex2D(x, y);
depth_out(x,y) = d0;
if (d0 < camera.minDepth || d0 > camera.maxDepth) return; if (d0 < camera.minDepth || d0 > camera.maxDepth) return;
float3 X = camera.screenToCam((int)(x),(int)(y),d0); float3 X = camera.screenToCam((int)(x),(int)(y),d0);
......
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