[PP GAPI] - Generic precision conversion kernel; support for U8 (#2076)
- added U8 support - tests are extended
This commit is contained in:
parent
8b87e1a477
commit
f86d930e3f
@ -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<p_f, supported_types_n>;
|
||||
|
||||
constexpr std::array<table_string_t, supported_types_n> func_table = {
|
||||
table_string_t{convert_precision<uint16_t, uint16_t>, convert_precision<uint16_t, float>},
|
||||
table_string_t{convert_precision<float, uint16_t>, convert_precision<float, float>}
|
||||
table_string_t{convert_precision<uint16_t, uint16_t>, convert_precision<uint16_t, float>, convert_precision<uint16_t, uint8_t>},
|
||||
table_string_t{convert_precision<float, uint16_t>, convert_precision<float, float>, convert_precision<float, uint8_t>},
|
||||
table_string_t{convert_precision<uint8_t, uint16_t>, convert_precision<uint8_t, float>, convert_precision<uint8_t, uint8_t>}
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
@ -145,8 +145,8 @@ namespace gapi {
|
||||
|
||||
G_TYPED_KERNEL(ConvertDepth, <cv::GMat(cv::GMat, int depth)>, "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);
|
||||
}
|
||||
|
@ -24,6 +24,7 @@
|
||||
|
||||
#include <climits>
|
||||
#include <cstdint>
|
||||
#include <limits>
|
||||
|
||||
#if defined(__GNUC__) && (__GNUC__ <= 5)
|
||||
#include <cmath>
|
||||
@ -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<short>(static_cast<int>(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<uint16_t>(static_cast<int>(std::rint(x))); }
|
||||
template<> inline uchar saturate_cast<uchar>(int v) { return (uchar)((unsigned)v <= UCHAR_MAX ? v : v > 0 ? UCHAR_MAX : 0); }
|
||||
template<> inline uchar saturate_cast<uchar>(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<uint8_t>; return std::min(static_cast<uint16_t>(lim::max()), std::max(static_cast<uint16_t>(lim::min()), x));}
|
||||
template<> inline uint8_t saturate_cast(float x) { return saturate_cast<uint8_t>(static_cast<int>(std::rint(x))); }
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
constexpr static const int ONE = 1 << 15;
|
||||
|
@ -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),
|
||||
|
Loading…
Reference in New Issue
Block a user