From: Anton Potapov Date: Wed, 9 Sep 2020 12:30:08 +0000 (+0300) Subject: [PP GAPI] - Generic precision conversion kernel; support for U8 (#2076) X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f86d930e3f105a252b1e5d27cbe64187dd723565;p=platform%2Fupstream%2Fdldt.git [PP GAPI] - Generic precision conversion kernel; support for U8 (#2076) - added U8 support - tests are extended --- diff --git a/inference-engine/src/preprocessing/ie_preprocess_gapi_kernels.cpp b/inference-engine/src/preprocessing/ie_preprocess_gapi_kernels.cpp index 654b625..e104dcf 100644 --- a/inference-engine/src/preprocessing/ie_preprocess_gapi_kernels.cpp +++ b/inference-engine/src/preprocessing/ie_preprocess_gapi_kernels.cpp @@ -2247,25 +2247,27 @@ GAPI_FLUID_KERNEL(FConvertDepth, ConvertDepth, false) { static const int Window = 1; static void run(const cv::gapi::fluid::View& src, int depth, cv::gapi::fluid::Buffer& dst) { - GAPI_Assert(src.meta().depth == CV_16U || src.meta().depth == CV_32F); - GAPI_Assert(dst.meta().depth == CV_32F || dst.meta().depth == CV_16U); + GAPI_Assert(src.meta().depth == CV_8U || src.meta().depth == CV_32F || src.meta().depth == CV_16U); + GAPI_Assert(dst.meta().depth == CV_8U || dst.meta().depth == CV_32F || dst.meta().depth == CV_16U); GAPI_Assert(src.meta().chan == 1); GAPI_Assert(dst.meta().chan == 1); GAPI_Assert(src.length() == dst.length()); - constexpr unsigned supported_types_n = 2; + constexpr unsigned supported_types_n = 3; using p_f = void (*)( const uint8_t* src, uint8_t* dst, const int width); using table_string_t = std::array; constexpr std::array func_table = { - table_string_t{convert_precision, convert_precision}, - table_string_t{convert_precision, convert_precision} + table_string_t{convert_precision, convert_precision, convert_precision}, + table_string_t{convert_precision, convert_precision, convert_precision}, + table_string_t{convert_precision, convert_precision, convert_precision} }; auto depth_to_index = [](int depth){ switch (depth) { case CV_16U: return 0; case CV_32F: return 1; + case CV_8U: return 2; default: GAPI_Assert(!"not supported depth"); return -1; } }; diff --git a/inference-engine/src/preprocessing/ie_preprocess_gapi_kernels.hpp b/inference-engine/src/preprocessing/ie_preprocess_gapi_kernels.hpp index 7b6acdb..685eae4 100644 --- a/inference-engine/src/preprocessing/ie_preprocess_gapi_kernels.hpp +++ b/inference-engine/src/preprocessing/ie_preprocess_gapi_kernels.hpp @@ -145,8 +145,8 @@ namespace gapi { G_TYPED_KERNEL(ConvertDepth, , "com.intel.ie.ConvertDepth") { static cv::GMatDesc outMeta(const cv::GMatDesc& in, int depth) { - GAPI_Assert(in.depth == CV_16U || in.depth == CV_32F); - GAPI_Assert(depth == CV_32F || depth == CV_16U); + GAPI_Assert(in.depth == CV_8U || in.depth == CV_16U || in.depth == CV_32F); + GAPI_Assert(depth == CV_8U || depth == CV_32F || depth == CV_16U); return in.withDepth(depth); } diff --git a/inference-engine/src/preprocessing/ie_preprocess_gapi_kernels_impl.hpp b/inference-engine/src/preprocessing/ie_preprocess_gapi_kernels_impl.hpp index 6d5161f..bce88e1 100644 --- a/inference-engine/src/preprocessing/ie_preprocess_gapi_kernels_impl.hpp +++ b/inference-engine/src/preprocessing/ie_preprocess_gapi_kernels_impl.hpp @@ -24,6 +24,7 @@ #include #include +#include #if defined(__GNUC__) && (__GNUC__ <= 5) #include @@ -38,12 +39,20 @@ template<> inline short saturate_cast(int x) { return (std::min)(SHRT_MAX, (std: template<> inline short saturate_cast(float x) { return saturate_cast(static_cast(std::rint(x))); } template<> inline float saturate_cast(float x) { return x; } template<> inline short saturate_cast(short x) { return x; } + template<> inline uint16_t saturate_cast(uint16_t x) { return x; } template<> inline float saturate_cast(uint16_t x) { return x; } + template<> inline uint16_t saturate_cast(int x) { return (std::min)(USHRT_MAX, (std::max)(0, x)); } template<> inline uint16_t saturate_cast(float x) { return saturate_cast(static_cast(std::rint(x))); } -template<> inline uchar saturate_cast(int v) { return (uchar)((unsigned)v <= UCHAR_MAX ? v : v > 0 ? UCHAR_MAX : 0); } +template<> inline uchar saturate_cast(int v) { return (uchar)((unsigned)v <= UCHAR_MAX ? v : v > 0 ? UCHAR_MAX : 0); } + +template<> inline uint16_t saturate_cast(uint8_t x) { return x; } +template<> inline float saturate_cast(uint8_t x) { return x; } +template<> inline uint8_t saturate_cast(uint8_t x) { return x; } +template<> inline uint8_t saturate_cast(uint16_t x) { using lim = std::numeric_limits; return std::min(static_cast(lim::max()), std::max(static_cast(lim::min()), x));} +template<> inline uint8_t saturate_cast(float x) { return saturate_cast(static_cast(std::rint(x))); } //------------------------------------------------------------------------------ constexpr static const int ONE = 1 << 15; diff --git a/inference-engine/tests_deprecated/fluid_preproc/cpu/fluid_tests_cpu.cpp b/inference-engine/tests_deprecated/fluid_preproc/cpu/fluid_tests_cpu.cpp index 954bff9..1e21638 100644 --- a/inference-engine/tests_deprecated/fluid_preproc/cpu/fluid_tests_cpu.cpp +++ b/inference-engine/tests_deprecated/fluid_preproc/cpu/fluid_tests_cpu.cpp @@ -171,8 +171,8 @@ INSTANTIATE_TEST_CASE_P(I420toRGBTestFluid, I420toRGBTestGAPI, Values(0))); INSTANTIATE_TEST_CASE_P(ConvertDepthFluid, ConvertDepthTestGAPI, - Combine(Values(CV_16U, CV_32F), - Values(CV_32F, CV_16U), + Combine(Values(CV_16U, CV_32F, CV_8U), + Values(CV_32F, CV_16U, CV_8U), Values(cv::Size(3840, 2160), cv::Size(1920, 1080), cv::Size(1280, 720),