mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 07:43:03 +04:00
added basic support for CV_16F (the new datatype etc.) (#12463)
* added basic support for CV_16F (the new datatype etc.). CV_USRTYPE1 is now equal to CV_16F, which may break some [rarely used] functionality. We'll see * fixed just introduced bug in norm; reverted errorneous changes in Torch importer (need to find a better solution) * addressed some issues found during the PR review * restored the patch to fix some perf test failures
This commit is contained in:
@@ -3009,6 +3009,7 @@ public:
|
||||
|
||||
virtual Ptr<Formatted> format(const Mat& mtx) const = 0;
|
||||
|
||||
virtual void set16fPrecision(int p = 4) = 0;
|
||||
virtual void set32fPrecision(int p = 8) = 0;
|
||||
virtual void set64fPrecision(int p = 16) = 0;
|
||||
virtual void setMultiline(bool ml = true) = 0;
|
||||
|
||||
@@ -317,13 +317,10 @@ Cv64suf;
|
||||
#define CV_IS_SUBMAT(flags) ((flags) & CV_MAT_SUBMAT_FLAG)
|
||||
|
||||
/** Size of each channel item,
|
||||
0x8442211 = 1000 0100 0100 0010 0010 0001 0001 ~ array of sizeof(arr_type_elem) */
|
||||
#define CV_ELEM_SIZE1(type) \
|
||||
((((sizeof(size_t)<<28)|0x8442211) >> CV_MAT_DEPTH(type)*4) & 15)
|
||||
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)
|
||||
|
||||
/** 0x3a50 = 11 10 10 01 01 00 00 ~ array of log2(sizeof(arr_type_elem)) */
|
||||
#define CV_ELEM_SIZE(type) \
|
||||
(CV_MAT_CN(type) << ((((sizeof(size_t)/4+1)*16384|0x3a50) >> CV_MAT_DEPTH(type)*2) & 3))
|
||||
#define CV_ELEM_SIZE(type) (CV_MAT_CN(type)*CV_ELEM_SIZE1(type))
|
||||
|
||||
#ifndef MIN
|
||||
# define MIN(a,b) ((a) > (b) ? (b) : (a))
|
||||
|
||||
@@ -195,6 +195,12 @@ CV_EXPORTS void addWeighted32s( const int* src1, size_t step1, const int* src2,
|
||||
CV_EXPORTS void addWeighted32f( const float* src1, size_t step1, const float* src2, size_t step2, float* dst, size_t step, int width, int height, void* scalars );
|
||||
CV_EXPORTS void addWeighted64f( const double* src1, size_t step1, const double* src2, size_t step2, double* dst, size_t step, int width, int height, void* scalars );
|
||||
|
||||
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 addRNGBias32f( float* arr, const float* scaleBiasPairs, int len );
|
||||
CV_EXPORTS void addRNGBias64f( double* arr, const double* scaleBiasPairs, int len );
|
||||
|
||||
struct CV_EXPORTS DFT1D
|
||||
{
|
||||
static Ptr<DFT1D> create(int len, int count, int depth, int flags, bool * useBuffer = 0);
|
||||
|
||||
@@ -76,6 +76,7 @@ typedef signed char schar;
|
||||
#define CV_32F 5
|
||||
#define CV_64F 6
|
||||
#define CV_USRTYPE1 7
|
||||
#define CV_16F 7
|
||||
|
||||
#define CV_MAT_DEPTH_MASK (CV_DEPTH_MAX - 1)
|
||||
#define CV_MAT_DEPTH(flags) ((flags) & CV_MAT_DEPTH_MASK)
|
||||
@@ -124,6 +125,12 @@ typedef signed char schar;
|
||||
#define CV_64FC3 CV_MAKETYPE(CV_64F,3)
|
||||
#define CV_64FC4 CV_MAKETYPE(CV_64F,4)
|
||||
#define CV_64FC(n) CV_MAKETYPE(CV_64F,(n))
|
||||
|
||||
#define CV_16FC1 CV_MAKETYPE(CV_16F,1)
|
||||
#define CV_16FC2 CV_MAKETYPE(CV_16F,2)
|
||||
#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))
|
||||
//! @}
|
||||
|
||||
//! @name Comparison operation
|
||||
|
||||
@@ -296,8 +296,10 @@ public:
|
||||
DEPTH_MASK_32S = 1 << CV_32S,
|
||||
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_BUT_8S = DEPTH_MASK_ALL & ~DEPTH_MASK_8S,
|
||||
DEPTH_MASK_ALL_16F = (DEPTH_MASK_16F<<1)-1,
|
||||
DEPTH_MASK_FLT = DEPTH_MASK_32F + DEPTH_MASK_64F
|
||||
};
|
||||
|
||||
|
||||
@@ -158,6 +158,22 @@ template<> inline uint64 saturate_cast<uint64>(int64 v) { return (uint64)st
|
||||
|
||||
template<> inline int64 saturate_cast<int64>(uint64 v) { return (int64)std::min(v, (uint64)LLONG_MAX); }
|
||||
|
||||
/** @overload */
|
||||
template<typename _Tp> static inline _Tp saturate_cast(float16_t v) { return saturate_cast<_Tp>((float)v); }
|
||||
|
||||
// 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
|
||||
template<> inline float16_t saturate_cast<float16_t>(uchar v) { return float16_t((float)v); }
|
||||
template<> inline float16_t saturate_cast<float16_t>(schar v) { return float16_t((float)v); }
|
||||
template<> inline float16_t saturate_cast<float16_t>(ushort v) { return float16_t((float)v); }
|
||||
template<> inline float16_t saturate_cast<float16_t>(short v) { return float16_t((float)v); }
|
||||
template<> inline float16_t saturate_cast<float16_t>(unsigned v){ return float16_t((float)v); }
|
||||
template<> inline float16_t saturate_cast<float16_t>(int v) { return float16_t((float)v); }
|
||||
template<> inline float16_t saturate_cast<float16_t>(uint64 v) { return float16_t((float)v); }
|
||||
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); }
|
||||
|
||||
//! @}
|
||||
|
||||
} // cv
|
||||
|
||||
@@ -261,6 +261,20 @@ public:
|
||||
};
|
||||
};
|
||||
|
||||
template<> class DataType<float16_t>
|
||||
{
|
||||
public:
|
||||
typedef float16_t value_type;
|
||||
typedef float work_type;
|
||||
typedef value_type channel_type;
|
||||
typedef value_type vec_type;
|
||||
enum { generic_type = 0,
|
||||
depth = CV_16F,
|
||||
channels = 1,
|
||||
fmt = (int)'h',
|
||||
type = CV_MAKETYPE(depth, channels)
|
||||
};
|
||||
};
|
||||
|
||||
/** @brief A helper class for cv::DataType
|
||||
|
||||
@@ -330,6 +344,12 @@ template<> class TypeDepth<CV_64F>
|
||||
typedef double value_type;
|
||||
};
|
||||
|
||||
template<> class TypeDepth<CV_16F>
|
||||
{
|
||||
enum { depth = CV_16F };
|
||||
typedef float16_t value_type;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
//! @}
|
||||
|
||||
Reference in New Issue
Block a user