From 4afea678a5ed785c0559dc513dccf1db26927187 Mon Sep 17 00:00:00 2001 From: Nicolas Pope <nwpope@utu.fi> Date: Tue, 27 Oct 2020 09:35:26 +0200 Subject: [PATCH] Image display utility function --- components/common/cpp/CMakeLists.txt | 1 + .../cpp/include/ftl/utility/image_debug.hpp | 23 ++++++++++++ .../common/cpp/src/utility/image_debug.cpp | 36 +++++++++++++++++++ .../operators/src/disparity/fixstars_sgm.cpp | 3 ++ 4 files changed, 63 insertions(+) create mode 100644 components/common/cpp/include/ftl/utility/image_debug.hpp create mode 100644 components/common/cpp/src/utility/image_debug.cpp diff --git a/components/common/cpp/CMakeLists.txt b/components/common/cpp/CMakeLists.txt index 69eaa3908..5541d5b96 100644 --- a/components/common/cpp/CMakeLists.txt +++ b/components/common/cpp/CMakeLists.txt @@ -14,6 +14,7 @@ set(COMMONSRC src/exception.cpp src/file.cpp src/utility/base64.cpp + src/utility/image_debug.cpp ) check_function_exists(uriParseSingleUriA HAVE_URIPARSESINGLE) diff --git a/components/common/cpp/include/ftl/utility/image_debug.hpp b/components/common/cpp/include/ftl/utility/image_debug.hpp new file mode 100644 index 000000000..5547e6f01 --- /dev/null +++ b/components/common/cpp/include/ftl/utility/image_debug.hpp @@ -0,0 +1,23 @@ +#ifndef _FTL_UTILITY_IMAGE_DEBUG_HPP_ +#define _FTL_UTILITY_IMAGE_DEBUG_HPP_ + +namespace ftl { +namespace utility { + +enum class ImageVisualisation { + RAW_COLOUR, + RAW_GRAY, + NORMALISED_FLOAT, + HEAT_MAPPED +}; + +void show_image( + const cv::cuda::GpuMat &m, + const std::string &name, + float scale, + ImageVisualisation iv); + +} +} + +#endif \ No newline at end of file diff --git a/components/common/cpp/src/utility/image_debug.cpp b/components/common/cpp/src/utility/image_debug.cpp new file mode 100644 index 000000000..d9321e8a6 --- /dev/null +++ b/components/common/cpp/src/utility/image_debug.cpp @@ -0,0 +1,36 @@ +#include <ftl/utility/image_debug.hpp> + +#include <opencv2/core.hpp> +#include <opencv2/imgproc.hpp> +#include <opencv2/cudaimgproc.hpp> +#include <opencv2/highgui.hpp> + +void ftl::utility::show_image( + const cv::cuda::GpuMat &m, + const std::string &name, + float scale, + ImageVisualisation iv +) { + cv::Mat tmp; + m.download(tmp); + + if (scale != 1.0f) { + cv::resize(tmp, tmp, cv::Size(float(tmp.cols)*scale, float(tmp.rows)*scale)); + } + + // Must do some conversion. + if (tmp.type() == CV_32F) { + + } + + if (iv == ftl::utility::ImageVisualisation::HEAT_MAPPED) { + #if OPENCV_VERSION >= 40102 + cv::applyColorMap(tmp, tmp, cv::COLORMAP_TURBO); + #else + cv::applyColorMap(tmp, tmp, cv::COLORMAP_INFERNO); + #endif + } + + cv::imshow(name, tmp); + cv::waitKey(1); +} diff --git a/components/operators/src/disparity/fixstars_sgm.cpp b/components/operators/src/disparity/fixstars_sgm.cpp index 5604f134c..acd468f24 100644 --- a/components/operators/src/disparity/fixstars_sgm.cpp +++ b/components/operators/src/disparity/fixstars_sgm.cpp @@ -2,6 +2,7 @@ #include "ftl/operators/disparity.hpp" #include <ftl/operators/cuda/disparity.hpp> +#include <ftl/utility/image_debug.hpp> #include <opencv2/cudaimgproc.hpp> #include <opencv2/cudaarithm.hpp> @@ -215,6 +216,8 @@ bool FixstarsSGM::apply(Frame &in, Frame &out, cudaStream_t stream) { cv::cuda::normalize(weightsF_, weightsF_, minweight, 1.0, cv::NORM_MINMAX, -1, cv::noArray(), cvstream); weightsF_.convertTo(weights_, CV_8UC1, 255.0f, cvstream); + //ftl::utility::show_image(weights_, "VarWeight", 0.5f, ftl::utility::ImageVisualisation::HEAT_MAPPED); + //if ((int)P2_map_.step != P2_map_.cols) LOG(ERROR) << "P2 map step error: " << P2_map_.cols << "," << P2_map_.step; ssgm_->execute(lbw_.data, rbw_.data, disp_int_.data, P2_map_.data, (uint8_t*) weights_.data, weights_.step1(), config()->value("min_disp", 60), stream); } else { -- GitLab