mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 15:53:03 +04:00
Added new data types to cv::Mat & UMat (#23865)
* started working on adding 32u, 64u, 64s, bool and 16bf types to OpenCV * core & imgproc tests seem to pass * fixed a few compile errors and test failures on macOS x86 * hopefully fixed some compile problems and test failures * fixed some more warnings and test failures * trying to fix small deviations in perf_core & perf_imgproc by revering randf_64f to exact version used before * trying to fix behavior of the new OpenCV with old plugins; there is (quite strong) assumption that video capture would give us frames with depth == CV_8U (0) or CV_16U (2). If depth is > 7 then it means that the plugin is built with the old OpenCV. It needs to be recompiled, of course and then this hack can be removed. * try to repair the case when target arch does not have FP64 SIMD * 1. fixed bug in itoa() found by alalek 2. restored ==, !=, > and < univ. intrinsics on ARM32/ARM64.
This commit is contained in:
@@ -487,9 +487,13 @@ Cv64suf;
|
||||
#define CV_SUBMAT_FLAG (1 << CV_SUBMAT_FLAG_SHIFT)
|
||||
#define CV_IS_SUBMAT(flags) ((flags) & CV_MAT_SUBMAT_FLAG)
|
||||
|
||||
/** Size of each channel item,
|
||||
0x28442211 = 0010 1000 0100 0100 0010 0010 0001 0001 ~ array of sizeof(arr_type_elem) */
|
||||
#define CV_ELEM_SIZE1(type) ((0x28442211 >> CV_MAT_DEPTH(type)*4) & 15)
|
||||
/** Size of an array/scalar single-channel value, 4 bits per type:
|
||||
CV_8U - 1 byte
|
||||
CV_8S - 1 byte
|
||||
CV_16U - 2 bytes
|
||||
...
|
||||
*/
|
||||
#define CV_ELEM_SIZE1(type) ((int)(0x4881228442211ULL >> (CV_MAT_DEPTH(type) * 4)) & 15)
|
||||
|
||||
#define CV_ELEM_SIZE(type) (CV_MAT_CN(type)*CV_ELEM_SIZE1(type))
|
||||
|
||||
@@ -963,6 +967,41 @@ protected:
|
||||
#endif
|
||||
};
|
||||
|
||||
class bfloat16_t
|
||||
{
|
||||
public:
|
||||
bfloat16_t() : w(0) {}
|
||||
explicit bfloat16_t(float x)
|
||||
{
|
||||
Cv32suf in;
|
||||
in.f = x;
|
||||
w = (ushort)(in.u >> 16);
|
||||
}
|
||||
|
||||
operator float() const
|
||||
{
|
||||
Cv32suf out;
|
||||
out.u = w << 16;
|
||||
return out.f;
|
||||
}
|
||||
|
||||
static bfloat16_t fromBits(ushort b)
|
||||
{
|
||||
bfloat16_t result;
|
||||
result.w = b;
|
||||
return result;
|
||||
}
|
||||
static bfloat16_t zero()
|
||||
{
|
||||
bfloat16_t result;
|
||||
result.w = (ushort)0;
|
||||
return result;
|
||||
}
|
||||
ushort bits() const { return w; }
|
||||
protected:
|
||||
ushort w;
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -197,9 +197,11 @@ CV_EXPORTS void addWeighted64f( const double* src1, size_t step1, const double*
|
||||
|
||||
CV_EXPORTS void cvt16f32f( const float16_t* src, float* dst, int len );
|
||||
CV_EXPORTS void cvt32f16f( const float* src, float16_t* dst, int len );
|
||||
CV_EXPORTS void cvt16bf32f( const bfloat16_t* src, float* dst, int len );
|
||||
CV_EXPORTS void cvt32f16bf( const float* src, bfloat16_t* dst, int len );
|
||||
|
||||
CV_EXPORTS void addRNGBias32f( float* arr, const float* scaleBiasPairs, int len );
|
||||
CV_EXPORTS void addRNGBias64f( double* arr, const double* scaleBiasPairs, int len );
|
||||
CV_EXPORTS void addRNGBias32f( float* arr, const float* scaleBiasPairs, int len, int cn );
|
||||
CV_EXPORTS void addRNGBias64f( double* arr, const double* scaleBiasPairs, int len, int cn );
|
||||
|
||||
struct CV_EXPORTS DFT1D
|
||||
{
|
||||
|
||||
@@ -66,8 +66,8 @@ typedef signed char schar;
|
||||
|
||||
#define CV_USRTYPE1 (void)"CV_USRTYPE1 support has been dropped in OpenCV 4.0"
|
||||
|
||||
#define CV_CN_MAX 512
|
||||
#define CV_CN_SHIFT 3
|
||||
#define CV_CN_MAX 128
|
||||
#define CV_CN_SHIFT 5
|
||||
#define CV_DEPTH_MAX (1 << CV_CN_SHIFT)
|
||||
|
||||
#define CV_8U 0
|
||||
@@ -78,9 +78,17 @@ typedef signed char schar;
|
||||
#define CV_32F 5
|
||||
#define CV_64F 6
|
||||
#define CV_16F 7
|
||||
#define CV_16BF 8
|
||||
#define CV_Bool 9
|
||||
#define CV_64U 10
|
||||
#define CV_64S 11
|
||||
#define CV_32U 12
|
||||
#define CV_DEPTH_CURR_MAX 13
|
||||
|
||||
#define CV_MAT_DEPTH_MASK (CV_DEPTH_MAX - 1)
|
||||
#define CV_MAT_DEPTH(flags) ((flags) & CV_MAT_DEPTH_MASK)
|
||||
#define CV_IS_INT_TYPE(flags) (((1 << CV_MAT_DEPTH(flags)) & 0x1e1f) != 0)
|
||||
#define CV_IS_FLOAT_TYPE(flags) (((1 << CV_MAT_DEPTH(flags)) & 0x1e0) != 0)
|
||||
|
||||
#define CV_MAKETYPE(depth,cn) (CV_MAT_DEPTH(depth) + (((cn)-1) << CV_CN_SHIFT))
|
||||
#define CV_MAKE_TYPE CV_MAKETYPE
|
||||
@@ -132,6 +140,37 @@ typedef signed char schar;
|
||||
#define CV_16FC3 CV_MAKETYPE(CV_16F,3)
|
||||
#define CV_16FC4 CV_MAKETYPE(CV_16F,4)
|
||||
#define CV_16FC(n) CV_MAKETYPE(CV_16F,(n))
|
||||
|
||||
#define CV_64SC1 CV_MAKETYPE(CV_64S,1)
|
||||
#define CV_64SC2 CV_MAKETYPE(CV_64S,2)
|
||||
#define CV_64SC3 CV_MAKETYPE(CV_64S,3)
|
||||
#define CV_64SC4 CV_MAKETYPE(CV_64S,4)
|
||||
#define CV_64SC(n) CV_MAKETYPE(CV_64S,(n))
|
||||
|
||||
#define CV_64UC1 CV_MAKETYPE(CV_64U,1)
|
||||
#define CV_64UC2 CV_MAKETYPE(CV_64U,2)
|
||||
#define CV_64UC3 CV_MAKETYPE(CV_64U,3)
|
||||
#define CV_64UC4 CV_MAKETYPE(CV_64U,4)
|
||||
#define CV_64UC(n) CV_MAKETYPE(CV_64U,(n))
|
||||
|
||||
#define CV_BoolC1 CV_MAKETYPE(CV_Bool,1)
|
||||
#define CV_BoolC2 CV_MAKETYPE(CV_Bool,2)
|
||||
#define CV_BoolC3 CV_MAKETYPE(CV_Bool,3)
|
||||
#define CV_BoolC4 CV_MAKETYPE(CV_Bool,4)
|
||||
#define CV_BoolC(n) CV_MAKETYPE(CV_Bool,(n))
|
||||
|
||||
#define CV_32UC1 CV_MAKETYPE(CV_32U,1)
|
||||
#define CV_32UC2 CV_MAKETYPE(CV_32U,2)
|
||||
#define CV_32UC3 CV_MAKETYPE(CV_32U,3)
|
||||
#define CV_32UC4 CV_MAKETYPE(CV_32U,4)
|
||||
#define CV_32UC(n) CV_MAKETYPE(CV_32U,(n))
|
||||
|
||||
#define CV_16BFC1 CV_MAKETYPE(CV_16BF,1)
|
||||
#define CV_16BFC2 CV_MAKETYPE(CV_16BF,2)
|
||||
#define CV_16BFC3 CV_MAKETYPE(CV_16BF,3)
|
||||
#define CV_16BFC4 CV_MAKETYPE(CV_16BF,4)
|
||||
#define CV_16BFC(n) CV_MAKETYPE(CV_16BF,(n))
|
||||
|
||||
//! @}
|
||||
|
||||
//! @name Comparison operation
|
||||
|
||||
@@ -720,6 +720,22 @@ namespace CV__SIMD_NAMESPACE {
|
||||
inline v_int32 vx_load_expand_q(const schar * ptr) { return VXPREFIX(_load_expand_q)(ptr); }
|
||||
//! @}
|
||||
|
||||
#ifndef OPENCV_HAL_HAVE_LOAD_STORE_BFLOAT16
|
||||
|
||||
inline v_float32 vx_load_expand(const bfloat16_t* ptr)
|
||||
{
|
||||
v_uint32 v = vx_load_expand((const ushort*)ptr);
|
||||
return v_reinterpret_as_f32(v_shl<16>(v));
|
||||
}
|
||||
|
||||
inline void v_pack_store(const bfloat16_t* ptr, v_float32 v)
|
||||
{
|
||||
v_int32 iv = v_shr<16>(v_reinterpret_as_s32(v));
|
||||
v_pack_store((short*)ptr, iv);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/** @brief SIMD processing state cleanup call */
|
||||
inline void vx_cleanup() { VXPREFIX(_cleanup)(); }
|
||||
|
||||
@@ -1095,6 +1111,10 @@ namespace CV__SIMD_NAMESPACE {
|
||||
#define CV_SIMD 0
|
||||
#endif
|
||||
|
||||
#if (!defined CV_SIMD_64F) || (!CV_SIMD_64F)
|
||||
typedef struct v_float64 { int dummy; } v_float64;
|
||||
#endif
|
||||
|
||||
#include "simd_utils.impl.hpp"
|
||||
|
||||
#ifndef CV_DOXYGEN
|
||||
|
||||
@@ -937,6 +937,11 @@ OPENCV_HAL_IMPL_AVX_CMP_OP_INT(v_uint32x8, v_int32x8, epi32, (int)0x80000000)
|
||||
inline _Tpvec operator != (const _Tpvec& a, const _Tpvec& b) \
|
||||
{ return ~(a == b); }
|
||||
|
||||
inline v_int64x4 operator > (const v_int64x4& a, const v_int64x4& b)
|
||||
{ return v_int64x4(_mm256_cmpgt_epi64(a.val, b.val)); }
|
||||
inline v_int64x4 operator < (const v_int64x4& a, const v_int64x4& b)
|
||||
{ return v_int64x4(_mm256_cmpgt_epi64(b.val, a.val)); }
|
||||
|
||||
OPENCV_HAL_IMPL_AVX_CMP_OP_64BIT(v_uint64x4)
|
||||
OPENCV_HAL_IMPL_AVX_CMP_OP_64BIT(v_int64x4)
|
||||
|
||||
@@ -3162,6 +3167,22 @@ inline void v_pack_store(float16_t* ptr, const v_float32x8& a)
|
||||
#endif
|
||||
}
|
||||
|
||||
/*#define OPENCV_HAL_HAVE_PACK_STORE_BFLOAT16 1
|
||||
|
||||
inline v_float32x8 v256_load_expand(const bfloat16_t* ptr)
|
||||
{
|
||||
__m128i bf = _mm_loadu_si128((const __m128i*)ptr);
|
||||
__m256i f = _mm256_unpacklo_epi16(_mm256_setzero_si256(), _mm256_castsi128_si256(bf));
|
||||
return v_float32x8(_mm256_castsi256_ps(f));
|
||||
}
|
||||
|
||||
inline void v_pack_store(bfloat16_t* ptr, const v_float32x8& a)
|
||||
{
|
||||
__m256i f = _mm256_castps_si256(a.val);
|
||||
f = _mm256_packs_epi32(_mm256_srai_epi32(f, 16), f);
|
||||
_mm_storeu_si128((__m128i*)ptr, _v256_extract_low(f));
|
||||
}*/
|
||||
|
||||
//
|
||||
// end of FP16
|
||||
//
|
||||
|
||||
@@ -3250,6 +3250,8 @@ template<int n> inline v_reg<double, n/2> v_dotprod_expand_fast(const v_reg<int,
|
||||
|
||||
////// FP16 support ///////
|
||||
|
||||
#define OPENCV_HAL_HAVE_PACK_STORE_BFLOAT16 1
|
||||
|
||||
inline v_reg<float, simd128_width / sizeof(float)>
|
||||
v_load_expand(const float16_t* ptr)
|
||||
{
|
||||
|
||||
@@ -1057,44 +1057,61 @@ OPENCV_HAL_IMPL_NEON_INT_CMP_OP(v_int16x8, vreinterpretq_s16_u16, s16, u16)
|
||||
OPENCV_HAL_IMPL_NEON_INT_CMP_OP(v_uint32x4, OPENCV_HAL_NOP, u32, u32)
|
||||
OPENCV_HAL_IMPL_NEON_INT_CMP_OP(v_int32x4, vreinterpretq_s32_u32, s32, u32)
|
||||
OPENCV_HAL_IMPL_NEON_INT_CMP_OP(v_float32x4, vreinterpretq_f32_u32, f32, u32)
|
||||
|
||||
#if defined(__aarch64__) || defined(_M_ARM64)
|
||||
static inline uint64x2_t vmvnq_u64(uint64x2_t a)
|
||||
{
|
||||
uint64x2_t vx = vreinterpretq_u64_u32(vdupq_n_u32(0xFFFFFFFF));
|
||||
return veorq_u64(a, vx);
|
||||
}
|
||||
//OPENCV_HAL_IMPL_NEON_INT_CMP_OP(v_uint64x2, OPENCV_HAL_NOP, u64, u64)
|
||||
//OPENCV_HAL_IMPL_NEON_INT_CMP_OP(v_int64x2, vreinterpretq_s64_u64, s64, u64)
|
||||
static inline v_uint64x2 operator == (const v_uint64x2& a, const v_uint64x2& b)
|
||||
{ return v_uint64x2(vceqq_u64(a.val, b.val)); }
|
||||
static inline v_uint64x2 operator != (const v_uint64x2& a, const v_uint64x2& b)
|
||||
{ return v_uint64x2(vmvnq_u64(vceqq_u64(a.val, b.val))); }
|
||||
static inline v_int64x2 operator == (const v_int64x2& a, const v_int64x2& b)
|
||||
{ return v_int64x2(vreinterpretq_s64_u64(vceqq_s64(a.val, b.val))); }
|
||||
static inline v_int64x2 operator != (const v_int64x2& a, const v_int64x2& b)
|
||||
{ return v_int64x2(vreinterpretq_s64_u64(vmvnq_u64(vceqq_s64(a.val, b.val)))); }
|
||||
OPENCV_HAL_IMPL_NEON_INT_CMP_OP(v_uint64x2, OPENCV_HAL_NOP, u64, u64)
|
||||
OPENCV_HAL_IMPL_NEON_INT_CMP_OP(v_int64x2, vreinterpretq_s64_u64, s64, u64)
|
||||
#else
|
||||
static inline v_uint64x2 operator == (const v_uint64x2& a, const v_uint64x2& b)
|
||||
{
|
||||
uint32x4_t cmp = vceqq_u32(vreinterpretq_u32_u64(a.val), vreinterpretq_u32_u64(b.val));
|
||||
uint32x4_t swapped = vrev64q_u32(cmp);
|
||||
return v_uint64x2(vreinterpretq_u64_u32(vandq_u32(cmp, swapped)));
|
||||
uint32x4_t cmp = vceqq_u32(vreinterpretq_u32_u64(a.val),
|
||||
vreinterpretq_u32_u64(b.val));
|
||||
uint32x4_t v_eq = vandq_u32(cmp, vrev64q_u32(cmp));
|
||||
return v_uint64x2(vreinterpretq_u64_u32(v_eq));
|
||||
}
|
||||
static inline v_uint64x2 operator != (const v_uint64x2& a, const v_uint64x2& b)
|
||||
{
|
||||
uint32x4_t cmp = vceqq_u32(vreinterpretq_u32_u64(a.val), vreinterpretq_u32_u64(b.val));
|
||||
uint32x4_t swapped = vrev64q_u32(cmp);
|
||||
uint64x2_t v_eq = vreinterpretq_u64_u32(vandq_u32(cmp, swapped));
|
||||
uint64x2_t vx = vreinterpretq_u64_u32(vdupq_n_u32(0xFFFFFFFF));
|
||||
return v_uint64x2(veorq_u64(v_eq, vx));
|
||||
uint64x2_t v_mask = vorrq_u64(vsubq_u64(a.val, b.val), vsubq_u64(b.val, a.val));
|
||||
int64x2_t v_smask = vshrq_n_s64(vreinterpretq_s64_u64(v_mask), 63);
|
||||
return v_uint64x2(vreinterpretq_u64_s64(v_smask));
|
||||
}
|
||||
static inline v_int64x2 operator == (const v_int64x2& a, const v_int64x2& b)
|
||||
{
|
||||
return v_reinterpret_as_s64(v_reinterpret_as_u64(a) == v_reinterpret_as_u64(b));
|
||||
uint32x4_t cmp = vceqq_u32(vreinterpretq_u32_s64(a.val),
|
||||
vreinterpretq_u32_s64(b.val));
|
||||
uint32x4_t v_eq = vandq_u32(cmp, vrev64q_u32(cmp));
|
||||
return v_int64x2(vreinterpretq_s64_u32(v_eq));
|
||||
}
|
||||
static inline v_int64x2 operator != (const v_int64x2& a, const v_int64x2& b)
|
||||
{
|
||||
return v_reinterpret_as_s64(v_reinterpret_as_u64(a) != v_reinterpret_as_u64(b));
|
||||
int64x2_t v_mask = vorrq_s64(vsubq_s64(a.val, b.val), vsubq_s64(b.val, a.val));
|
||||
int64x2_t v_smask = vshrq_n_s64(v_mask, 63);
|
||||
return v_int64x2(v_smask);
|
||||
}
|
||||
static inline v_uint64x2 operator > (const v_uint64x2& a, const v_uint64x2& b)
|
||||
{
|
||||
int64x2_t v_mask = vreinterpretq_s64_u64(vsubq_u64(b.val, a.val));
|
||||
return v_uint64x2(vreinterpretq_u64_s64(vshrq_n_s64(v_mask, 63)));
|
||||
}
|
||||
static inline v_uint64x2 operator < (const v_uint64x2& a, const v_uint64x2& b)
|
||||
{
|
||||
int64x2_t v_mask = vreinterpretq_s64_u64(vsubq_u64(a.val, b.val));
|
||||
return v_uint64x2(vreinterpretq_u64_s64(vshrq_n_s64(v_mask, 63)));
|
||||
}
|
||||
static inline v_int64x2 operator > (const v_int64x2& a, const v_int64x2& b)
|
||||
{
|
||||
int64x2_t v_mask = vsubq_s64(b.val, a.val);
|
||||
return v_int64x2(vshrq_n_s64(v_mask, 63));
|
||||
}
|
||||
static inline v_int64x2 operator < (const v_int64x2& a, const v_int64x2& b)
|
||||
{
|
||||
int64x2_t v_mask = vsubq_s64(a.val, b.val);
|
||||
return v_int64x2(vshrq_n_s64(v_mask, 63));
|
||||
}
|
||||
#endif
|
||||
#if CV_SIMD128_64F
|
||||
@@ -1622,7 +1639,7 @@ inline int v_signmask(const v_uint64x2& a)
|
||||
const int64x2_t signPosition = {0,1};
|
||||
uint64x2_t v0 = vshlq_u64(vshrq_n_u64(a.val, 63), signPosition);
|
||||
uint64_t t0 = vaddvq_u64(v0);
|
||||
return t0;
|
||||
return (int)t0;
|
||||
#else // #if CV_NEON_AARCH64
|
||||
int64x1_t m0 = vdup_n_s64(0);
|
||||
uint64x2_t v0 = vshlq_u64(vshrq_n_u64(a.val, 63), vcombine_s64(m0, m0));
|
||||
|
||||
@@ -1275,6 +1275,14 @@ inline _Tpvec operator != (const _Tpvec& a, const _Tpvec& b) \
|
||||
{ return ~(a == b); }
|
||||
#endif
|
||||
|
||||
inline v_int64x2 operator > (const v_int64x2& a, const v_int64x2& b)
|
||||
{
|
||||
__m128i s = _mm_srli_epi64(_mm_sub_epi64(b.val, a.val), 63);
|
||||
return v_int64x2(_mm_sub_epi64(_mm_setzero_si128(), s));
|
||||
}
|
||||
inline v_int64x2 operator < (const v_int64x2& a, const v_int64x2& b)
|
||||
{ return b > a; }
|
||||
|
||||
OPENCV_HAL_IMPL_SSE_64BIT_CMP_OP(v_uint64x2)
|
||||
OPENCV_HAL_IMPL_SSE_64BIT_CMP_OP(v_int64x2)
|
||||
|
||||
|
||||
@@ -298,9 +298,9 @@ public:
|
||||
DEPTH_MASK_32F = 1 << CV_32F,
|
||||
DEPTH_MASK_64F = 1 << CV_64F,
|
||||
DEPTH_MASK_16F = 1 << CV_16F,
|
||||
DEPTH_MASK_ALL = (DEPTH_MASK_64F<<1)-1,
|
||||
DEPTH_MASK_ALL = (1 << CV_DEPTH_CURR_MAX)-1,
|
||||
DEPTH_MASK_ALL_BUT_8S = DEPTH_MASK_ALL & ~DEPTH_MASK_8S,
|
||||
DEPTH_MASK_ALL_16F = (DEPTH_MASK_16F<<1)-1,
|
||||
DEPTH_MASK_ALL_16F = DEPTH_MASK_ALL,
|
||||
DEPTH_MASK_FLT = DEPTH_MASK_32F + DEPTH_MASK_64F
|
||||
};
|
||||
|
||||
|
||||
@@ -666,9 +666,7 @@ bool Mat::isSubmatrix() const
|
||||
inline
|
||||
size_t Mat::elemSize() const
|
||||
{
|
||||
size_t res = dims > 0 ? step.p[dims - 1] : 0;
|
||||
CV_DbgAssert(res != 0);
|
||||
return res;
|
||||
return CV_ELEM_SIZE(flags);
|
||||
}
|
||||
|
||||
inline
|
||||
|
||||
@@ -442,6 +442,12 @@ typedef Vec<int, 4> Vec4i;
|
||||
typedef Vec<int, 6> Vec6i;
|
||||
typedef Vec<int, 8> Vec8i;
|
||||
|
||||
typedef Vec<int64_t, 2> Vec2l;
|
||||
typedef Vec<int64_t, 3> Vec3l;
|
||||
typedef Vec<int64_t, 4> Vec4l;
|
||||
typedef Vec<int64_t, 6> Vec6l;
|
||||
typedef Vec<int64_t, 8> Vec8l;
|
||||
|
||||
typedef Vec<float, 2> Vec2f;
|
||||
typedef Vec<float, 3> Vec3f;
|
||||
typedef Vec<float, 4> Vec4f;
|
||||
|
||||
@@ -146,9 +146,8 @@ template<> inline unsigned saturate_cast<unsigned>(short v) { return (unsigned)
|
||||
template<> inline unsigned saturate_cast<unsigned>(int v) { return (unsigned)std::max(v, (int)0); }
|
||||
template<> inline unsigned saturate_cast<unsigned>(int64 v) { return (unsigned)((uint64)v <= (uint64)UINT_MAX ? v : v > 0 ? UINT_MAX : 0); }
|
||||
template<> inline unsigned saturate_cast<unsigned>(uint64 v) { return (unsigned)std::min(v, (uint64)UINT_MAX); }
|
||||
// we intentionally do not clip negative numbers, to make -1 become 0xffffffff etc.
|
||||
template<> inline unsigned saturate_cast<unsigned>(float v) { return static_cast<unsigned>(cvRound(v)); }
|
||||
template<> inline unsigned saturate_cast<unsigned>(double v) { return static_cast<unsigned>(cvRound(v)); }
|
||||
template<> inline unsigned saturate_cast<unsigned>(float v) { return (unsigned)round(std::max(v, 0.f)); }
|
||||
template<> inline unsigned saturate_cast<unsigned>(double v) { return (unsigned)round(std::max(v, 0.)); }
|
||||
|
||||
template<> inline uint64 saturate_cast<uint64>(schar v) { return (uint64)std::max(v, (schar)0); }
|
||||
template<> inline uint64 saturate_cast<uint64>(short v) { return (uint64)std::max(v, (short)0); }
|
||||
@@ -156,9 +155,16 @@ template<> inline uint64 saturate_cast<uint64>(int v) { return (uint64)st
|
||||
template<> inline uint64 saturate_cast<uint64>(int64 v) { return (uint64)std::max(v, (int64)0); }
|
||||
|
||||
template<> inline int64 saturate_cast<int64>(uint64 v) { return (int64)std::min(v, (uint64)LLONG_MAX); }
|
||||
template<> inline int64 saturate_cast<int64>(float v) { return (int64)round((double)v); }
|
||||
template<> inline int64 saturate_cast<int64>(double v) { return (int64)round(v); }
|
||||
template<> inline uint64 saturate_cast<uint64>(float v) { return (int64)round((double)std::max(v, 0.f)); }
|
||||
template<> inline uint64 saturate_cast<uint64>(double v) { return (int64)round(std::max(v, 0.)); }
|
||||
|
||||
|
||||
/** @overload */
|
||||
template<typename _Tp> static inline _Tp saturate_cast(float16_t v) { return saturate_cast<_Tp>((float)v); }
|
||||
template<typename _Tp> static inline _Tp saturate_cast(bfloat16_t v) { return saturate_cast<_Tp>((float)v); }
|
||||
template<typename _Tp> static inline _Tp saturate_cast(bool v) { return saturate_cast<_Tp>(v ? 1 : 0); }
|
||||
|
||||
// in theory, we could use a LUT for 8u/8s->16f conversion,
|
||||
// but with hardware support for FP32->FP16 conversion the current approach is preferable
|
||||
@@ -172,6 +178,32 @@ template<> inline float16_t saturate_cast<float16_t>(uint64 v) { return float16
|
||||
template<> inline float16_t saturate_cast<float16_t>(int64 v) { return float16_t((float)v); }
|
||||
template<> inline float16_t saturate_cast<float16_t>(float v) { return float16_t(v); }
|
||||
template<> inline float16_t saturate_cast<float16_t>(double v) { return float16_t((float)v); }
|
||||
template<> inline float16_t saturate_cast<float16_t>(bfloat16_t v) { return float16_t((float)v); }
|
||||
|
||||
template<> inline bfloat16_t saturate_cast<bfloat16_t>(uchar v) { return bfloat16_t((float)v); }
|
||||
template<> inline bfloat16_t saturate_cast<bfloat16_t>(schar v) { return bfloat16_t((float)v); }
|
||||
template<> inline bfloat16_t saturate_cast<bfloat16_t>(ushort v) { return bfloat16_t((float)v); }
|
||||
template<> inline bfloat16_t saturate_cast<bfloat16_t>(short v) { return bfloat16_t((float)v); }
|
||||
template<> inline bfloat16_t saturate_cast<bfloat16_t>(unsigned v){ return bfloat16_t((float)v); }
|
||||
template<> inline bfloat16_t saturate_cast<bfloat16_t>(int v) { return bfloat16_t((float)v); }
|
||||
template<> inline bfloat16_t saturate_cast<bfloat16_t>(uint64 v) { return bfloat16_t((float)v); }
|
||||
template<> inline bfloat16_t saturate_cast<bfloat16_t>(int64 v) { return bfloat16_t((float)v); }
|
||||
template<> inline bfloat16_t saturate_cast<bfloat16_t>(float v) { return bfloat16_t(v); }
|
||||
template<> inline bfloat16_t saturate_cast<bfloat16_t>(double v) { return bfloat16_t((float)v); }
|
||||
template<> inline bfloat16_t saturate_cast<bfloat16_t>(float16_t v) { return bfloat16_t((float)v); }
|
||||
|
||||
template<> inline bool saturate_cast<bool>(uchar v) { return v != 0; }
|
||||
template<> inline bool saturate_cast<bool>(schar v) { return v != 0; }
|
||||
template<> inline bool saturate_cast<bool>(ushort v) { return v != 0; }
|
||||
template<> inline bool saturate_cast<bool>(short v) { return v != 0; }
|
||||
template<> inline bool saturate_cast<bool>(unsigned v){ return v != 0; }
|
||||
template<> inline bool saturate_cast<bool>(int v){ return v != 0; }
|
||||
template<> inline bool saturate_cast<bool>(float v){ return v != 0; }
|
||||
template<> inline bool saturate_cast<bool>(double v){ return v != 0; }
|
||||
template<> inline bool saturate_cast<bool>(uint64_t v){ return v != 0; }
|
||||
template<> inline bool saturate_cast<bool>(int64_t v){ return v != 0; }
|
||||
template<> inline bool saturate_cast<bool>(float16_t v){ return (float)v != 0; }
|
||||
template<> inline bool saturate_cast<bool>(bfloat16_t v){ return (float)v != 0; }
|
||||
|
||||
//! @}
|
||||
|
||||
|
||||
@@ -134,9 +134,9 @@ public:
|
||||
typedef value_type channel_type;
|
||||
typedef value_type vec_type;
|
||||
enum { generic_type = 0,
|
||||
depth = CV_8U,
|
||||
depth = CV_Bool,
|
||||
channels = 1,
|
||||
fmt = (int)'u',
|
||||
fmt = (int)'b',
|
||||
type = CV_MAKETYPE(depth, channels)
|
||||
};
|
||||
};
|
||||
@@ -231,6 +231,51 @@ public:
|
||||
};
|
||||
};
|
||||
|
||||
template<> class DataType<unsigned>
|
||||
{
|
||||
public:
|
||||
typedef unsigned value_type;
|
||||
typedef value_type work_type;
|
||||
typedef value_type channel_type;
|
||||
typedef value_type vec_type;
|
||||
enum { generic_type = 0,
|
||||
depth = CV_32U,
|
||||
channels = 1,
|
||||
fmt = (int)'n',
|
||||
type = CV_MAKETYPE(depth, channels)
|
||||
};
|
||||
};
|
||||
|
||||
template<> class DataType<int64_t>
|
||||
{
|
||||
public:
|
||||
typedef unsigned value_type;
|
||||
typedef value_type work_type;
|
||||
typedef value_type channel_type;
|
||||
typedef value_type vec_type;
|
||||
enum { generic_type = 0,
|
||||
depth = CV_64S,
|
||||
channels = 1,
|
||||
fmt = (int)'L',
|
||||
type = CV_MAKETYPE(depth, channels)
|
||||
};
|
||||
};
|
||||
|
||||
template<> class DataType<uint64_t>
|
||||
{
|
||||
public:
|
||||
typedef unsigned value_type;
|
||||
typedef value_type work_type;
|
||||
typedef value_type channel_type;
|
||||
typedef value_type vec_type;
|
||||
enum { generic_type = 0,
|
||||
depth = CV_64U,
|
||||
channels = 1,
|
||||
fmt = (int)'U',
|
||||
type = CV_MAKETYPE(depth, channels)
|
||||
};
|
||||
};
|
||||
|
||||
template<> class DataType<float>
|
||||
{
|
||||
public:
|
||||
@@ -276,6 +321,21 @@ public:
|
||||
};
|
||||
};
|
||||
|
||||
template<> class DataType<bfloat16_t>
|
||||
{
|
||||
public:
|
||||
typedef bfloat16_t value_type;
|
||||
typedef float work_type;
|
||||
typedef value_type channel_type;
|
||||
typedef value_type vec_type;
|
||||
enum { generic_type = 0,
|
||||
depth = CV_16BF,
|
||||
channels = 1,
|
||||
fmt = (int)'H',
|
||||
type = CV_MAKETYPE(depth, channels)
|
||||
};
|
||||
};
|
||||
|
||||
/** @brief A helper class for cv::DataType
|
||||
|
||||
The class is specialized for each fundamental numerical data type supported by OpenCV. It provides
|
||||
@@ -332,6 +392,12 @@ template<> class TypeDepth<CV_32S>
|
||||
typedef int value_type;
|
||||
};
|
||||
|
||||
template<> class TypeDepth<CV_32U>
|
||||
{
|
||||
enum { depth = CV_32U };
|
||||
typedef unsigned value_type;
|
||||
};
|
||||
|
||||
template<> class TypeDepth<CV_32F>
|
||||
{
|
||||
enum { depth = CV_32F };
|
||||
@@ -344,12 +410,36 @@ template<> class TypeDepth<CV_64F>
|
||||
typedef double value_type;
|
||||
};
|
||||
|
||||
template<> class TypeDepth<CV_64U>
|
||||
{
|
||||
enum { depth = CV_64U };
|
||||
typedef uint64_t value_type;
|
||||
};
|
||||
|
||||
template<> class TypeDepth<CV_64S>
|
||||
{
|
||||
enum { depth = CV_64S };
|
||||
typedef int64_t value_type;
|
||||
};
|
||||
|
||||
template<> class TypeDepth<CV_16F>
|
||||
{
|
||||
enum { depth = CV_16F };
|
||||
typedef float16_t value_type;
|
||||
};
|
||||
|
||||
template<> class TypeDepth<CV_16BF>
|
||||
{
|
||||
enum { depth = CV_16BF };
|
||||
typedef bfloat16_t value_type;
|
||||
};
|
||||
|
||||
template<> class TypeDepth<CV_Bool>
|
||||
{
|
||||
enum { depth = CV_Bool };
|
||||
typedef bool value_type;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
//! @}
|
||||
|
||||
Reference in New Issue
Block a user