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

Optionally use Lab colour space

parent e19d1541
No related branches found
No related tags found
2 merge requests!116Implements #133 point alignment,!114Ongoing #133 improvements
......@@ -18,6 +18,7 @@ ILW::ILW(nlohmann::json &config) : ftl::Configurable(config) {
iterations_ = value("iterations", 1);
motion_rate_ = value("motion_rate", 0.4f);
motion_window_ = value("motion_window", 3);
use_lab_ = value("use_Lab", false);
on("ilw_align", [this](const ftl::config::Event &e) {
enabled_ = value("ilw_align", true);
......@@ -35,6 +36,10 @@ ILW::ILW(nlohmann::json &config) : ftl::Configurable(config) {
motion_window_ = value("motion_window", 3);
});
on("use_Lab", [this](const ftl::config::Event &e) {
use_lab_ = value("use_Lab", false);
});
flags_ = 0;
if (value("ignore_bad", false)) flags_ |= ftl::cuda::kILWFlag_IgnoreBad;
if (value("restrict_z", true)) flags_ |= ftl::cuda::kILWFlag_RestrictZ;
......@@ -97,11 +102,13 @@ bool ILW::_phase0(ftl::rgbd::FrameSet &fs, cudaStream_t stream) {
// Convert colour from BGR to BGRA if needed
if (f.get<GpuMat>(Channel::Colour).type() == CV_8UC3) {
cv::cuda::Stream cvstream = cv::cuda::StreamAccessor::wrapStream(stream);
// Convert to 4 channel colour
auto &col = f.get<GpuMat>(Channel::Colour);
GpuMat tmp(col.size(), CV_8UC4);
cv::cuda::swap(col, tmp);
cv::cuda::cvtColor(tmp,col, cv::COLOR_BGR2BGRA);
if (use_lab_) cv::cuda::cvtColor(tmp,tmp, cv::COLOR_BGR2Lab, 0, cvstream);
cv::cuda::cvtColor(tmp,col, cv::COLOR_BGR2BGRA, 0, cvstream);
}
f.createTexture<float4>(Channel::EnergyVector, Format<float4>(f.get<GpuMat>(Channel::Colour).size()));
......
......@@ -42,6 +42,8 @@ class ILW : public ftl::Configurable {
*/
bool process(ftl::rgbd::FrameSet &fs, cudaStream_t stream=0);
inline bool isLabColour() const { return use_lab_; }
private:
/*
* Initialise data.
......@@ -64,6 +66,7 @@ class ILW : public ftl::Configurable {
int iterations_;
float motion_rate_;
int motion_window_;
bool use_lab_;
};
}
......
......@@ -137,8 +137,15 @@ static void run(ftl::Configurable *root) {
ftl::ILW *align = ftl::create<ftl::ILW>(root, "merge");
// Generate virtual camera render when requested by streamer
virt->onRender([splat,virt,&scene_B](ftl::rgbd::Frame &out) {
virt->onRender([splat,virt,&scene_B,align](ftl::rgbd::Frame &out) {
virt->setTimestamp(scene_B.timestamp);
// Do we need to convert Lab to BGR?
if (align->isLabColour()) {
for (auto &f : scene_B.frames) {
auto &col = f.get<cv::cuda::GpuMat>(Channel::Colour);
cv::cuda::cvtColor(col,col, cv::COLOR_Lab2BGR);
}
}
splat->render(virt, out);
});
stream->add(virt);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment