mirror of
https://github.com/opencv/opencv.git
synced 2026-07-31 00:03:03 +04:00
Merge remote-tracking branch 'upstream/3.4' into merge-3.4
This commit is contained in:
@@ -3064,7 +3064,7 @@ template<typename _Tp> inline void Seq<_Tp>::copyTo(std::vector<_Tp>& vec, const
|
||||
size_t len = !seq ? 0 : range == Range::all() ? seq->total : range.end - range.start;
|
||||
vec.resize(len);
|
||||
if( seq && len )
|
||||
cvCvtSeqToArray(seq, &vec[0], range);
|
||||
cvCvtSeqToArray(seq, &vec[0], cvSlice(range));
|
||||
}
|
||||
|
||||
template<typename _Tp> inline Seq<_Tp>::operator std::vector<_Tp>() const
|
||||
|
||||
@@ -219,15 +219,10 @@ enum CpuFeatures {
|
||||
typedef union Cv16suf
|
||||
{
|
||||
short i;
|
||||
ushort u;
|
||||
#if CV_FP16_TYPE
|
||||
__fp16 h;
|
||||
#endif
|
||||
struct _fp16Format
|
||||
{
|
||||
unsigned int significand : 10;
|
||||
unsigned int exponent : 5;
|
||||
unsigned int sign : 1;
|
||||
} fmt;
|
||||
}
|
||||
Cv16suf;
|
||||
|
||||
@@ -236,12 +231,6 @@ typedef union Cv32suf
|
||||
int i;
|
||||
unsigned u;
|
||||
float f;
|
||||
struct _fp32Format
|
||||
{
|
||||
unsigned int significand : 23;
|
||||
unsigned int exponent : 8;
|
||||
unsigned int sign : 1;
|
||||
} fmt;
|
||||
}
|
||||
Cv32suf;
|
||||
|
||||
@@ -515,6 +504,115 @@ typedef ::uint64_t uint64_t;
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
namespace cv
|
||||
{
|
||||
|
||||
class float16_t
|
||||
{
|
||||
public:
|
||||
#if CV_FP16_TYPE
|
||||
|
||||
float16_t() {}
|
||||
explicit float16_t(float x) { h = (__fp16)x; }
|
||||
operator float() const { return (float)h; }
|
||||
static float16_t fromBits(ushort w)
|
||||
{
|
||||
Cv16suf u;
|
||||
u.u = w;
|
||||
float16_t result;
|
||||
result.h = u.h;
|
||||
return result;
|
||||
}
|
||||
static float16_t zero()
|
||||
{
|
||||
float16_t result;
|
||||
result.h = (__fp16)0;
|
||||
return result;
|
||||
}
|
||||
ushort bits() const
|
||||
{
|
||||
Cv16suf u;
|
||||
u.h = h;
|
||||
return u.u;
|
||||
}
|
||||
protected:
|
||||
__fp16 h;
|
||||
|
||||
#else
|
||||
float16_t() {}
|
||||
explicit float16_t(float x)
|
||||
{
|
||||
#if CV_AVX2
|
||||
__m128 v = _mm_load_ss(&x);
|
||||
w = (ushort)_mm_cvtsi128_si32(_mm_cvtps_ph(v, 0));
|
||||
#else
|
||||
Cv32suf in;
|
||||
in.f = x;
|
||||
unsigned sign = in.u & 0x80000000;
|
||||
in.u ^= sign;
|
||||
|
||||
if( in.u >= 0x47800000 )
|
||||
w = (ushort)(in.u > 0x7f800000 ? 0x7e00 : 0x7c00);
|
||||
else
|
||||
{
|
||||
if (in.u < 0x38800000)
|
||||
{
|
||||
in.f += 0.5f;
|
||||
w = (ushort)(in.u - 0x3f000000);
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned t = in.u + 0xc8000fff;
|
||||
w = (ushort)((t + ((in.u >> 13) & 1)) >> 13);
|
||||
}
|
||||
}
|
||||
|
||||
w = (ushort)(w | (sign >> 16));
|
||||
#endif
|
||||
}
|
||||
|
||||
operator float() const
|
||||
{
|
||||
#if CV_AVX2
|
||||
float f;
|
||||
_mm_store_ss(&f, _mm_cvtph_ps(_mm_cvtsi32_si128(w)));
|
||||
return f;
|
||||
#else
|
||||
Cv32suf out;
|
||||
|
||||
unsigned t = ((w & 0x7fff) << 13) + 0x38000000;
|
||||
unsigned sign = (w & 0x8000) << 16;
|
||||
unsigned e = w & 0x7c00;
|
||||
|
||||
out.u = t + (1 << 23);
|
||||
out.u = (e >= 0x7c00 ? t + 0x38000000 :
|
||||
e == 0 ? (out.f -= 6.103515625e-05f, out.u) : t) | sign;
|
||||
return out.f;
|
||||
#endif
|
||||
}
|
||||
|
||||
static float16_t fromBits(ushort b)
|
||||
{
|
||||
float16_t result;
|
||||
result.w = b;
|
||||
return result;
|
||||
}
|
||||
static float16_t zero()
|
||||
{
|
||||
float16_t result;
|
||||
result.w = (ushort)0;
|
||||
return result;
|
||||
}
|
||||
ushort bits() const { return w; }
|
||||
protected:
|
||||
ushort w;
|
||||
|
||||
#endif
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
//! @}
|
||||
|
||||
|
||||
@@ -252,7 +252,8 @@ CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN
|
||||
CV_INTRIN_DEFINE_WIDE_LOAD_EXPAND(unsigned, v_uint64, prefix) \
|
||||
CV_INTRIN_DEFINE_WIDE_INTRIN(float, v_float32, f32, prefix, load) \
|
||||
CV_INTRIN_DEFINE_WIDE_INTRIN(int64, v_int64, s64, prefix, load) \
|
||||
CV_INTRIN_DEFINE_WIDE_INTRIN(uint64, v_uint64, u64, prefix, load)
|
||||
CV_INTRIN_DEFINE_WIDE_INTRIN(uint64, v_uint64, u64, prefix, load) \
|
||||
CV_INTRIN_DEFINE_WIDE_LOAD_EXPAND(float16_t, v_float32, prefix)
|
||||
|
||||
template<typename _Tp> struct V_RegTraits
|
||||
{
|
||||
@@ -286,9 +287,6 @@ template<typename _Tp> struct V_RegTraits
|
||||
#if CV_SIMD128_64F
|
||||
CV_DEF_REG_TRAITS(v, v_float64x2, double, f64, v_float64x2, void, void, v_int64x2, v_int32x4);
|
||||
#endif
|
||||
#if CV_SIMD128_FP16
|
||||
CV_DEF_REG_TRAITS(v, v_float16x8, short, f16, v_float16x8, void, void, v_int16x8, v_int16x8);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if CV_SIMD256
|
||||
@@ -302,9 +300,6 @@ template<typename _Tp> struct V_RegTraits
|
||||
CV_DEF_REG_TRAITS(v256, v_uint64x4, uint64, u64, v_uint64x4, void, void, v_int64x4, void);
|
||||
CV_DEF_REG_TRAITS(v256, v_int64x4, int64, s64, v_uint64x4, void, void, v_int64x4, void);
|
||||
CV_DEF_REG_TRAITS(v256, v_float64x4, double, f64, v_float64x4, void, void, v_int64x4, v_int32x8);
|
||||
#if CV_SIMD256_FP16
|
||||
CV_DEF_REG_TRAITS(v256, v_float16x16, short, f16, v_float16x16, void, void, v_int16x16, void);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if CV_SIMD512 && (!defined(CV__SIMD_FORCE_WIDTH) || CV__SIMD_FORCE_WIDTH == 512)
|
||||
@@ -335,14 +330,6 @@ namespace CV__SIMD_NAMESPACE {
|
||||
#if CV_SIMD256_64F
|
||||
typedef v_float64x4 v_float64;
|
||||
#endif
|
||||
#if CV_FP16
|
||||
#define vx_load_fp16_f32 v256_load_fp16_f32
|
||||
#define vx_store_fp16 v_store_fp16
|
||||
#endif
|
||||
#if CV_SIMD256_FP16
|
||||
typedef v_float16x16 v_float16;
|
||||
CV_INTRIN_DEFINE_WIDE_INTRIN(short, v_float16, f16, v256, load_f16)
|
||||
#endif
|
||||
CV_INTRIN_DEFINE_WIDE_INTRIN_ALL_TYPES(v256)
|
||||
CV_INTRIN_DEFINE_WIDE_INTRIN(double, v_float64, f64, v256, load)
|
||||
inline void vx_cleanup() { v256_cleanup(); }
|
||||
@@ -353,7 +340,6 @@ using namespace CV__SIMD_NAMESPACE;
|
||||
namespace CV__SIMD_NAMESPACE {
|
||||
#define CV_SIMD CV_SIMD128
|
||||
#define CV_SIMD_64F CV_SIMD128_64F
|
||||
#define CV_SIMD_FP16 CV_SIMD128_FP16
|
||||
#define CV_SIMD_WIDTH 16
|
||||
typedef v_uint8x16 v_uint8;
|
||||
typedef v_int8x16 v_int8;
|
||||
@@ -367,14 +353,6 @@ namespace CV__SIMD_NAMESPACE {
|
||||
#if CV_SIMD128_64F
|
||||
typedef v_float64x2 v_float64;
|
||||
#endif
|
||||
#if CV_FP16
|
||||
#define vx_load_fp16_f32 v128_load_fp16_f32
|
||||
#define vx_store_fp16 v_store_fp16
|
||||
#endif
|
||||
#if CV_SIMD128_FP16
|
||||
typedef v_float16x8 v_float16;
|
||||
CV_INTRIN_DEFINE_WIDE_INTRIN(short, v_float16, f16, v, load_f16)
|
||||
#endif
|
||||
CV_INTRIN_DEFINE_WIDE_INTRIN_ALL_TYPES(v)
|
||||
#if CV_SIMD128_64F
|
||||
CV_INTRIN_DEFINE_WIDE_INTRIN(double, v_float64, f64, v, load)
|
||||
|
||||
@@ -234,7 +234,15 @@ struct v_uint64x4
|
||||
{ val = _mm256_setr_epi64x((int64)v0, (int64)v1, (int64)v2, (int64)v3); }
|
||||
v_uint64x4() : val(_mm256_setzero_si256()) {}
|
||||
uint64 get0() const
|
||||
{ return (uint64)_mm_cvtsi128_si64(_mm256_castsi256_si128(val)); }
|
||||
{
|
||||
#if defined __x86_64__ || defined _M_X64
|
||||
return (uint64)_mm_cvtsi128_si64(_mm256_castsi256_si128(val));
|
||||
#else
|
||||
int a = _mm_cvtsi128_si32(_mm256_castsi256_si128(val));
|
||||
int b = _mm_cvtsi128_si32(_mm256_castsi256_si128(_mm256_srli_epi64(val, 32)));
|
||||
return (unsigned)a | ((uint64)(unsigned)b << 32);
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
struct v_int64x4
|
||||
@@ -247,7 +255,17 @@ struct v_int64x4
|
||||
v_int64x4(int64 v0, int64 v1, int64 v2, int64 v3)
|
||||
{ val = _mm256_setr_epi64x(v0, v1, v2, v3); }
|
||||
v_int64x4() : val(_mm256_setzero_si256()) {}
|
||||
int64 get0() const { return (int64)_mm_cvtsi128_si64(_mm256_castsi256_si128(val)); }
|
||||
|
||||
int64 get0() const
|
||||
{
|
||||
#if defined __x86_64__ || defined _M_X64
|
||||
return (int64)_mm_cvtsi128_si64(_mm256_castsi256_si128(val));
|
||||
#else
|
||||
int a = _mm_cvtsi128_si32(_mm256_castsi256_si128(val));
|
||||
int b = _mm_cvtsi128_si32(_mm256_castsi256_si128(_mm256_srli_epi64(val, 32)));
|
||||
return (int64)((unsigned)a | ((uint64)(unsigned)b << 32));
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
struct v_float64x4
|
||||
@@ -1396,10 +1414,17 @@ inline v_int8x32 v_pack(const v_int16x16& a, const v_int16x16& b)
|
||||
{ return v_int8x32(_v256_shuffle_odd_64(_mm256_packs_epi16(a.val, b.val))); }
|
||||
|
||||
inline v_uint8x32 v_pack(const v_uint16x16& a, const v_uint16x16& b)
|
||||
{ return v_uint8x32(_v256_shuffle_odd_64(_mm256_packus_epi16(a.val, b.val))); }
|
||||
{
|
||||
__m256i t = _mm256_set1_epi16(255);
|
||||
__m256i a1 = _mm256_min_epu16(a.val, t);
|
||||
__m256i b1 = _mm256_min_epu16(b.val, t);
|
||||
return v_uint8x32(_v256_shuffle_odd_64(_mm256_packus_epi16(a1, b1)));
|
||||
}
|
||||
|
||||
inline v_uint8x32 v_pack_u(const v_int16x16& a, const v_int16x16& b)
|
||||
{ return v_pack(v_reinterpret_as_u16(a), v_reinterpret_as_u16(b)); }
|
||||
{
|
||||
return v_uint8x32(_v256_shuffle_odd_64(_mm256_packus_epi16(a.val, b.val)));
|
||||
}
|
||||
|
||||
inline void v_pack_store(schar* ptr, const v_int16x16& a)
|
||||
{ v_store_low(ptr, v_pack(a, a)); }
|
||||
@@ -2372,6 +2397,18 @@ OPENCV_HAL_IMPL_AVX_LOADSTORE_INTERLEAVE(v_float32x8, float, f32, v_uint32x8, un
|
||||
OPENCV_HAL_IMPL_AVX_LOADSTORE_INTERLEAVE(v_int64x4, int64, s64, v_uint64x4, uint64, u64)
|
||||
OPENCV_HAL_IMPL_AVX_LOADSTORE_INTERLEAVE(v_float64x4, double, f64, v_uint64x4, uint64, u64)
|
||||
|
||||
// FP16
|
||||
inline v_float32x8 v256_load_expand(const float16_t* ptr)
|
||||
{
|
||||
return v_float32x8(_mm256_cvtph_ps(_mm_loadu_si128((const __m128i*)ptr)));
|
||||
}
|
||||
|
||||
inline void v_pack_store(float16_t* ptr, const v_float32x8& a)
|
||||
{
|
||||
__m128i ah = _mm256_cvtps_ph(a.val, 0);
|
||||
_mm_storeu_si128((__m128i*)ptr, ah);
|
||||
}
|
||||
|
||||
inline void v256_cleanup() { _mm256_zeroupper(); }
|
||||
|
||||
//! @name Check SIMD256 support
|
||||
|
||||
@@ -2062,6 +2062,28 @@ inline v_float32x4 v_matmuladd(const v_float32x4& v, const v_float32x4& m0,
|
||||
v.s[0]*m0.s[3] + v.s[1]*m1.s[3] + v.s[2]*m2.s[3] + m3.s[3]);
|
||||
}
|
||||
|
||||
////// FP16 suport ///////
|
||||
|
||||
inline v_reg<float, V_TypeTraits<float>::nlanes128>
|
||||
v_load_expand(const float16_t* ptr)
|
||||
{
|
||||
v_reg<float, V_TypeTraits<float>::nlanes128> v;
|
||||
for( int i = 0; i < v.nlanes; i++ )
|
||||
{
|
||||
v.s[i] = ptr[i];
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
inline void
|
||||
v_pack_store(float16_t* ptr, v_reg<float, V_TypeTraits<float>::nlanes128>& v)
|
||||
{
|
||||
for( int i = 0; i < v.nlanes; i++ )
|
||||
{
|
||||
ptr[i] = float16_t(v.s[i]);
|
||||
}
|
||||
}
|
||||
|
||||
inline void v_cleanup() {}
|
||||
|
||||
//! @}
|
||||
|
||||
@@ -62,15 +62,6 @@ CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN
|
||||
#define CV_SIMD128_64F 0
|
||||
#endif
|
||||
|
||||
#ifndef CV_SIMD128_FP16
|
||||
# if CV_FP16 && (defined(__GNUC__) && __GNUC__ >= 5) // #12027: float16x8_t is missing in GCC 4.8.2
|
||||
# define CV_SIMD128_FP16 1
|
||||
# endif
|
||||
#endif
|
||||
#ifndef CV_SIMD128_FP16
|
||||
# define CV_SIMD128_FP16 0
|
||||
#endif
|
||||
|
||||
#if CV_SIMD128_64F
|
||||
#define OPENCV_HAL_IMPL_NEON_REINTERPRET(_Tpv, suffix) \
|
||||
template <typename T> static inline \
|
||||
@@ -329,53 +320,6 @@ inline void v_store_fp16(short* ptr, const v_float32x4& a)
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if CV_SIMD128_FP16
|
||||
// Workaround for old compilers
|
||||
static inline int16x8_t vreinterpretq_s16_f16(float16x8_t a) { return (int16x8_t)a; }
|
||||
static inline float16x8_t vreinterpretq_f16_s16(int16x8_t a) { return (float16x8_t)a; }
|
||||
|
||||
static inline float16x8_t cv_vld1q_f16(const void* ptr)
|
||||
{
|
||||
#ifndef vld1q_f16 // APPLE compiler defines vld1_f16 as macro
|
||||
return vreinterpretq_f16_s16(vld1q_s16((const short*)ptr));
|
||||
#else
|
||||
return vld1q_f16((const __fp16*)ptr);
|
||||
#endif
|
||||
}
|
||||
static inline void cv_vst1q_f16(void* ptr, float16x8_t a)
|
||||
{
|
||||
#ifndef vst1q_f16 // APPLE compiler defines vst1_f16 as macro
|
||||
vst1q_s16((short*)ptr, vreinterpretq_s16_f16(a));
|
||||
#else
|
||||
vst1q_f16((__fp16*)ptr, a);
|
||||
#endif
|
||||
}
|
||||
|
||||
struct v_float16x8
|
||||
{
|
||||
typedef short lane_type;
|
||||
enum { nlanes = 8 };
|
||||
|
||||
v_float16x8() {}
|
||||
explicit v_float16x8(float16x8_t v) : val(v) {}
|
||||
v_float16x8(short v0, short v1, short v2, short v3, short v4, short v5, short v6, short v7)
|
||||
{
|
||||
short v[] = {v0, v1, v2, v3, v4, v5, v6, v7};
|
||||
val = cv_vld1q_f16(v);
|
||||
}
|
||||
short get0() const
|
||||
{
|
||||
return vgetq_lane_s16(vreinterpretq_s16_f16(val), 0);
|
||||
}
|
||||
float16x8_t val;
|
||||
};
|
||||
|
||||
inline v_float16x8 v_setzero_f16() { return v_float16x8(vreinterpretq_f16_s16(vdupq_n_s16((short)0))); }
|
||||
inline v_float16x8 v_setall_f16(short v) { return v_float16x8(vreinterpretq_f16_s16(vdupq_n_s16(v))); }
|
||||
|
||||
#endif // CV_SIMD128_FP16
|
||||
|
||||
#define OPENCV_HAL_IMPL_NEON_INIT(_Tpv, _Tp, suffix) \
|
||||
inline v_##_Tpv v_setzero_##suffix() { return v_##_Tpv(vdupq_n_##suffix((_Tp)0)); } \
|
||||
inline v_##_Tpv v_setall_##suffix(_Tp v) { return v_##_Tpv(vdupq_n_##suffix(v)); } \
|
||||
@@ -934,24 +878,6 @@ OPENCV_HAL_IMPL_NEON_LOADSTORE_OP(v_float32x4, float, f32)
|
||||
OPENCV_HAL_IMPL_NEON_LOADSTORE_OP(v_float64x2, double, f64)
|
||||
#endif
|
||||
|
||||
#if CV_SIMD128_FP16
|
||||
// Workaround for old comiplers
|
||||
inline v_float16x8 v_load_f16(const short* ptr)
|
||||
{ return v_float16x8(cv_vld1q_f16(ptr)); }
|
||||
inline v_float16x8 v_load_f16_aligned(const short* ptr)
|
||||
{ return v_float16x8(cv_vld1q_f16(ptr)); }
|
||||
|
||||
inline v_float16x8 v_load_f16_low(const short* ptr)
|
||||
{ return v_float16x8(vcombine_f16(cv_vld1_f16(ptr), vdup_n_f16((float16_t)0))); }
|
||||
inline v_float16x8 v_load_f16_halves(const short* ptr0, const short* ptr1)
|
||||
{ return v_float16x8(vcombine_f16(cv_vld1_f16(ptr0), cv_vld1_f16(ptr1))); }
|
||||
|
||||
inline void v_store(short* ptr, const v_float16x8& a)
|
||||
{ cv_vst1q_f16(ptr, a.val); }
|
||||
inline void v_store_aligned(short* ptr, const v_float16x8& a)
|
||||
{ cv_vst1q_f16(ptr, a.val); }
|
||||
#endif
|
||||
|
||||
#define OPENCV_HAL_IMPL_NEON_REDUCE_OP_8(_Tpvec, _Tpnvec, scalartype, func, vectorfunc, suffix) \
|
||||
inline scalartype v_reduce_##func(const _Tpvec& a) \
|
||||
{ \
|
||||
@@ -1507,22 +1433,6 @@ inline v_float64x2 v_cvt_f64_high(const v_float32x4& a)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CV_SIMD128_FP16
|
||||
inline v_float32x4 v_cvt_f32(const v_float16x8& a)
|
||||
{
|
||||
return v_float32x4(vcvt_f32_f16(vget_low_f16(a.val)));
|
||||
}
|
||||
inline v_float32x4 v_cvt_f32_high(const v_float16x8& a)
|
||||
{
|
||||
return v_float32x4(vcvt_f32_f16(vget_high_f16(a.val)));
|
||||
}
|
||||
|
||||
inline v_float16x8 v_cvt_f16(const v_float32x4& a, const v_float32x4& b)
|
||||
{
|
||||
return v_float16x8(vcombine_f16(vcvt_f16_f32(a.val), vcvt_f16_f32(b.val)));
|
||||
}
|
||||
#endif
|
||||
|
||||
////////////// Lookup table access ////////////////////
|
||||
|
||||
inline v_int32x4 v_lut(const int* tab, const v_int32x4& idxvec)
|
||||
@@ -1588,6 +1498,47 @@ inline void v_lut_deinterleave(const double* tab, const v_int32x4& idxvec, v_flo
|
||||
}
|
||||
#endif
|
||||
|
||||
////// FP16 suport ///////
|
||||
#if CV_FP16
|
||||
inline v_float32x4 v_load_expand(const float16_t* ptr)
|
||||
{
|
||||
float16x4_t v =
|
||||
#ifndef vld1_f16 // APPLE compiler defines vld1_f16 as macro
|
||||
(float16x4_t)vld1_s16((const short*)ptr);
|
||||
#else
|
||||
vld1_f16((const __fp16*)ptr);
|
||||
#endif
|
||||
return v_float32x4(vcvt_f32_f16(v));
|
||||
}
|
||||
|
||||
inline void v_pack_store(float16_t* ptr, const v_float32x4& v)
|
||||
{
|
||||
float16x4_t hv = vcvt_f16_f32(v.val);
|
||||
|
||||
#ifndef vst1_f16 // APPLE compiler defines vst1_f16 as macro
|
||||
vst1_s16((short*)ptr, (int16x4_t)hv);
|
||||
#else
|
||||
vst1_f16((__fp16*)ptr, hv);
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
inline v_float32x4 v_load_expand(const float16_t* ptr)
|
||||
{
|
||||
const int N = 4;
|
||||
float buf[N];
|
||||
for( int i = 0; i < N; i++ ) buf[i] = (float)ptr[i];
|
||||
return v_load(buf);
|
||||
}
|
||||
|
||||
inline void v_pack_store(float16_t* ptr, const v_float32x4& v)
|
||||
{
|
||||
const int N = 4;
|
||||
float buf[N];
|
||||
v_store(buf, v);
|
||||
for( int i = 0; i < N; i++ ) ptr[i] = float16_t(buf[i]);
|
||||
}
|
||||
#endif
|
||||
|
||||
inline void v_cleanup() {}
|
||||
|
||||
//! @name Check SIMD support
|
||||
|
||||
@@ -404,7 +404,7 @@ void v_rshr_pack_u_store(uchar* ptr, const v_int16x8& a)
|
||||
inline v_int8x16 v_pack(const v_int16x8& a, const v_int16x8& b)
|
||||
{ return v_int8x16(_mm_packs_epi16(a.val, b.val)); }
|
||||
|
||||
inline void v_pack_store(schar* ptr, v_int16x8& a)
|
||||
inline void v_pack_store(schar* ptr, const v_int16x8& a)
|
||||
{ _mm_storel_epi64((__m128i*)ptr, _mm_packs_epi16(a.val, a.val)); }
|
||||
|
||||
template<int n> inline
|
||||
@@ -2655,6 +2655,50 @@ inline void v_lut_deinterleave(const double* tab, const v_int32x4& idxvec, v_flo
|
||||
y = v_float64x2(_mm_unpackhi_pd(xy0, xy1));
|
||||
}
|
||||
|
||||
|
||||
////////////// FP16 support ///////////////////////////
|
||||
|
||||
inline v_float32x4 v_load_expand(const float16_t* ptr)
|
||||
{
|
||||
const __m128i z = _mm_setzero_si128(), delta = _mm_set1_epi32(0x38000000);
|
||||
const __m128i signmask = _mm_set1_epi32(0x80000000), maxexp = _mm_set1_epi32(0x7c000000);
|
||||
const __m128 deltaf = _mm_castsi128_ps(_mm_set1_epi32(0x38800000));
|
||||
__m128i bits = _mm_unpacklo_epi16(z, _mm_loadl_epi64((const __m128i*)ptr)); // h << 16
|
||||
__m128i e = _mm_and_si128(bits, maxexp), sign = _mm_and_si128(bits, signmask);
|
||||
__m128i t = _mm_add_epi32(_mm_srli_epi32(_mm_xor_si128(bits, sign), 3), delta); // ((h & 0x7fff) << 13) + delta
|
||||
__m128i zt = _mm_castps_si128(_mm_sub_ps(_mm_castsi128_ps(_mm_add_epi32(t, _mm_set1_epi32(1 << 23))), deltaf));
|
||||
|
||||
t = _mm_add_epi32(t, _mm_and_si128(delta, _mm_cmpeq_epi32(maxexp, e)));
|
||||
__m128i zmask = _mm_cmpeq_epi32(e, z);
|
||||
__m128i ft = v_select_si128(zmask, zt, t);
|
||||
return v_float32x4(_mm_castsi128_ps(_mm_or_si128(ft, sign)));
|
||||
}
|
||||
|
||||
inline void v_pack_store(float16_t* ptr, const v_float32x4& v)
|
||||
{
|
||||
const __m128i signmask = _mm_set1_epi32(0x80000000);
|
||||
const __m128i rval = _mm_set1_epi32(0x3f000000);
|
||||
|
||||
__m128i t = _mm_castps_si128(v.val);
|
||||
__m128i sign = _mm_srai_epi32(_mm_and_si128(t, signmask), 16);
|
||||
t = _mm_andnot_si128(signmask, t);
|
||||
|
||||
__m128i finitemask = _mm_cmpgt_epi32(_mm_set1_epi32(0x47800000), t);
|
||||
__m128i isnan = _mm_cmpgt_epi32(t, _mm_set1_epi32(0x7f800000));
|
||||
__m128i naninf = v_select_si128(isnan, _mm_set1_epi32(0x7e00), _mm_set1_epi32(0x7c00));
|
||||
__m128i tinymask = _mm_cmpgt_epi32(_mm_set1_epi32(0x38800000), t);
|
||||
__m128i tt = _mm_castps_si128(_mm_add_ps(_mm_castsi128_ps(t), _mm_castsi128_ps(rval)));
|
||||
tt = _mm_sub_epi32(tt, rval);
|
||||
__m128i odd = _mm_and_si128(_mm_srli_epi32(t, 13), _mm_set1_epi32(1));
|
||||
__m128i nt = _mm_add_epi32(t, _mm_set1_epi32(0xc8000fff));
|
||||
nt = _mm_srli_epi32(_mm_add_epi32(nt, odd), 13);
|
||||
t = v_select_si128(tinymask, tt, nt);
|
||||
t = v_select_si128(finitemask, t, naninf);
|
||||
t = _mm_or_si128(t, sign);
|
||||
t = _mm_packs_epi32(t, t);
|
||||
_mm_storel_epi64((__m128i*)ptr, t);
|
||||
}
|
||||
|
||||
inline void v_cleanup() {}
|
||||
|
||||
//! @name Check SIMD support
|
||||
|
||||
@@ -916,6 +916,24 @@ inline void v_lut_deinterleave(const double* tab, const v_int32x4& idxvec, v_flo
|
||||
y = v_float64x2(tab[idx[0]+1], tab[idx[1]+1]);
|
||||
}
|
||||
|
||||
/////// FP16 support ////////
|
||||
|
||||
// [TODO] implement these 2 using VSX or universal intrinsics (copy from intrin_sse.cpp and adopt)
|
||||
inline v_float32x4 v_load_expand(const float16_t* ptr)
|
||||
{
|
||||
return v_float32x4((float)ptr[0], (float)ptr[1], (float)ptr[2], (float)ptr[3]);
|
||||
}
|
||||
|
||||
inline void v_pack_store(float16_t* ptr, const v_float32x4& v)
|
||||
{
|
||||
float CV_DECL_ALIGNED(32) f[4];
|
||||
v_store_aligned(f, v);
|
||||
ptr[0] = float16_t(f[0]);
|
||||
ptr[1] = float16_t(f[1]);
|
||||
ptr[2] = float16_t(f[2]);
|
||||
ptr[3] = float16_t(f[3]);
|
||||
}
|
||||
|
||||
inline void v_cleanup() {}
|
||||
|
||||
|
||||
|
||||
@@ -44,6 +44,29 @@
|
||||
#ifndef OPENCV_CORE_TYPES_H
|
||||
#define OPENCV_CORE_TYPES_H
|
||||
|
||||
#if !defined(__OPENCV_BUILD) && !defined(CV__DISABLE_C_API_CTORS)
|
||||
#define CV__ENABLE_C_API_CTORS // enable C API ctors (must be removed)
|
||||
#endif
|
||||
|
||||
//#define CV__VALIDATE_UNUNITIALIZED_VARS 1 // C++11 & GCC only
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#ifdef CV__VALIDATE_UNUNITIALIZED_VARS
|
||||
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
|
||||
#define CV_STRUCT_INITIALIZER {0,}
|
||||
#else
|
||||
#if defined(__GNUC__) && __GNUC__ == 4 // GCC 4.x warns on "= {}" initialization, fixed in GCC 5.0
|
||||
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
|
||||
#endif
|
||||
#define CV_STRUCT_INITIALIZER {}
|
||||
#endif
|
||||
|
||||
#else
|
||||
#define CV_STRUCT_INITIALIZER {0}
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef HAVE_IPL
|
||||
# ifndef __IPL_H__
|
||||
# if defined _WIN32
|
||||
@@ -285,6 +308,11 @@ CV_INLINE double cvRandReal( CvRNG* rng )
|
||||
#define IPL_BORDER_REFLECT 2
|
||||
#define IPL_BORDER_WRAP 3
|
||||
|
||||
#ifdef __cplusplus
|
||||
typedef struct _IplImage IplImage;
|
||||
CV_EXPORTS _IplImage cvIplImage(const cv::Mat& m);
|
||||
#endif
|
||||
|
||||
/** The IplImage is taken from the Intel Image Processing Library, in which the format is native. OpenCV
|
||||
only supports a subset of possible IplImage formats, as outlined in the parameter list above.
|
||||
|
||||
@@ -294,9 +322,6 @@ hand, the Intel Image Processing Library processes the area of intersection betw
|
||||
destination images (or ROIs), allowing them to vary independently.
|
||||
*/
|
||||
typedef struct
|
||||
#ifdef __cplusplus
|
||||
CV_EXPORTS
|
||||
#endif
|
||||
_IplImage
|
||||
{
|
||||
int nSize; /**< sizeof(IplImage) */
|
||||
@@ -330,13 +355,22 @@ _IplImage
|
||||
(not necessarily aligned) -
|
||||
needed for correct deallocation */
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)
|
||||
_IplImage() {}
|
||||
_IplImage(const cv::Mat& m);
|
||||
_IplImage(const cv::Mat& m) { *this = cvIplImage(m); }
|
||||
#endif
|
||||
}
|
||||
IplImage;
|
||||
|
||||
CV_INLINE IplImage cvIplImage()
|
||||
{
|
||||
#if !defined(CV__ENABLE_C_API_CTORS)
|
||||
IplImage self = CV_STRUCT_INITIALIZER; self.nSize = sizeof(IplImage); return self;
|
||||
#else
|
||||
return _IplImage();
|
||||
#endif
|
||||
}
|
||||
|
||||
typedef struct _IplTileInfo IplTileInfo;
|
||||
|
||||
typedef struct _IplROI
|
||||
@@ -460,13 +494,10 @@ typedef struct CvMat
|
||||
int cols;
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)
|
||||
CvMat() {}
|
||||
CvMat(const CvMat& m) { memcpy(this, &m, sizeof(CvMat));}
|
||||
CvMat(const cv::Mat& m);
|
||||
CvMat(const cv::Mat& m) { *this = cvMat(m); }
|
||||
#endif
|
||||
|
||||
}
|
||||
CvMat;
|
||||
|
||||
@@ -529,15 +560,8 @@ CV_INLINE CvMat cvMat( int rows, int cols, int type, void* data CV_DEFAULT(NULL)
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
inline CvMat::CvMat(const cv::Mat& m)
|
||||
{
|
||||
CV_DbgAssert(m.dims <= 2);
|
||||
*this = cvMat(m.rows, m.dims == 1 ? 1 : m.cols, m.type(), m.data);
|
||||
step = (int)m.step[0];
|
||||
type = (type & ~cv::Mat::CONTINUOUS_FLAG) | (m.flags & cv::Mat::CONTINUOUS_FLAG);
|
||||
}
|
||||
|
||||
inline CvMat cvMat(const cv::Mat& m)
|
||||
CV_INLINE CvMat cvMat(const cv::Mat& m)
|
||||
{
|
||||
CvMat self;
|
||||
CV_DbgAssert(m.dims <= 2);
|
||||
@@ -546,7 +570,24 @@ inline CvMat cvMat(const cv::Mat& m)
|
||||
self.type = (self.type & ~cv::Mat::CONTINUOUS_FLAG) | (m.flags & cv::Mat::CONTINUOUS_FLAG);
|
||||
return self;
|
||||
}
|
||||
CV_INLINE CvMat cvMat()
|
||||
{
|
||||
#if !defined(CV__ENABLE_C_API_CTORS)
|
||||
CvMat self = CV_STRUCT_INITIALIZER; return self;
|
||||
#else
|
||||
return CvMat();
|
||||
#endif
|
||||
}
|
||||
CV_INLINE CvMat cvMat(const CvMat& m)
|
||||
{
|
||||
#if !defined(CV__ENABLE_C_API_CTORS)
|
||||
CvMat self = CV_STRUCT_INITIALIZER; memcpy(&self, &m, sizeof(self)); return self;
|
||||
#else
|
||||
return CvMat(m);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
|
||||
#define CV_MAT_ELEM_PTR_FAST( mat, row, col, pix_size ) \
|
||||
@@ -630,13 +671,15 @@ CV_INLINE int cvIplDepth( int type )
|
||||
|
||||
#define CV_MAX_DIM 32
|
||||
|
||||
#ifdef __cplusplus
|
||||
typedef struct CvMatND CvMatND;
|
||||
CV_EXPORTS CvMatND cvMatND(const cv::Mat& m);
|
||||
#endif
|
||||
|
||||
/**
|
||||
@deprecated consider using cv::Mat instead
|
||||
*/
|
||||
typedef struct
|
||||
#ifdef __cplusplus
|
||||
CV_EXPORTS
|
||||
#endif
|
||||
CvMatND
|
||||
{
|
||||
int type;
|
||||
@@ -661,13 +704,23 @@ CvMatND
|
||||
}
|
||||
dim[CV_MAX_DIM];
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)
|
||||
CvMatND() {}
|
||||
CvMatND(const cv::Mat& m);
|
||||
CvMatND(const cv::Mat& m) { *this = cvMatND(m); }
|
||||
#endif
|
||||
}
|
||||
CvMatND;
|
||||
|
||||
|
||||
CV_INLINE CvMatND cvMatND()
|
||||
{
|
||||
#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus))
|
||||
CvMatND self = CV_STRUCT_INITIALIZER; return self;
|
||||
#else
|
||||
return CvMatND();
|
||||
#endif
|
||||
}
|
||||
|
||||
#define CV_IS_MATND_HDR(mat) \
|
||||
((mat) != NULL && (((const CvMatND*)(mat))->type & CV_MAGIC_MASK) == CV_MATND_MAGIC_VAL)
|
||||
|
||||
@@ -684,11 +737,7 @@ CvMatND;
|
||||
|
||||
struct CvSet;
|
||||
|
||||
typedef struct
|
||||
#ifdef __cplusplus
|
||||
CV_EXPORTS
|
||||
#endif
|
||||
CvSparseMat
|
||||
typedef struct CvSparseMat
|
||||
{
|
||||
int type;
|
||||
int dims;
|
||||
@@ -703,13 +752,13 @@ CvSparseMat
|
||||
int size[CV_MAX_DIM];
|
||||
|
||||
#ifdef __cplusplus
|
||||
void copyToSparseMat(cv::SparseMat& m) const;
|
||||
CV_EXPORTS void copyToSparseMat(cv::SparseMat& m) const;
|
||||
#endif
|
||||
}
|
||||
CvSparseMat;
|
||||
|
||||
#ifdef __cplusplus
|
||||
CV_EXPORTS CvSparseMat* cvCreateSparseMat(const cv::SparseMat& m);
|
||||
CV_EXPORTS CvSparseMat* cvCreateSparseMat(const cv::SparseMat& m);
|
||||
#endif
|
||||
|
||||
#define CV_IS_SPARSE_MAT_HDR(mat) \
|
||||
@@ -796,10 +845,23 @@ typedef struct CvRect
|
||||
int width;
|
||||
int height;
|
||||
|
||||
#ifdef __cplusplus
|
||||
#ifdef CV__VALIDATE_UNUNITIALIZED_VARS
|
||||
CvRect() __attribute__(( warning("Non-initialized variable") )) {};
|
||||
template<typename _Tp> CvRect(const std::initializer_list<_Tp> list)
|
||||
{
|
||||
CV_Assert(list.size() == 0 || list.size() == 4);
|
||||
x = y = width = height = 0;
|
||||
if (list.size() == 4)
|
||||
{
|
||||
x = list.begin()[0]; y = list.begin()[1]; width = list.begin()[2]; height = list.begin()[3];
|
||||
}
|
||||
};
|
||||
#elif defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)
|
||||
CvRect(int _x = 0, int _y = 0, int w = 0, int h = 0): x(_x), y(_y), width(w), height(h) {}
|
||||
template<typename _Tp>
|
||||
CvRect(const cv::Rect_<_Tp>& r): x(cv::saturate_cast<int>(r.x)), y(cv::saturate_cast<int>(r.y)), width(cv::saturate_cast<int>(r.width)), height(cv::saturate_cast<int>(r.height)) {}
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
template<typename _Tp>
|
||||
operator cv::Rect_<_Tp>() const { return cv::Rect_<_Tp>((_Tp)x, (_Tp)y, (_Tp)width, (_Tp)height); }
|
||||
#endif
|
||||
@@ -809,16 +871,16 @@ CvRect;
|
||||
/** constructs CvRect structure. */
|
||||
CV_INLINE CvRect cvRect( int x, int y, int width, int height )
|
||||
{
|
||||
CvRect r;
|
||||
|
||||
r.x = x;
|
||||
r.y = y;
|
||||
r.width = width;
|
||||
r.height = height;
|
||||
|
||||
#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus))
|
||||
CvRect r = {x, y, width, height};
|
||||
#else
|
||||
CvRect r(x, y , width, height);
|
||||
#endif
|
||||
return r;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
CV_INLINE CvRect cvRect(const cv::Rect& rc) { return cvRect(rc.x, rc.y, rc.width, rc.height); }
|
||||
#endif
|
||||
|
||||
CV_INLINE IplROI cvRectToROI( CvRect rect, int coi )
|
||||
{
|
||||
@@ -853,26 +915,28 @@ typedef struct CvTermCriteria
|
||||
CV_TERMCRIT_EPS */
|
||||
int max_iter;
|
||||
double epsilon;
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)
|
||||
CvTermCriteria(int _type = 0, int _iter = 0, double _eps = 0) : type(_type), max_iter(_iter), epsilon(_eps) {}
|
||||
CvTermCriteria(const cv::TermCriteria& t) : type(t.type), max_iter(t.maxCount), epsilon(t.epsilon) {}
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
operator cv::TermCriteria() const { return cv::TermCriteria(type, max_iter, epsilon); }
|
||||
#endif
|
||||
|
||||
}
|
||||
CvTermCriteria;
|
||||
|
||||
CV_INLINE CvTermCriteria cvTermCriteria( int type, int max_iter, double epsilon )
|
||||
{
|
||||
CvTermCriteria t;
|
||||
|
||||
t.type = type;
|
||||
t.max_iter = max_iter;
|
||||
t.epsilon = (float)epsilon;
|
||||
|
||||
#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus))
|
||||
CvTermCriteria t = { type, max_iter, (float)epsilon};
|
||||
#else
|
||||
CvTermCriteria t(type, max_iter, epsilon);
|
||||
#endif
|
||||
return t;
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
CV_INLINE CvTermCriteria cvTermCriteria(const cv::TermCriteria& t) { return cvTermCriteria(t.type, t.maxCount, t.epsilon); }
|
||||
#endif
|
||||
|
||||
|
||||
/******************************* CvPoint and variants ***********************************/
|
||||
@@ -882,10 +946,23 @@ typedef struct CvPoint
|
||||
int x;
|
||||
int y;
|
||||
|
||||
#ifdef __cplusplus
|
||||
#ifdef CV__VALIDATE_UNUNITIALIZED_VARS
|
||||
CvPoint() __attribute__(( warning("Non-initialized variable") )) {}
|
||||
template<typename _Tp> CvPoint(const std::initializer_list<_Tp> list)
|
||||
{
|
||||
CV_Assert(list.size() == 0 || list.size() == 2);
|
||||
x = y = 0;
|
||||
if (list.size() == 2)
|
||||
{
|
||||
x = list.begin()[0]; y = list.begin()[1];
|
||||
}
|
||||
};
|
||||
#elif defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)
|
||||
CvPoint(int _x = 0, int _y = 0): x(_x), y(_y) {}
|
||||
template<typename _Tp>
|
||||
CvPoint(const cv::Point_<_Tp>& pt): x((int)pt.x), y((int)pt.y) {}
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
template<typename _Tp>
|
||||
operator cv::Point_<_Tp>() const { return cv::Point_<_Tp>(cv::saturate_cast<_Tp>(x), cv::saturate_cast<_Tp>(y)); }
|
||||
#endif
|
||||
@@ -895,24 +972,39 @@ CvPoint;
|
||||
/** constructs CvPoint structure. */
|
||||
CV_INLINE CvPoint cvPoint( int x, int y )
|
||||
{
|
||||
CvPoint p;
|
||||
|
||||
p.x = x;
|
||||
p.y = y;
|
||||
|
||||
#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus))
|
||||
CvPoint p = {x, y};
|
||||
#else
|
||||
CvPoint p(x, y);
|
||||
#endif
|
||||
return p;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
CV_INLINE CvPoint cvPoint(const cv::Point& pt) { return cvPoint(pt.x, pt.y); }
|
||||
#endif
|
||||
|
||||
typedef struct CvPoint2D32f
|
||||
{
|
||||
float x;
|
||||
float y;
|
||||
|
||||
#ifdef __cplusplus
|
||||
#ifdef CV__VALIDATE_UNUNITIALIZED_VARS
|
||||
CvPoint2D32f() __attribute__(( warning("Non-initialized variable") )) {}
|
||||
template<typename _Tp> CvPoint2D32f(const std::initializer_list<_Tp> list)
|
||||
{
|
||||
CV_Assert(list.size() == 0 || list.size() == 2);
|
||||
x = y = 0;
|
||||
if (list.size() == 2)
|
||||
{
|
||||
x = list.begin()[0]; y = list.begin()[1];
|
||||
}
|
||||
};
|
||||
#elif defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)
|
||||
CvPoint2D32f(float _x = 0, float _y = 0): x(_x), y(_y) {}
|
||||
template<typename _Tp>
|
||||
CvPoint2D32f(const cv::Point_<_Tp>& pt): x((float)pt.x), y((float)pt.y) {}
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
template<typename _Tp>
|
||||
operator cv::Point_<_Tp>() const { return cv::Point_<_Tp>(cv::saturate_cast<_Tp>(x), cv::saturate_cast<_Tp>(y)); }
|
||||
#endif
|
||||
@@ -922,11 +1014,11 @@ CvPoint2D32f;
|
||||
/** constructs CvPoint2D32f structure. */
|
||||
CV_INLINE CvPoint2D32f cvPoint2D32f( double x, double y )
|
||||
{
|
||||
CvPoint2D32f p;
|
||||
|
||||
p.x = (float)x;
|
||||
p.y = (float)y;
|
||||
|
||||
#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus))
|
||||
CvPoint2D32f p = { (float)x, (float)y };
|
||||
#else
|
||||
CvPoint2D32f p((float)x, (float)y);
|
||||
#endif
|
||||
return p;
|
||||
}
|
||||
|
||||
@@ -934,7 +1026,11 @@ CV_INLINE CvPoint2D32f cvPoint2D32f( double x, double y )
|
||||
template<typename _Tp>
|
||||
CvPoint2D32f cvPoint2D32f(const cv::Point_<_Tp>& pt)
|
||||
{
|
||||
#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus))
|
||||
CvPoint2D32f p = { (float)pt.x, (float)pt.y };
|
||||
#else
|
||||
CvPoint2D32f p((float)pt.x, (float)pt.y);
|
||||
#endif
|
||||
return p;
|
||||
}
|
||||
#endif
|
||||
@@ -948,10 +1044,11 @@ CV_INLINE CvPoint2D32f cvPointTo32f( CvPoint point )
|
||||
/** converts CvPoint2D32f to CvPoint. */
|
||||
CV_INLINE CvPoint cvPointFrom32f( CvPoint2D32f point )
|
||||
{
|
||||
CvPoint ipt;
|
||||
ipt.x = cvRound(point.x);
|
||||
ipt.y = cvRound(point.y);
|
||||
|
||||
#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus))
|
||||
CvPoint ipt = { cvRound(point.x), cvRound(point.y) };
|
||||
#else
|
||||
CvPoint ipt(cvRound(point.x), cvRound(point.y));
|
||||
#endif
|
||||
return ipt;
|
||||
}
|
||||
|
||||
@@ -962,10 +1059,23 @@ typedef struct CvPoint3D32f
|
||||
float y;
|
||||
float z;
|
||||
|
||||
#ifdef __cplusplus
|
||||
#ifdef CV__VALIDATE_UNUNITIALIZED_VARS
|
||||
CvPoint3D32f() __attribute__(( warning("Non-initialized variable") )) {}
|
||||
template<typename _Tp> CvPoint3D32f(const std::initializer_list<_Tp> list)
|
||||
{
|
||||
CV_Assert(list.size() == 0 || list.size() == 3);
|
||||
x = y = z = 0;
|
||||
if (list.size() == 3)
|
||||
{
|
||||
x = list.begin()[0]; y = list.begin()[1]; z = list.begin()[2];
|
||||
}
|
||||
};
|
||||
#elif defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)
|
||||
CvPoint3D32f(float _x = 0, float _y = 0, float _z = 0): x(_x), y(_y), z(_z) {}
|
||||
template<typename _Tp>
|
||||
CvPoint3D32f(const cv::Point3_<_Tp>& pt): x((float)pt.x), y((float)pt.y), z((float)pt.z) {}
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
template<typename _Tp>
|
||||
operator cv::Point3_<_Tp>() const { return cv::Point3_<_Tp>(cv::saturate_cast<_Tp>(x), cv::saturate_cast<_Tp>(y), cv::saturate_cast<_Tp>(z)); }
|
||||
#endif
|
||||
@@ -975,31 +1085,51 @@ CvPoint3D32f;
|
||||
/** constructs CvPoint3D32f structure. */
|
||||
CV_INLINE CvPoint3D32f cvPoint3D32f( double x, double y, double z )
|
||||
{
|
||||
CvPoint3D32f p;
|
||||
|
||||
p.x = (float)x;
|
||||
p.y = (float)y;
|
||||
p.z = (float)z;
|
||||
|
||||
#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus))
|
||||
CvPoint3D32f p = { (float)x, (float)y, (float)z };
|
||||
#else
|
||||
CvPoint3D32f p((float)x, (float)y, (float)z);
|
||||
#endif
|
||||
return p;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
template<typename _Tp>
|
||||
CvPoint3D32f cvPoint3D32f(const cv::Point3_<_Tp>& pt)
|
||||
{
|
||||
#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus))
|
||||
CvPoint3D32f p = { (float)pt.x, (float)pt.y, (float)pt.z };
|
||||
#else
|
||||
CvPoint3D32f p((float)pt.x, (float)pt.y, (float)pt.z);
|
||||
#endif
|
||||
return p;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct CvPoint2D64f
|
||||
{
|
||||
double x;
|
||||
double y;
|
||||
#ifdef CV__VALIDATE_UNUNITIALIZED_VARS
|
||||
CvPoint2D64f() __attribute__(( warning("Non-initialized variable") )) {}
|
||||
template<typename _Tp> CvPoint2D64f(const std::initializer_list<_Tp> list)
|
||||
{
|
||||
CV_Assert(list.size() == 0 || list.size() == 2);
|
||||
x = y = 0;
|
||||
if (list.size() == 2)
|
||||
{
|
||||
x = list.begin()[0]; y = list.begin()[1];
|
||||
}
|
||||
};
|
||||
#endif
|
||||
}
|
||||
CvPoint2D64f;
|
||||
|
||||
/** constructs CvPoint2D64f structure.*/
|
||||
CV_INLINE CvPoint2D64f cvPoint2D64f( double x, double y )
|
||||
{
|
||||
CvPoint2D64f p;
|
||||
|
||||
p.x = x;
|
||||
p.y = y;
|
||||
|
||||
CvPoint2D64f p = { x, y };
|
||||
return p;
|
||||
}
|
||||
|
||||
@@ -1009,18 +1139,25 @@ typedef struct CvPoint3D64f
|
||||
double x;
|
||||
double y;
|
||||
double z;
|
||||
#ifdef CV__VALIDATE_UNUNITIALIZED_VARS
|
||||
CvPoint3D64f() __attribute__(( warning("Non-initialized variable") )) {}
|
||||
template<typename _Tp> CvPoint3D64f(const std::initializer_list<_Tp> list)
|
||||
{
|
||||
CV_Assert(list.size() == 0 || list.size() == 3);
|
||||
x = y = z = 0;
|
||||
if (list.size() == 3)
|
||||
{
|
||||
x = list.begin()[0]; y = list.begin()[1]; z = list.begin()[2];
|
||||
}
|
||||
};
|
||||
#endif
|
||||
}
|
||||
CvPoint3D64f;
|
||||
|
||||
/** constructs CvPoint3D64f structure. */
|
||||
CV_INLINE CvPoint3D64f cvPoint3D64f( double x, double y, double z )
|
||||
{
|
||||
CvPoint3D64f p;
|
||||
|
||||
p.x = x;
|
||||
p.y = y;
|
||||
p.z = z;
|
||||
|
||||
CvPoint3D64f p = { x, y, z };
|
||||
return p;
|
||||
}
|
||||
|
||||
@@ -1032,10 +1169,23 @@ typedef struct CvSize
|
||||
int width;
|
||||
int height;
|
||||
|
||||
#ifdef __cplusplus
|
||||
#ifdef CV__VALIDATE_UNUNITIALIZED_VARS
|
||||
CvSize() __attribute__(( warning("Non-initialized variable") )) {}
|
||||
template<typename _Tp> CvSize(const std::initializer_list<_Tp> list)
|
||||
{
|
||||
CV_Assert(list.size() == 0 || list.size() == 2);
|
||||
width = 0; height = 0;
|
||||
if (list.size() == 2)
|
||||
{
|
||||
width = list.begin()[0]; height = list.begin()[1];
|
||||
}
|
||||
};
|
||||
#elif defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)
|
||||
CvSize(int w = 0, int h = 0): width(w), height(h) {}
|
||||
template<typename _Tp>
|
||||
CvSize(const cv::Size_<_Tp>& sz): width(cv::saturate_cast<int>(sz.width)), height(cv::saturate_cast<int>(sz.height)) {}
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
template<typename _Tp>
|
||||
operator cv::Size_<_Tp>() const { return cv::Size_<_Tp>(cv::saturate_cast<_Tp>(width), cv::saturate_cast<_Tp>(height)); }
|
||||
#endif
|
||||
@@ -1045,23 +1195,48 @@ CvSize;
|
||||
/** constructs CvSize structure. */
|
||||
CV_INLINE CvSize cvSize( int width, int height )
|
||||
{
|
||||
CvSize s;
|
||||
|
||||
s.width = width;
|
||||
s.height = height;
|
||||
|
||||
#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus))
|
||||
CvSize s = { width, height };
|
||||
#else
|
||||
CvSize s(width, height);
|
||||
#endif
|
||||
return s;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
CV_INLINE CvSize cvSize(const cv::Size& sz)
|
||||
{
|
||||
#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus))
|
||||
CvSize s = { sz.width, sz.height };
|
||||
#else
|
||||
CvSize s(sz.width, sz.height);
|
||||
#endif
|
||||
return s;
|
||||
}
|
||||
#endif
|
||||
|
||||
typedef struct CvSize2D32f
|
||||
{
|
||||
float width;
|
||||
float height;
|
||||
|
||||
#ifdef __cplusplus
|
||||
#ifdef CV__VALIDATE_UNUNITIALIZED_VARS
|
||||
CvSize2D32f() __attribute__(( warning("Non-initialized variable") )) {}
|
||||
template<typename _Tp> CvSize2D32f(const std::initializer_list<_Tp> list)
|
||||
{
|
||||
CV_Assert(list.size() == 0 || list.size() == 2);
|
||||
width = 0; height = 0;
|
||||
if (list.size() == 2)
|
||||
{
|
||||
width = list.begin()[0]; height = list.begin()[1];
|
||||
}
|
||||
};
|
||||
#elif defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)
|
||||
CvSize2D32f(float w = 0, float h = 0): width(w), height(h) {}
|
||||
template<typename _Tp>
|
||||
CvSize2D32f(const cv::Size_<_Tp>& sz): width(cv::saturate_cast<float>(sz.width)), height(cv::saturate_cast<float>(sz.height)) {}
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
template<typename _Tp>
|
||||
operator cv::Size_<_Tp>() const { return cv::Size_<_Tp>(cv::saturate_cast<_Tp>(width), cv::saturate_cast<_Tp>(height)); }
|
||||
#endif
|
||||
@@ -1071,13 +1246,25 @@ CvSize2D32f;
|
||||
/** constructs CvSize2D32f structure. */
|
||||
CV_INLINE CvSize2D32f cvSize2D32f( double width, double height )
|
||||
{
|
||||
CvSize2D32f s;
|
||||
|
||||
s.width = (float)width;
|
||||
s.height = (float)height;
|
||||
|
||||
#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus))
|
||||
CvSize2D32f s = { (float)width, (float)height };
|
||||
#else
|
||||
CvSize2D32f s((float)width, (float)height);
|
||||
#endif
|
||||
return s;
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
template<typename _Tp>
|
||||
CvSize2D32f cvSize2D32f(const cv::Size_<_Tp>& sz)
|
||||
{
|
||||
#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus))
|
||||
CvSize2D32f s = { (float)sz.width, (float)sz.height };
|
||||
#else
|
||||
CvSize2D32f s((float)sz.width, (float)sz.height);
|
||||
#endif
|
||||
return s;
|
||||
}
|
||||
#endif
|
||||
|
||||
/** @sa RotatedRect
|
||||
*/
|
||||
@@ -1088,15 +1275,37 @@ typedef struct CvBox2D
|
||||
float angle; /**< Angle between the horizontal axis */
|
||||
/**< and the first side (i.e. length) in degrees */
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)
|
||||
CvBox2D(CvPoint2D32f c = CvPoint2D32f(), CvSize2D32f s = CvSize2D32f(), float a = 0) : center(c), size(s), angle(a) {}
|
||||
CvBox2D(const cv::RotatedRect& rr) : center(rr.center), size(rr.size), angle(rr.angle) {}
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
operator cv::RotatedRect() const { return cv::RotatedRect(center, size, angle); }
|
||||
#endif
|
||||
}
|
||||
CvBox2D;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
CV_INLINE CvBox2D cvBox2D(CvPoint2D32f c = CvPoint2D32f(), CvSize2D32f s = CvSize2D32f(), float a = 0)
|
||||
{
|
||||
CvBox2D self;
|
||||
self.center = c;
|
||||
self.size = s;
|
||||
self.angle = a;
|
||||
return self;
|
||||
}
|
||||
CV_INLINE CvBox2D cvBox2D(const cv::RotatedRect& rr)
|
||||
{
|
||||
CvBox2D self;
|
||||
self.center = cvPoint2D32f(rr.center);
|
||||
self.size = cvSize2D32f(rr.size);
|
||||
self.angle = rr.angle;
|
||||
return self;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/** Line iterator state: */
|
||||
typedef struct CvLineIterator
|
||||
{
|
||||
@@ -1122,7 +1331,19 @@ typedef struct CvSlice
|
||||
{
|
||||
int start_index, end_index;
|
||||
|
||||
#if defined(__cplusplus) && !defined(__CUDACC__)
|
||||
#ifdef CV__VALIDATE_UNUNITIALIZED_VARS
|
||||
CvSlice() __attribute__(( warning("Non-initialized variable") )) {}
|
||||
template<typename _Tp> CvSlice(const std::initializer_list<_Tp> list)
|
||||
{
|
||||
CV_Assert(list.size() == 0 || list.size() == 2);
|
||||
start_index = end_index = 0;
|
||||
if (list.size() == 2)
|
||||
{
|
||||
start_index = list.begin()[0]; end_index = list.begin()[1];
|
||||
}
|
||||
};
|
||||
#endif
|
||||
#if defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus) && !defined(__CUDACC__)
|
||||
CvSlice(int start = 0, int end = 0) : start_index(start), end_index(end) {}
|
||||
CvSlice(const cv::Range& r) { *this = (r.start != INT_MIN && r.end != INT_MAX) ? CvSlice(r.start, r.end) : CvSlice(0, CV_WHOLE_SEQ_END_INDEX); }
|
||||
operator cv::Range() const { return (start_index == 0 && end_index == CV_WHOLE_SEQ_END_INDEX ) ? cv::Range::all() : cv::Range(start_index, end_index); }
|
||||
@@ -1132,13 +1353,21 @@ CvSlice;
|
||||
|
||||
CV_INLINE CvSlice cvSlice( int start, int end )
|
||||
{
|
||||
CvSlice slice;
|
||||
slice.start_index = start;
|
||||
slice.end_index = end;
|
||||
|
||||
#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus))
|
||||
CvSlice slice = { start, end };
|
||||
#else
|
||||
CvSlice slice(start, end);
|
||||
#endif
|
||||
return slice;
|
||||
}
|
||||
|
||||
#if defined(__cplusplus)
|
||||
CV_INLINE CvSlice cvSlice(const cv::Range& r)
|
||||
{
|
||||
CvSlice slice = (r.start != INT_MIN && r.end != INT_MAX) ? cvSlice(r.start, r.end) : cvSlice(0, CV_WHOLE_SEQ_END_INDEX);
|
||||
return slice;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/************************************* CvScalar *****************************************/
|
||||
@@ -1148,13 +1377,22 @@ typedef struct CvScalar
|
||||
{
|
||||
double val[4];
|
||||
|
||||
#ifdef __cplusplus
|
||||
#ifdef CV__VALIDATE_UNUNITIALIZED_VARS
|
||||
CvScalar() __attribute__(( warning("Non-initialized variable") )) {}
|
||||
CvScalar(const std::initializer_list<double> list)
|
||||
{
|
||||
CV_Assert(list.size() == 0 || list.size() == 4);
|
||||
val[0] = val[1] = val[2] = val[3] = 0;
|
||||
if (list.size() == 4)
|
||||
{
|
||||
val[0] = list.begin()[0]; val[1] = list.begin()[1]; val[2] = list.begin()[2]; val[3] = list.begin()[3];
|
||||
}
|
||||
};
|
||||
#elif defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)
|
||||
CvScalar() {}
|
||||
CvScalar(double d0, double d1 = 0, double d2 = 0, double d3 = 0) { val[0] = d0; val[1] = d1; val[2] = d2; val[3] = d3; }
|
||||
template<typename _Tp>
|
||||
CvScalar(const cv::Scalar_<_Tp>& s) { val[0] = s.val[0]; val[1] = s.val[1]; val[2] = s.val[2]; val[3] = s.val[3]; }
|
||||
template<typename _Tp>
|
||||
operator cv::Scalar_<_Tp>() const { return cv::Scalar_<_Tp>(cv::saturate_cast<_Tp>(val[0]), cv::saturate_cast<_Tp>(val[1]), cv::saturate_cast<_Tp>(val[2]), cv::saturate_cast<_Tp>(val[3])); }
|
||||
template<typename _Tp, int cn>
|
||||
CvScalar(const cv::Vec<_Tp, cn>& v)
|
||||
{
|
||||
@@ -1163,22 +1401,59 @@ typedef struct CvScalar
|
||||
for( ; i < 4; i++ ) val[i] = 0;
|
||||
}
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
template<typename _Tp>
|
||||
operator cv::Scalar_<_Tp>() const { return cv::Scalar_<_Tp>(cv::saturate_cast<_Tp>(val[0]), cv::saturate_cast<_Tp>(val[1]), cv::saturate_cast<_Tp>(val[2]), cv::saturate_cast<_Tp>(val[3])); }
|
||||
#endif
|
||||
}
|
||||
CvScalar;
|
||||
|
||||
CV_INLINE CvScalar cvScalar( double val0, double val1 CV_DEFAULT(0),
|
||||
double val2 CV_DEFAULT(0), double val3 CV_DEFAULT(0))
|
||||
{
|
||||
#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus))
|
||||
CvScalar scalar = CV_STRUCT_INITIALIZER;
|
||||
#else
|
||||
CvScalar scalar;
|
||||
#endif
|
||||
scalar.val[0] = val0; scalar.val[1] = val1;
|
||||
scalar.val[2] = val2; scalar.val[3] = val3;
|
||||
return scalar;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
CV_INLINE CvScalar cvScalar()
|
||||
{
|
||||
#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus))
|
||||
CvScalar scalar = CV_STRUCT_INITIALIZER;
|
||||
#else
|
||||
CvScalar scalar;
|
||||
#endif
|
||||
scalar.val[0] = scalar.val[1] = scalar.val[2] = scalar.val[3] = 0;
|
||||
return scalar;
|
||||
}
|
||||
CV_INLINE CvScalar cvScalar(const cv::Scalar& s)
|
||||
{
|
||||
#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus))
|
||||
CvScalar scalar = CV_STRUCT_INITIALIZER;
|
||||
#else
|
||||
CvScalar scalar;
|
||||
#endif
|
||||
scalar.val[0] = s.val[0];
|
||||
scalar.val[1] = s.val[1];
|
||||
scalar.val[2] = s.val[2];
|
||||
scalar.val[3] = s.val[3];
|
||||
return scalar;
|
||||
}
|
||||
#endif
|
||||
|
||||
CV_INLINE CvScalar cvRealScalar( double val0 )
|
||||
{
|
||||
#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus))
|
||||
CvScalar scalar = CV_STRUCT_INITIALIZER;
|
||||
#else
|
||||
CvScalar scalar;
|
||||
#endif
|
||||
scalar.val[0] = val0;
|
||||
scalar.val[1] = scalar.val[2] = scalar.val[3] = 0;
|
||||
return scalar;
|
||||
@@ -1186,7 +1461,11 @@ CV_INLINE CvScalar cvRealScalar( double val0 )
|
||||
|
||||
CV_INLINE CvScalar cvScalarAll( double val0123 )
|
||||
{
|
||||
#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus))
|
||||
CvScalar scalar = CV_STRUCT_INITIALIZER;
|
||||
#else
|
||||
CvScalar scalar;
|
||||
#endif
|
||||
scalar.val[0] = val0123;
|
||||
scalar.val[1] = val0123;
|
||||
scalar.val[2] = val0123;
|
||||
@@ -1239,7 +1518,7 @@ typedef struct CvSeqBlock
|
||||
{
|
||||
struct CvSeqBlock* prev; /**< Previous sequence block. */
|
||||
struct CvSeqBlock* next; /**< Next sequence block. */
|
||||
int start_index; /**< Index of the first element in the block + */
|
||||
int start_index; /**< Index of the first element in the block + */
|
||||
/**< sequence->first->start_index. */
|
||||
int count; /**< Number of elements in the block. */
|
||||
schar* data; /**< Pointer to the first element of the block. */
|
||||
|
||||
@@ -117,7 +117,7 @@ OCL_PERF_TEST_P(LogFixture, Log, ::testing::Combine(
|
||||
OCL_TEST_CYCLE() cv::log(src, dst);
|
||||
|
||||
if (CV_MAT_DEPTH(type) >= CV_32F)
|
||||
SANITY_CHECK(dst, 1e-5, ERROR_RELATIVE);
|
||||
SANITY_CHECK(dst, 2e-4, ERROR_RELATIVE);
|
||||
else
|
||||
SANITY_CHECK(dst, 1);
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ PERF_TEST_P(Size_MatType, addWeighted, TYPICAL_MATS_ADWEIGHTED)
|
||||
{
|
||||
Size size = get<0>(GetParam());
|
||||
int type = get<1>(GetParam());
|
||||
int depth = CV_MAT_DEPTH(type);
|
||||
Mat src1(size, type);
|
||||
Mat src2(size, type);
|
||||
double alpha = 3.75;
|
||||
@@ -21,7 +22,7 @@ PERF_TEST_P(Size_MatType, addWeighted, TYPICAL_MATS_ADWEIGHTED)
|
||||
|
||||
declare.in(src1, src2, dst, WARMUP_RNG).out(dst);
|
||||
|
||||
if (CV_MAT_DEPTH(type) == CV_32S)
|
||||
if (depth == CV_32S)
|
||||
{
|
||||
// there might be not enough precision for integers
|
||||
src1 /= 2048;
|
||||
@@ -30,7 +31,7 @@ PERF_TEST_P(Size_MatType, addWeighted, TYPICAL_MATS_ADWEIGHTED)
|
||||
|
||||
TEST_CYCLE() cv::addWeighted( src1, alpha, src2, beta, gamma, dst, dst.type() );
|
||||
|
||||
SANITY_CHECK(dst, 1);
|
||||
SANITY_CHECK(dst, depth == CV_32S ? 4 : 1);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -33,7 +33,7 @@ PERF_TEST_P( Size_DepthSrc_DepthDst_Channels_alpha, convertTo,
|
||||
int runs = (sz.width <= 640) ? 8 : 1;
|
||||
TEST_CYCLE_MULTIRUN(runs) src.convertTo(dst, depthDst, alpha);
|
||||
|
||||
double eps = depthSrc <= CV_32S ? 1e-12 : (FLT_EPSILON * maxValue);
|
||||
double eps = depthSrc <= CV_32S && (depthDst <= CV_32S || depthDst == CV_64F) ? 1e-12 : (FLT_EPSILON * maxValue);
|
||||
eps = eps * std::max(1.0, fabs(alpha));
|
||||
SANITY_CHECK(dst, eps);
|
||||
}
|
||||
|
||||
@@ -27,11 +27,7 @@ PERF_TEST_P( Size_Depth_Channels, split,
|
||||
int runs = (sz.width <= 640) ? 8 : 1;
|
||||
TEST_CYCLE_MULTIRUN(runs) split(m, (vector<Mat>&)mv);
|
||||
|
||||
#if defined (__aarch64__)
|
||||
SANITY_CHECK(mv, 2e-5);
|
||||
#else
|
||||
SANITY_CHECK(mv, 1e-12);
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -617,7 +617,7 @@ static void arithm_op(InputArray _src1, InputArray _src2, OutputArray _dst,
|
||||
if( (kind1 == kind2 || cn == 1) && sz1 == sz2 && dims1 <= 2 && dims2 <= 2 && type1 == type2 &&
|
||||
!haveMask && ((!_dst.fixedType() && (dtype < 0 || CV_MAT_DEPTH(dtype) == depth1)) ||
|
||||
(_dst.fixedType() && _dst.type() == type1)) &&
|
||||
((src1Scalar && src2Scalar) || (!src1Scalar && !src2Scalar)) )
|
||||
(src1Scalar == src2Scalar) )
|
||||
{
|
||||
_dst.createSameSize(*psrc1, type1);
|
||||
CV_OCL_RUN(use_opencl,
|
||||
@@ -1204,7 +1204,7 @@ void cv::compare(InputArray _src1, InputArray _src2, OutputArray _dst, int op)
|
||||
compare(_src2, _src1, _dst, op);
|
||||
return;
|
||||
}
|
||||
else if( (is_src1_scalar && is_src2_scalar) || (!is_src1_scalar && !is_src2_scalar) )
|
||||
else if(is_src1_scalar == is_src2_scalar)
|
||||
CV_Error( CV_StsUnmatchedSizes,
|
||||
"The operation is neither 'array op array' (where arrays have the same size and the same type), "
|
||||
"nor 'array op scalar', nor 'scalar op array'" );
|
||||
|
||||
@@ -1017,7 +1017,7 @@ cvGetRawData( const CvArr* arr, uchar** data, int* step, CvSize* roi_size )
|
||||
*data = mat->data.ptr;
|
||||
|
||||
if( roi_size )
|
||||
*roi_size = cvGetMatSize( mat );
|
||||
*roi_size = cvSize(cvGetMatSize( mat ));
|
||||
}
|
||||
else if( CV_IS_IMAGE( arr ))
|
||||
{
|
||||
@@ -1218,7 +1218,7 @@ cvGetDimSize( const CvArr* arr, int index )
|
||||
CV_IMPL CvSize
|
||||
cvGetSize( const CvArr* arr )
|
||||
{
|
||||
CvSize size;
|
||||
CvSize size = {0, 0};
|
||||
|
||||
if( CV_IS_MAT_HDR_Z( arr ))
|
||||
{
|
||||
@@ -1918,7 +1918,7 @@ cvPtrND( const CvArr* arr, const int* idx, int* _type,
|
||||
CV_IMPL CvScalar
|
||||
cvGet1D( const CvArr* arr, int idx )
|
||||
{
|
||||
CvScalar scalar(0);
|
||||
CvScalar scalar = cvScalar();
|
||||
int type = 0;
|
||||
uchar* ptr;
|
||||
|
||||
@@ -1953,7 +1953,7 @@ cvGet1D( const CvArr* arr, int idx )
|
||||
CV_IMPL CvScalar
|
||||
cvGet2D( const CvArr* arr, int y, int x )
|
||||
{
|
||||
CvScalar scalar(0);
|
||||
CvScalar scalar = cvScalar();
|
||||
int type = 0;
|
||||
uchar* ptr;
|
||||
|
||||
@@ -1987,7 +1987,7 @@ cvGet2D( const CvArr* arr, int y, int x )
|
||||
CV_IMPL CvScalar
|
||||
cvGet3D( const CvArr* arr, int z, int y, int x )
|
||||
{
|
||||
CvScalar scalar(0);
|
||||
CvScalar scalar = cvScalar();
|
||||
int type = 0;
|
||||
uchar* ptr;
|
||||
|
||||
@@ -2009,7 +2009,7 @@ cvGet3D( const CvArr* arr, int z, int y, int x )
|
||||
CV_IMPL CvScalar
|
||||
cvGetND( const CvArr* arr, const int* idx )
|
||||
{
|
||||
CvScalar scalar(0);
|
||||
CvScalar scalar = cvScalar();
|
||||
int type = 0;
|
||||
uchar* ptr;
|
||||
|
||||
@@ -2916,15 +2916,7 @@ cvInitImageHeader( IplImage * image, CvSize size, int depth,
|
||||
if( !image )
|
||||
CV_Error( CV_HeaderIsNull, "null pointer to header" );
|
||||
|
||||
#if defined __GNUC__ && __GNUC__ >= 8
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wclass-memaccess"
|
||||
#endif
|
||||
memset( image, 0, sizeof( *image ));
|
||||
#if defined __GNUC__ && __GNUC__ >= 8
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
image->nSize = sizeof( *image );
|
||||
*image = cvIplImage();
|
||||
|
||||
icvGetColorModel( channels, &colorModel, &channelSeq );
|
||||
for (int i = 0; i < 4; i++)
|
||||
@@ -3081,7 +3073,7 @@ cvResetImageROI( IplImage* image )
|
||||
CV_IMPL CvRect
|
||||
cvGetImageROI( const IplImage* img )
|
||||
{
|
||||
CvRect rect;
|
||||
CvRect rect = {0, 0, 0, 0};
|
||||
if( !img )
|
||||
CV_Error( CV_StsNullPtr, "Null pointer to image" );
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#include "precomp.hpp"
|
||||
#include "stat.hpp"
|
||||
#include <opencv2/core/hal/hal.hpp>
|
||||
|
||||
namespace cv
|
||||
{
|
||||
@@ -45,6 +46,24 @@ void batchDistL2Sqr_(const _Tp* src1, const _Tp* src2, size_t step2,
|
||||
}
|
||||
}
|
||||
|
||||
template<>
|
||||
void batchDistL2Sqr_(const float* src1, const float* src2, size_t step2,
|
||||
int nvecs, int len, float* dist, const uchar* mask)
|
||||
{
|
||||
step2 /= sizeof(src2[0]);
|
||||
if( !mask )
|
||||
{
|
||||
for( int i = 0; i < nvecs; i++ )
|
||||
dist[i] = hal::normL2Sqr_(src1, src2 + step2*i, len);
|
||||
}
|
||||
else
|
||||
{
|
||||
float val0 = std::numeric_limits<float>::max();
|
||||
for( int i = 0; i < nvecs; i++ )
|
||||
dist[i] = mask[i] ? hal::normL2Sqr_(src1, src2 + step2*i, len) : val0;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename _Tp, typename _Rt>
|
||||
void batchDistL2_(const _Tp* src1, const _Tp* src2, size_t step2,
|
||||
int nvecs, int len, _Rt* dist, const uchar* mask)
|
||||
@@ -63,6 +82,24 @@ void batchDistL2_(const _Tp* src1, const _Tp* src2, size_t step2,
|
||||
}
|
||||
}
|
||||
|
||||
template<>
|
||||
void batchDistL2_(const float* src1, const float* src2, size_t step2,
|
||||
int nvecs, int len, float* dist, const uchar* mask)
|
||||
{
|
||||
step2 /= sizeof(src2[0]);
|
||||
if( !mask )
|
||||
{
|
||||
for( int i = 0; i < nvecs; i++ )
|
||||
dist[i] = std::sqrt(hal::normL2Sqr_(src1, src2 + step2*i, len));
|
||||
}
|
||||
else
|
||||
{
|
||||
float val0 = std::numeric_limits<float>::max();
|
||||
for( int i = 0; i < nvecs; i++ )
|
||||
dist[i] = mask[i] ? std::sqrt(hal::normL2Sqr_(src1, src2 + step2*i, len)) : val0;
|
||||
}
|
||||
}
|
||||
|
||||
static void batchDistHamming(const uchar* src1, const uchar* src2, size_t step2,
|
||||
int nvecs, int len, int* dist, const uchar* mask)
|
||||
{
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
// This file is part of OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html
|
||||
|
||||
|
||||
#include "precomp.hpp"
|
||||
#include "convert.hpp"
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace opt_AVX2
|
||||
{
|
||||
|
||||
void cvtScale_s16s32f32Line_AVX2(const short* src, int* dst, float scale, float shift, int width)
|
||||
{
|
||||
int x = 0;
|
||||
|
||||
__m256 scale256 = _mm256_set1_ps(scale);
|
||||
__m256 shift256 = _mm256_set1_ps(shift);
|
||||
const int shuffle = 0xD8;
|
||||
|
||||
for (; x <= width - 16; x += 16)
|
||||
{
|
||||
__m256i v_src = _mm256_loadu_si256((const __m256i *)(src + x));
|
||||
v_src = _mm256_permute4x64_epi64(v_src, shuffle);
|
||||
__m256i v_src_lo = _mm256_srai_epi32(_mm256_unpacklo_epi16(v_src, v_src), 16);
|
||||
__m256i v_src_hi = _mm256_srai_epi32(_mm256_unpackhi_epi16(v_src, v_src), 16);
|
||||
__m256 v_dst0 = _mm256_add_ps(_mm256_mul_ps(_mm256_cvtepi32_ps(v_src_lo), scale256), shift256);
|
||||
__m256 v_dst1 = _mm256_add_ps(_mm256_mul_ps(_mm256_cvtepi32_ps(v_src_hi), scale256), shift256);
|
||||
_mm256_storeu_si256((__m256i *)(dst + x), _mm256_cvtps_epi32(v_dst0));
|
||||
_mm256_storeu_si256((__m256i *)(dst + x + 8), _mm256_cvtps_epi32(v_dst1));
|
||||
}
|
||||
|
||||
for (; x < width; x++)
|
||||
dst[x] = saturate_cast<int>(src[x] * scale + shift);
|
||||
}
|
||||
|
||||
}
|
||||
} // cv::
|
||||
/* End of file. */
|
||||
+252
-1230
File diff suppressed because it is too large
Load Diff
@@ -1,126 +0,0 @@
|
||||
// This file is part of OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html
|
||||
|
||||
|
||||
#include "precomp.hpp"
|
||||
#include "convert.hpp"
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace opt_FP16
|
||||
{
|
||||
#if !defined(CV_NEON) || !CV_NEON
|
||||
const static int cVectorWidth = 8;
|
||||
|
||||
void cvtScaleHalf_SIMD32f16f( const float* src, size_t sstep, short* dst, size_t dstep, cv::Size size )
|
||||
{
|
||||
CV_INSTRUMENT_REGION()
|
||||
|
||||
sstep /= sizeof(src[0]);
|
||||
dstep /= sizeof(dst[0]);
|
||||
|
||||
for( ; size.height--; src += sstep, dst += dstep )
|
||||
{
|
||||
int x = 0;
|
||||
for ( ; x <= size.width - cVectorWidth ; x += cVectorWidth )
|
||||
{
|
||||
__m256 v_src = _mm256_loadu_ps(src + x);
|
||||
|
||||
// round to nearest even
|
||||
__m128i v_dst = _mm256_cvtps_ph(v_src, 0);
|
||||
|
||||
_mm_storeu_si128((__m128i*)(dst + x), v_dst);
|
||||
}
|
||||
|
||||
for ( ; x < size.width; x++ )
|
||||
{
|
||||
dst[x] = convertFp16SW(src[x]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void cvtScaleHalf_SIMD16f32f( const short* src, size_t sstep, float* dst, size_t dstep, cv::Size size )
|
||||
{
|
||||
CV_INSTRUMENT_REGION()
|
||||
|
||||
sstep /= sizeof(src[0]);
|
||||
dstep /= sizeof(dst[0]);
|
||||
|
||||
for( ; size.height--; src += sstep, dst += dstep )
|
||||
{
|
||||
int x = 0;
|
||||
for ( ; x <= size.width - cVectorWidth ; x += cVectorWidth )
|
||||
{
|
||||
__m128i v_src = _mm_loadu_si128((__m128i*)(src + x));
|
||||
|
||||
__m256 v_dst = _mm256_cvtph_ps(v_src);
|
||||
|
||||
_mm256_storeu_ps(dst + x, v_dst);
|
||||
}
|
||||
|
||||
for ( ; x < size.width; x++ )
|
||||
{
|
||||
dst[x] = convertFp16SW(src[x]);
|
||||
}
|
||||
}
|
||||
}
|
||||
#elif CV_NEON
|
||||
const static int cVectorWidth = 4;
|
||||
|
||||
void cvtScaleHalf_SIMD32f16f( const float* src, size_t sstep, short* dst, size_t dstep, cv::Size size )
|
||||
{
|
||||
CV_INSTRUMENT_REGION()
|
||||
|
||||
sstep /= sizeof(src[0]);
|
||||
dstep /= sizeof(dst[0]);
|
||||
|
||||
for( ; size.height--; src += sstep, dst += dstep )
|
||||
{
|
||||
int x = 0;
|
||||
for ( ; x <= size.width - cVectorWidth ; x += cVectorWidth)
|
||||
{
|
||||
float32x4_t v_src = vld1q_f32(src + x);
|
||||
float16x4_t v_dst = vcvt_f16_f32(v_src);
|
||||
|
||||
cv_vst1_f16(dst + x, v_dst);
|
||||
}
|
||||
|
||||
for ( ; x < size.width; x++ )
|
||||
{
|
||||
dst[x] = convertFp16SW(src[x]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void cvtScaleHalf_SIMD16f32f( const short* src, size_t sstep, float* dst, size_t dstep, cv::Size size )
|
||||
{
|
||||
CV_INSTRUMENT_REGION()
|
||||
|
||||
sstep /= sizeof(src[0]);
|
||||
dstep /= sizeof(dst[0]);
|
||||
|
||||
for( ; size.height--; src += sstep, dst += dstep )
|
||||
{
|
||||
int x = 0;
|
||||
for ( ; x <= size.width - cVectorWidth ; x += cVectorWidth )
|
||||
{
|
||||
float16x4_t v_src = cv_vld1_f16((__fp16*)src + x);
|
||||
|
||||
float32x4_t v_dst = vcvt_f32_f16(v_src);
|
||||
|
||||
vst1q_f32(dst + x, v_dst);
|
||||
}
|
||||
|
||||
for ( ; x < size.width; x++ )
|
||||
{
|
||||
dst[x] = convertFp16SW(src[x]);
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
#error "Unsupported build configuration"
|
||||
#endif
|
||||
}
|
||||
|
||||
} // cv::
|
||||
+388
-178
@@ -8,192 +8,402 @@
|
||||
|
||||
#include "opencv2/core/types.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
float convertFp16SW(short fp16);
|
||||
short convertFp16SW(float fp32);
|
||||
|
||||
#if !CV_FP16_TYPE
|
||||
// const numbers for floating points format
|
||||
const unsigned int kShiftSignificand = 13;
|
||||
const unsigned int kMaskFp16Significand = 0x3ff;
|
||||
const unsigned int kBiasFp16Exponent = 15;
|
||||
const unsigned int kBiasFp32Exponent = 127;
|
||||
#endif
|
||||
|
||||
#if CV_FP16_TYPE
|
||||
inline float convertFp16SW(short fp16)
|
||||
{
|
||||
// Fp16 -> Fp32
|
||||
Cv16suf a;
|
||||
a.i = fp16;
|
||||
return (float)a.h;
|
||||
}
|
||||
#else
|
||||
inline float convertFp16SW(short fp16)
|
||||
{
|
||||
// Fp16 -> Fp32
|
||||
Cv16suf b;
|
||||
b.i = fp16;
|
||||
int exponent = b.fmt.exponent - kBiasFp16Exponent;
|
||||
int significand = b.fmt.significand;
|
||||
|
||||
Cv32suf a;
|
||||
a.i = 0;
|
||||
a.fmt.sign = b.fmt.sign; // sign bit
|
||||
if( exponent == 16 )
|
||||
{
|
||||
// Inf or NaN
|
||||
a.i = a.i | 0x7F800000;
|
||||
if( significand != 0 )
|
||||
{
|
||||
// NaN
|
||||
#if defined(__x86_64__) || defined(_M_X64)
|
||||
// 64bit
|
||||
a.i = a.i | 0x7FC00000;
|
||||
#endif
|
||||
a.fmt.significand = a.fmt.significand | (significand << kShiftSignificand);
|
||||
}
|
||||
return a.f;
|
||||
}
|
||||
else if ( exponent == -(int)kBiasFp16Exponent )
|
||||
{
|
||||
// subnormal in Fp16
|
||||
if( significand == 0 )
|
||||
{
|
||||
// zero
|
||||
return a.f;
|
||||
}
|
||||
else
|
||||
{
|
||||
int shift = -1;
|
||||
while( ( significand & 0x400 ) == 0 )
|
||||
{
|
||||
significand = significand << 1;
|
||||
shift++;
|
||||
}
|
||||
significand = significand & kMaskFp16Significand;
|
||||
exponent -= shift;
|
||||
}
|
||||
}
|
||||
|
||||
a.fmt.exponent = (exponent+kBiasFp32Exponent);
|
||||
a.fmt.significand = significand << kShiftSignificand;
|
||||
return a.f;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CV_FP16_TYPE
|
||||
inline short convertFp16SW(float fp32)
|
||||
{
|
||||
// Fp32 -> Fp16
|
||||
Cv16suf a;
|
||||
a.h = (__fp16)fp32;
|
||||
return a.i;
|
||||
}
|
||||
#else
|
||||
inline short convertFp16SW(float fp32)
|
||||
{
|
||||
// Fp32 -> Fp16
|
||||
Cv32suf a;
|
||||
a.f = fp32;
|
||||
int exponent = a.fmt.exponent - kBiasFp32Exponent;
|
||||
int significand = a.fmt.significand;
|
||||
|
||||
Cv16suf result;
|
||||
result.i = 0;
|
||||
unsigned int absolute = a.i & 0x7fffffff;
|
||||
if( 0x477ff000 <= absolute )
|
||||
{
|
||||
// Inf in Fp16
|
||||
result.i = result.i | 0x7C00;
|
||||
if( exponent == 128 && significand != 0 )
|
||||
{
|
||||
// NaN
|
||||
result.i = (short)( result.i | 0x200 | ( significand >> kShiftSignificand ) );
|
||||
}
|
||||
}
|
||||
else if ( absolute < 0x33000001 )
|
||||
{
|
||||
// too small for fp16
|
||||
result.i = 0;
|
||||
}
|
||||
else if ( absolute < 0x387fe000 )
|
||||
{
|
||||
// subnormal in Fp16
|
||||
int fp16Significand = significand | 0x800000;
|
||||
int bitShift = (-exponent) - 1;
|
||||
fp16Significand = fp16Significand >> bitShift;
|
||||
|
||||
// special cases to round up
|
||||
bitShift = exponent + 24;
|
||||
int threshold = ( ( 0x400000 >> bitShift ) | ( ( ( significand & ( 0x800000 >> bitShift ) ) >> ( 126 - a.fmt.exponent ) ) ^ 1 ) );
|
||||
if( absolute == 0x33c00000 )
|
||||
{
|
||||
result.i = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( threshold <= ( significand & ( 0xffffff >> ( exponent + 25 ) ) ) )
|
||||
{
|
||||
fp16Significand++;
|
||||
}
|
||||
result.i = (short)fp16Significand;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// usual situation
|
||||
// exponent
|
||||
result.fmt.exponent = ( exponent + kBiasFp16Exponent );
|
||||
|
||||
// significand;
|
||||
short fp16Significand = (short)(significand >> kShiftSignificand);
|
||||
result.fmt.significand = fp16Significand;
|
||||
|
||||
// special cases to round up
|
||||
short lsb10bitsFp32 = (significand & 0x1fff);
|
||||
short threshold = 0x1000 + ( ( fp16Significand & 0x1 ) ? 0 : 1 );
|
||||
if( threshold <= lsb10bitsFp32 )
|
||||
{
|
||||
result.i++;
|
||||
}
|
||||
else if ( fp16Significand == kMaskFp16Significand && exponent == -15)
|
||||
{
|
||||
result.i++;
|
||||
}
|
||||
}
|
||||
|
||||
// sign bit
|
||||
result.fmt.sign = a.fmt.sign;
|
||||
return result.i;
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace opt_FP16
|
||||
|
||||
#if CV_SIMD
|
||||
|
||||
static inline void vx_load_as(const uchar* ptr, v_float32& a)
|
||||
{ a = v_cvt_f32(v_reinterpret_as_s32(vx_load_expand_q(ptr))); }
|
||||
|
||||
static inline void vx_load_as(const schar* ptr, v_float32& a)
|
||||
{ a = v_cvt_f32(vx_load_expand_q(ptr)); }
|
||||
|
||||
static inline void vx_load_as(const ushort* ptr, v_float32& a)
|
||||
{ a = v_cvt_f32(v_reinterpret_as_s32(vx_load_expand(ptr))); }
|
||||
|
||||
static inline void vx_load_as(const short* ptr, v_float32& a)
|
||||
{ a = v_cvt_f32(v_reinterpret_as_s32(vx_load_expand(ptr))); }
|
||||
|
||||
static inline void vx_load_as(const int* ptr, v_float32& a)
|
||||
{ a = v_cvt_f32(vx_load(ptr)); }
|
||||
|
||||
static inline void vx_load_as(const float* ptr, v_float32& a)
|
||||
{ a = vx_load(ptr); }
|
||||
|
||||
static inline void vx_load_as(const float16_t* ptr, v_float32& a)
|
||||
{ a = vx_load_expand(ptr); }
|
||||
|
||||
static inline void v_store_as(ushort* ptr, const v_float32& a)
|
||||
{ v_pack_u_store(ptr, v_round(a)); }
|
||||
|
||||
static inline void v_store_as(short* ptr, const v_float32& a)
|
||||
{ v_pack_store(ptr, v_round(a)); }
|
||||
|
||||
static inline void v_store_as(int* ptr, const v_float32& a)
|
||||
{ v_store(ptr, v_round(a)); }
|
||||
|
||||
static inline void v_store_as(float* ptr, const v_float32& a)
|
||||
{ v_store(ptr, a); }
|
||||
|
||||
static inline void v_store_as(float16_t* ptr, const v_float32& a)
|
||||
{ v_pack_store(ptr, a); }
|
||||
|
||||
static inline void vx_load_pair_as(const uchar* ptr, v_uint16& a, v_uint16& b)
|
||||
{ v_expand(vx_load(ptr), a, b); }
|
||||
|
||||
static inline void vx_load_pair_as(const schar* ptr, v_uint16& a, v_uint16& b)
|
||||
{
|
||||
void cvtScaleHalf_SIMD32f16f( const float* src, size_t sstep, short* dst, size_t dstep, cv::Size size );
|
||||
void cvtScaleHalf_SIMD16f32f( const short* src, size_t sstep, float* dst, size_t dstep, cv::Size size );
|
||||
const v_int8 z = vx_setzero_s8();
|
||||
v_int16 sa, sb;
|
||||
v_expand(v_max(vx_load(ptr), z), sa, sb);
|
||||
a = v_reinterpret_as_u16(sa);
|
||||
b = v_reinterpret_as_u16(sb);
|
||||
}
|
||||
namespace opt_AVX2
|
||||
|
||||
static inline void vx_load_pair_as(const ushort* ptr, v_uint16& a, v_uint16& b)
|
||||
{ a = vx_load(ptr); b = vx_load(ptr + v_uint16::nlanes); }
|
||||
|
||||
static inline void vx_load_pair_as(const uchar* ptr, v_int16& a, v_int16& b)
|
||||
{
|
||||
void cvtScale_s16s32f32Line_AVX2(const short* src, int* dst, float scale, float shift, int width);
|
||||
v_uint16 ua, ub;
|
||||
v_expand(vx_load(ptr), ua, ub);
|
||||
a = v_reinterpret_as_s16(ua);
|
||||
b = v_reinterpret_as_s16(ub);
|
||||
}
|
||||
namespace opt_SSE4_1
|
||||
|
||||
static inline void vx_load_pair_as(const schar* ptr, v_int16& a, v_int16& b)
|
||||
{ v_expand(vx_load(ptr), a, b); }
|
||||
|
||||
static inline void vx_load_pair_as(const short* ptr, v_int16& a, v_int16& b)
|
||||
{ a = vx_load(ptr); b = vx_load(ptr + v_uint16::nlanes); }
|
||||
|
||||
static inline void vx_load_pair_as(const uchar* ptr, v_int32& a, v_int32& b)
|
||||
{
|
||||
int cvtScale_SIMD_u8u16f32_SSE41(const uchar * src, ushort * dst, int width, float scale, float shift);
|
||||
int cvtScale_SIMD_s8u16f32_SSE41(const schar * src, ushort * dst, int width, float scale, float shift);
|
||||
int cvtScale_SIMD_u16u16f32_SSE41(const ushort * src, ushort * dst, int width, float scale, float shift);
|
||||
int cvtScale_SIMD_s16u16f32_SSE41(const short * src, ushort * dst, int width, float scale, float shift);
|
||||
int cvtScale_SIMD_s32u16f32_SSE41(const int * src, ushort * dst, int width, float scale, float shift);
|
||||
int cvtScale_SIMD_f32u16f32_SSE41(const float * src, ushort * dst, int width, float scale, float shift);
|
||||
int cvtScale_SIMD_f64u16f32_SSE41(const double * src, ushort * dst, int width, float scale, float shift);
|
||||
int Cvt_SIMD_f64u16_SSE41(const double * src, ushort * dst, int width);
|
||||
v_uint32 ua, ub;
|
||||
v_expand(vx_load_expand(ptr), ua, ub);
|
||||
a = v_reinterpret_as_s32(ua);
|
||||
b = v_reinterpret_as_s32(ub);
|
||||
}
|
||||
|
||||
static inline void vx_load_pair_as(const schar* ptr, v_int32& a, v_int32& b)
|
||||
{ v_expand(vx_load_expand(ptr), a, b); }
|
||||
|
||||
static inline void vx_load_pair_as(const ushort* ptr, v_int32& a, v_int32& b)
|
||||
{
|
||||
v_uint32 ua, ub;
|
||||
v_expand(vx_load(ptr), ua, ub);
|
||||
a = v_reinterpret_as_s32(ua);
|
||||
b = v_reinterpret_as_s32(ub);
|
||||
}
|
||||
|
||||
static inline void vx_load_pair_as(const short* ptr, v_int32& a, v_int32& b)
|
||||
{
|
||||
v_expand(vx_load(ptr), a, b);
|
||||
}
|
||||
|
||||
static inline void vx_load_pair_as(const int* ptr, v_int32& a, v_int32& b)
|
||||
{
|
||||
a = vx_load(ptr);
|
||||
b = vx_load(ptr + v_int32::nlanes);
|
||||
}
|
||||
|
||||
static inline void vx_load_pair_as(const uchar* ptr, v_float32& a, v_float32& b)
|
||||
{
|
||||
v_uint32 ua, ub;
|
||||
v_expand(vx_load_expand(ptr), ua, ub);
|
||||
a = v_cvt_f32(v_reinterpret_as_s32(ua));
|
||||
b = v_cvt_f32(v_reinterpret_as_s32(ub));
|
||||
}
|
||||
|
||||
static inline void vx_load_pair_as(const schar* ptr, v_float32& a, v_float32& b)
|
||||
{
|
||||
v_int32 ia, ib;
|
||||
v_expand(vx_load_expand(ptr), ia, ib);
|
||||
a = v_cvt_f32(ia);
|
||||
b = v_cvt_f32(ib);
|
||||
}
|
||||
|
||||
static inline void vx_load_pair_as(const ushort* ptr, v_float32& a, v_float32& b)
|
||||
{
|
||||
v_uint32 ua, ub;
|
||||
v_expand(vx_load(ptr), ua, ub);
|
||||
a = v_cvt_f32(v_reinterpret_as_s32(ua));
|
||||
b = v_cvt_f32(v_reinterpret_as_s32(ub));
|
||||
}
|
||||
|
||||
static inline void vx_load_pair_as(const short* ptr, v_float32& a, v_float32& b)
|
||||
{
|
||||
v_int32 ia, ib;
|
||||
v_expand(vx_load(ptr), ia, ib);
|
||||
a = v_cvt_f32(ia);
|
||||
b = v_cvt_f32(ib);
|
||||
}
|
||||
|
||||
static inline void vx_load_pair_as(const int* ptr, v_float32& a, v_float32& b)
|
||||
{
|
||||
v_int32 ia = vx_load(ptr), ib = vx_load(ptr + v_int32::nlanes);
|
||||
a = v_cvt_f32(ia);
|
||||
b = v_cvt_f32(ib);
|
||||
}
|
||||
|
||||
static inline void vx_load_pair_as(const float* ptr, v_float32& a, v_float32& b)
|
||||
{ a = vx_load(ptr); b = vx_load(ptr + v_float32::nlanes); }
|
||||
|
||||
//static inline void vx_load_pair_as(const float16_t* ptr, v_float32& a, v_float32& b)
|
||||
//{
|
||||
// a = vx_load_expand(ptr);
|
||||
// b = vx_load_expand(ptr + v_float32::nlanes);
|
||||
//}
|
||||
|
||||
|
||||
static inline void v_store_pair_as(uchar* ptr, const v_uint16& a, const v_uint16& b)
|
||||
{
|
||||
v_store(ptr, v_pack(a, b));
|
||||
}
|
||||
|
||||
static inline void v_store_pair_as(schar* ptr, const v_uint16& a, const v_uint16& b)
|
||||
{
|
||||
const v_uint8 maxval = vx_setall_u8((uchar)std::numeric_limits<schar>::max());
|
||||
v_uint8 v = v_pack(a, b);
|
||||
v_store(ptr, v_reinterpret_as_s8(v_min(v, maxval)));
|
||||
}
|
||||
|
||||
static inline void v_store_pair_as(ushort* ptr, const v_uint16& a, const v_uint16& b)
|
||||
{ v_store(ptr, a); v_store(ptr + v_uint16::nlanes, b); }
|
||||
|
||||
static inline void v_store_pair_as(uchar* ptr, const v_int16& a, const v_int16& b)
|
||||
{ v_store(ptr, v_pack_u(a, b)); }
|
||||
|
||||
static inline void v_store_pair_as(schar* ptr, const v_int16& a, const v_int16& b)
|
||||
{ v_store(ptr, v_pack(a, b)); }
|
||||
|
||||
static inline void v_store_pair_as(short* ptr, const v_int16& a, const v_int16& b)
|
||||
{ v_store(ptr, a); v_store(ptr + v_int16::nlanes, b); }
|
||||
|
||||
static inline void v_store_pair_as(uchar* ptr, const v_int32& a, const v_int32& b)
|
||||
{ v_pack_u_store(ptr, v_pack(a, b)); }
|
||||
|
||||
static inline void v_store_pair_as(schar* ptr, const v_int32& a, const v_int32& b)
|
||||
{ v_pack_store(ptr, v_pack(a, b)); }
|
||||
|
||||
static inline void v_store_pair_as(ushort* ptr, const v_int32& a, const v_int32& b)
|
||||
{ v_store(ptr, v_pack_u(a, b)); }
|
||||
|
||||
static inline void v_store_pair_as(short* ptr, const v_int32& a, const v_int32& b)
|
||||
{ v_store(ptr, v_pack(a, b)); }
|
||||
|
||||
static inline void v_store_pair_as(int* ptr, const v_int32& a, const v_int32& b)
|
||||
{
|
||||
v_store(ptr, a);
|
||||
v_store(ptr + v_int32::nlanes, b);
|
||||
}
|
||||
|
||||
static inline void v_store_pair_as(uchar* ptr, const v_float32& a, const v_float32& b)
|
||||
{ v_pack_u_store(ptr, v_pack(v_round(a), v_round(b))); }
|
||||
|
||||
static inline void v_store_pair_as(schar* ptr, const v_float32& a, const v_float32& b)
|
||||
{ v_pack_store(ptr, v_pack(v_round(a), v_round(b))); }
|
||||
|
||||
static inline void v_store_pair_as(ushort* ptr, const v_float32& a, const v_float32& b)
|
||||
{ v_store(ptr, v_pack_u(v_round(a), v_round(b))); }
|
||||
|
||||
static inline void v_store_pair_as(short* ptr, const v_float32& a, const v_float32& b)
|
||||
{ v_store(ptr, v_pack(v_round(a), v_round(b))); }
|
||||
|
||||
static inline void v_store_pair_as(int* ptr, const v_float32& a, const v_float32& b)
|
||||
{
|
||||
v_int32 ia = v_round(a), ib = v_round(b);
|
||||
v_store(ptr, ia);
|
||||
v_store(ptr + v_int32::nlanes, ib);
|
||||
}
|
||||
|
||||
static inline void v_store_pair_as(float* ptr, const v_float32& a, const v_float32& b)
|
||||
{ v_store(ptr, a); v_store(ptr + v_float32::nlanes, b); }
|
||||
|
||||
#if CV_SIMD_64F
|
||||
|
||||
static inline void vx_load_as(const double* ptr, v_float32& a)
|
||||
{
|
||||
v_float64 v0 = vx_load(ptr), v1 = vx_load(ptr + v_float64::nlanes);
|
||||
a = v_cvt_f32(v0, v1);
|
||||
}
|
||||
|
||||
static inline void vx_load_pair_as(const double* ptr, v_int32& a, v_int32& b)
|
||||
{
|
||||
v_float64 v0 = vx_load(ptr), v1 = vx_load(ptr + v_float64::nlanes);
|
||||
v_float64 v2 = vx_load(ptr + v_float64::nlanes*2), v3 = vx_load(ptr + v_float64::nlanes*3);
|
||||
v_int32 iv0 = v_round(v0), iv1 = v_round(v1);
|
||||
v_int32 iv2 = v_round(v2), iv3 = v_round(v3);
|
||||
a = v_combine_low(iv0, iv1);
|
||||
b = v_combine_low(iv2, iv3);
|
||||
}
|
||||
|
||||
static inline void vx_load_pair_as(const double* ptr, v_float32& a, v_float32& b)
|
||||
{
|
||||
v_float64 v0 = vx_load(ptr), v1 = vx_load(ptr + v_float64::nlanes);
|
||||
v_float64 v2 = vx_load(ptr + v_float64::nlanes*2), v3 = vx_load(ptr + v_float64::nlanes*3);
|
||||
a = v_cvt_f32(v0, v1);
|
||||
b = v_cvt_f32(v2, v3);
|
||||
}
|
||||
|
||||
static inline void vx_load_pair_as(const uchar* ptr, v_float64& a, v_float64& b)
|
||||
{
|
||||
v_int32 v0 = v_reinterpret_as_s32(vx_load_expand_q(ptr));
|
||||
a = v_cvt_f64(v0);
|
||||
b = v_cvt_f64_high(v0);
|
||||
}
|
||||
|
||||
static inline void vx_load_pair_as(const schar* ptr, v_float64& a, v_float64& b)
|
||||
{
|
||||
v_int32 v0 = vx_load_expand_q(ptr);
|
||||
a = v_cvt_f64(v0);
|
||||
b = v_cvt_f64_high(v0);
|
||||
}
|
||||
|
||||
static inline void vx_load_pair_as(const ushort* ptr, v_float64& a, v_float64& b)
|
||||
{
|
||||
v_int32 v0 = v_reinterpret_as_s32(vx_load_expand(ptr));
|
||||
a = v_cvt_f64(v0);
|
||||
b = v_cvt_f64_high(v0);
|
||||
}
|
||||
|
||||
static inline void vx_load_pair_as(const short* ptr, v_float64& a, v_float64& b)
|
||||
{
|
||||
v_int32 v0 = vx_load_expand(ptr);
|
||||
a = v_cvt_f64(v0);
|
||||
b = v_cvt_f64_high(v0);
|
||||
}
|
||||
|
||||
static inline void vx_load_pair_as(const int* ptr, v_float64& a, v_float64& b)
|
||||
{
|
||||
v_int32 v0 = vx_load(ptr);
|
||||
a = v_cvt_f64(v0);
|
||||
b = v_cvt_f64_high(v0);
|
||||
}
|
||||
|
||||
static inline void vx_load_pair_as(const float* ptr, v_float64& a, v_float64& b)
|
||||
{
|
||||
v_float32 v0 = vx_load(ptr);
|
||||
a = v_cvt_f64(v0);
|
||||
b = v_cvt_f64_high(v0);
|
||||
}
|
||||
|
||||
static inline void vx_load_pair_as(const double* ptr, v_float64& a, v_float64& b)
|
||||
{
|
||||
a = vx_load(ptr);
|
||||
b = vx_load(ptr + v_float64::nlanes);
|
||||
}
|
||||
|
||||
//static inline void vx_load_pair_as(const float16_t* ptr, v_float64& a, v_float64& b)
|
||||
//{
|
||||
// v_float32 v0 = vx_load_expand(ptr);
|
||||
// a = v_cvt_f64(v0);
|
||||
// b = v_cvt_f64_high(v0);
|
||||
//}
|
||||
|
||||
static inline void v_store_as(double* ptr, const v_float32& a)
|
||||
{
|
||||
v_float64 fa0 = v_cvt_f64(a), fa1 = v_cvt_f64_high(a);
|
||||
v_store(ptr, fa0);
|
||||
v_store(ptr + v_float64::nlanes, fa1);
|
||||
}
|
||||
|
||||
static inline void v_store_pair_as(double* ptr, const v_int32& a, const v_int32& b)
|
||||
{
|
||||
v_float64 fa0 = v_cvt_f64(a), fa1 = v_cvt_f64_high(a);
|
||||
v_float64 fb0 = v_cvt_f64(b), fb1 = v_cvt_f64_high(b);
|
||||
|
||||
v_store(ptr, fa0);
|
||||
v_store(ptr + v_float64::nlanes, fa1);
|
||||
v_store(ptr + v_float64::nlanes*2, fb0);
|
||||
v_store(ptr + v_float64::nlanes*3, fb1);
|
||||
}
|
||||
|
||||
static inline void v_store_pair_as(double* ptr, const v_float32& a, const v_float32& b)
|
||||
{
|
||||
v_float64 fa0 = v_cvt_f64(a), fa1 = v_cvt_f64_high(a);
|
||||
v_float64 fb0 = v_cvt_f64(b), fb1 = v_cvt_f64_high(b);
|
||||
|
||||
v_store(ptr, fa0);
|
||||
v_store(ptr + v_float64::nlanes, fa1);
|
||||
v_store(ptr + v_float64::nlanes*2, fb0);
|
||||
v_store(ptr + v_float64::nlanes*3, fb1);
|
||||
}
|
||||
|
||||
static inline void v_store_pair_as(double* ptr, const v_float64& a, const v_float64& b)
|
||||
{
|
||||
v_store(ptr, a);
|
||||
v_store(ptr + v_float64::nlanes, b);
|
||||
}
|
||||
|
||||
static inline void v_store_pair_as(int* ptr, const v_float64& a, const v_float64& b)
|
||||
{
|
||||
v_int32 ia = v_round(a), ib = v_round(b);
|
||||
v_store(ptr, v_combine_low(ia, ib));
|
||||
}
|
||||
|
||||
static inline void v_store_pair_as(float* ptr, const v_float64& a, const v_float64& b)
|
||||
{
|
||||
v_float32 v = v_cvt_f32(a, b);
|
||||
v_store(ptr, v);
|
||||
}
|
||||
|
||||
//static inline void v_store_pair_as(float16_t* ptr, const v_float64& a, const v_float64& b)
|
||||
//{
|
||||
// v_float32 v = v_cvt_f32(a, b);
|
||||
// v_pack_store(ptr, v);
|
||||
//}
|
||||
|
||||
#else
|
||||
|
||||
static inline void vx_load_as(const double* ptr, v_float32& a)
|
||||
{
|
||||
const int VECSZ = v_float32::nlanes;
|
||||
float buf[VECSZ*2];
|
||||
|
||||
for( int i = 0; i < VECSZ; i++ )
|
||||
buf[i] = saturate_cast<float>(ptr[i]);
|
||||
a = vx_load(buf);
|
||||
}
|
||||
|
||||
template<typename _Tdvec>
|
||||
static inline void vx_load_pair_as(const double* ptr, _Tdvec& a, _Tdvec& b)
|
||||
{
|
||||
const int VECSZ = _Tdvec::nlanes;
|
||||
typename _Tdvec::lane_type buf[VECSZ*2];
|
||||
|
||||
for( int i = 0; i < VECSZ*2; i++ )
|
||||
buf[i] = saturate_cast<typename _Tdvec::lane_type>(ptr[i]);
|
||||
a = vx_load(buf);
|
||||
b = vx_load(buf + VECSZ);
|
||||
}
|
||||
|
||||
static inline void v_store_as(double* ptr, const v_float32& a)
|
||||
{
|
||||
const int VECSZ = v_float32::nlanes;
|
||||
float buf[VECSZ];
|
||||
|
||||
v_store(buf, a);
|
||||
for( int i = 0; i < VECSZ; i++ )
|
||||
ptr[i] = (double)buf[i];
|
||||
}
|
||||
|
||||
template<typename _Tsvec>
|
||||
static inline void v_store_pair_as(double* ptr, const _Tsvec& a, const _Tsvec& b)
|
||||
{
|
||||
const int VECSZ = _Tsvec::nlanes;
|
||||
typename _Tsvec::lane_type buf[VECSZ*2];
|
||||
|
||||
v_store(buf, a); v_store(buf + VECSZ, b);
|
||||
for( int i = 0; i < VECSZ*2; i++ )
|
||||
ptr[i] = (double)buf[i];
|
||||
}
|
||||
|
||||
#endif /////////// CV_SIMD_64F
|
||||
|
||||
#endif /////////// CV_SIMD
|
||||
|
||||
}
|
||||
|
||||
#endif // SRC_CONVERT_HPP
|
||||
|
||||
@@ -1,203 +0,0 @@
|
||||
// This file is part of OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html
|
||||
|
||||
|
||||
#include "precomp.hpp"
|
||||
#include "convert.hpp"
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace opt_SSE4_1
|
||||
{
|
||||
|
||||
int cvtScale_SIMD_u8u16f32_SSE41(const uchar * src, ushort * dst, int width, float scale, float shift)
|
||||
{
|
||||
int x = 0;
|
||||
|
||||
__m128i v_zero = _mm_setzero_si128();
|
||||
__m128 v_scale = _mm_set1_ps(scale), v_shift = _mm_set1_ps(shift);
|
||||
|
||||
for ( ; x <= width - 8; x += 8)
|
||||
{
|
||||
__m128i v_src = _mm_unpacklo_epi8(_mm_loadl_epi64((__m128i const *)(src + x)), v_zero);
|
||||
__m128 v_src_f = _mm_cvtepi32_ps(_mm_unpacklo_epi16(v_src, v_zero));
|
||||
__m128 v_dst_0 = _mm_add_ps(_mm_mul_ps(v_src_f, v_scale), v_shift);
|
||||
|
||||
v_src_f = _mm_cvtepi32_ps(_mm_unpackhi_epi16(v_src, v_zero));
|
||||
__m128 v_dst_1 = _mm_add_ps(_mm_mul_ps(v_src_f, v_scale), v_shift);
|
||||
|
||||
__m128i v_dst = _mm_packus_epi32(_mm_cvtps_epi32(v_dst_0),
|
||||
_mm_cvtps_epi32(v_dst_1));
|
||||
_mm_storeu_si128((__m128i *)(dst + x), v_dst);
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
int cvtScale_SIMD_s8u16f32_SSE41(const schar * src, ushort * dst, int width, float scale, float shift)
|
||||
{
|
||||
int x = 0;
|
||||
|
||||
__m128i v_zero = _mm_setzero_si128();
|
||||
__m128 v_scale = _mm_set1_ps(scale), v_shift = _mm_set1_ps(shift);
|
||||
|
||||
for ( ; x <= width - 8; x += 8)
|
||||
{
|
||||
__m128i v_src = _mm_srai_epi16(_mm_unpacklo_epi8(v_zero, _mm_loadl_epi64((__m128i const *)(src + x))), 8);
|
||||
__m128 v_src_f = _mm_cvtepi32_ps(_mm_srai_epi32(_mm_unpacklo_epi16(v_zero, v_src), 16));
|
||||
__m128 v_dst_0 = _mm_add_ps(_mm_mul_ps(v_src_f, v_scale), v_shift);
|
||||
|
||||
v_src_f = _mm_cvtepi32_ps(_mm_srai_epi32(_mm_unpackhi_epi16(v_zero, v_src), 16));
|
||||
__m128 v_dst_1 = _mm_add_ps(_mm_mul_ps(v_src_f, v_scale), v_shift);
|
||||
|
||||
__m128i v_dst = _mm_packus_epi32(_mm_cvtps_epi32(v_dst_0),
|
||||
_mm_cvtps_epi32(v_dst_1));
|
||||
_mm_storeu_si128((__m128i *)(dst + x), v_dst);
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
int cvtScale_SIMD_u16u16f32_SSE41(const ushort * src, ushort * dst, int width, float scale, float shift)
|
||||
{
|
||||
int x = 0;
|
||||
|
||||
__m128i v_zero = _mm_setzero_si128();
|
||||
__m128 v_scale = _mm_set1_ps(scale), v_shift = _mm_set1_ps(shift);
|
||||
|
||||
for ( ; x <= width - 8; x += 8)
|
||||
{
|
||||
__m128i v_src = _mm_loadu_si128((__m128i const *)(src + x));
|
||||
__m128 v_src_f = _mm_cvtepi32_ps(_mm_unpacklo_epi16(v_src, v_zero));
|
||||
__m128 v_dst_0 = _mm_add_ps(_mm_mul_ps(v_src_f, v_scale), v_shift);
|
||||
|
||||
v_src_f = _mm_cvtepi32_ps(_mm_unpackhi_epi16(v_src, v_zero));
|
||||
__m128 v_dst_1 = _mm_add_ps(_mm_mul_ps(v_src_f, v_scale), v_shift);
|
||||
|
||||
__m128i v_dst = _mm_packus_epi32(_mm_cvtps_epi32(v_dst_0),
|
||||
_mm_cvtps_epi32(v_dst_1));
|
||||
_mm_storeu_si128((__m128i *)(dst + x), v_dst);
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
int cvtScale_SIMD_s16u16f32_SSE41(const short * src, ushort * dst, int width, float scale, float shift)
|
||||
{
|
||||
int x = 0;
|
||||
|
||||
__m128i v_zero = _mm_setzero_si128();
|
||||
__m128 v_scale = _mm_set1_ps(scale), v_shift = _mm_set1_ps(shift);
|
||||
|
||||
for ( ; x <= width - 8; x += 8)
|
||||
{
|
||||
__m128i v_src = _mm_loadu_si128((__m128i const *)(src + x));
|
||||
__m128 v_src_f = _mm_cvtepi32_ps(_mm_srai_epi32(_mm_unpacklo_epi16(v_zero, v_src), 16));
|
||||
__m128 v_dst_0 = _mm_add_ps(_mm_mul_ps(v_src_f, v_scale), v_shift);
|
||||
|
||||
v_src_f = _mm_cvtepi32_ps(_mm_srai_epi32(_mm_unpackhi_epi16(v_zero, v_src), 16));
|
||||
__m128 v_dst_1 = _mm_add_ps(_mm_mul_ps(v_src_f, v_scale), v_shift);
|
||||
|
||||
__m128i v_dst = _mm_packus_epi32(_mm_cvtps_epi32(v_dst_0),
|
||||
_mm_cvtps_epi32(v_dst_1));
|
||||
_mm_storeu_si128((__m128i *)(dst + x), v_dst);
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
int cvtScale_SIMD_s32u16f32_SSE41(const int * src, ushort * dst, int width, float scale, float shift)
|
||||
{
|
||||
int x = 0;
|
||||
|
||||
__m128 v_scale = _mm_set1_ps(scale), v_shift = _mm_set1_ps(shift);
|
||||
|
||||
for ( ; x <= width - 8; x += 8)
|
||||
{
|
||||
__m128i v_src = _mm_loadu_si128((__m128i const *)(src + x));
|
||||
__m128 v_dst_0 = _mm_add_ps(_mm_mul_ps(_mm_cvtepi32_ps(v_src), v_scale), v_shift);
|
||||
|
||||
v_src = _mm_loadu_si128((__m128i const *)(src + x + 4));
|
||||
__m128 v_dst_1 = _mm_add_ps(_mm_mul_ps(_mm_cvtepi32_ps(v_src), v_scale), v_shift);
|
||||
|
||||
__m128i v_dst = _mm_packus_epi32(_mm_cvtps_epi32(v_dst_0),
|
||||
_mm_cvtps_epi32(v_dst_1));
|
||||
_mm_storeu_si128((__m128i *)(dst + x), v_dst);
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
int cvtScale_SIMD_f32u16f32_SSE41(const float * src, ushort * dst, int width, float scale, float shift)
|
||||
{
|
||||
int x = 0;
|
||||
|
||||
__m128 v_scale = _mm_set1_ps(scale), v_shift = _mm_set1_ps(shift);
|
||||
|
||||
for ( ; x <= width - 8; x += 8)
|
||||
{
|
||||
__m128 v_src = _mm_loadu_ps(src + x);
|
||||
__m128 v_dst_0 = _mm_add_ps(_mm_mul_ps(v_src, v_scale), v_shift);
|
||||
|
||||
v_src = _mm_loadu_ps(src + x + 4);
|
||||
__m128 v_dst_1 = _mm_add_ps(_mm_mul_ps(v_src, v_scale), v_shift);
|
||||
|
||||
__m128i v_dst = _mm_packus_epi32(_mm_cvtps_epi32(v_dst_0),
|
||||
_mm_cvtps_epi32(v_dst_1));
|
||||
_mm_storeu_si128((__m128i *)(dst + x), v_dst);
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
int cvtScale_SIMD_f64u16f32_SSE41(const double * src, ushort * dst, int width, float scale, float shift)
|
||||
{
|
||||
int x = 0;
|
||||
|
||||
__m128 v_scale = _mm_set1_ps(scale), v_shift = _mm_set1_ps(shift);
|
||||
|
||||
for ( ; x <= width - 8; x += 8)
|
||||
{
|
||||
__m128 v_src = _mm_movelh_ps(_mm_cvtpd_ps(_mm_loadu_pd(src + x)),
|
||||
_mm_cvtpd_ps(_mm_loadu_pd(src + x + 2)));
|
||||
__m128 v_dst_0 = _mm_add_ps(_mm_mul_ps(v_src, v_scale), v_shift);
|
||||
|
||||
v_src = _mm_movelh_ps(_mm_cvtpd_ps(_mm_loadu_pd(src + x + 4)),
|
||||
_mm_cvtpd_ps(_mm_loadu_pd(src + x + 6)));
|
||||
__m128 v_dst_1 = _mm_add_ps(_mm_mul_ps(v_src, v_scale), v_shift);
|
||||
|
||||
__m128i v_dst = _mm_packus_epi32(_mm_cvtps_epi32(v_dst_0),
|
||||
_mm_cvtps_epi32(v_dst_1));
|
||||
_mm_storeu_si128((__m128i *)(dst + x), v_dst);
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
int Cvt_SIMD_f64u16_SSE41(const double * src, ushort * dst, int width)
|
||||
{
|
||||
int x = 0;
|
||||
|
||||
for ( ; x <= width - 8; x += 8)
|
||||
{
|
||||
__m128 v_src0 = _mm_cvtpd_ps(_mm_loadu_pd(src + x));
|
||||
__m128 v_src1 = _mm_cvtpd_ps(_mm_loadu_pd(src + x + 2));
|
||||
__m128 v_src2 = _mm_cvtpd_ps(_mm_loadu_pd(src + x + 4));
|
||||
__m128 v_src3 = _mm_cvtpd_ps(_mm_loadu_pd(src + x + 6));
|
||||
|
||||
v_src0 = _mm_movelh_ps(v_src0, v_src1);
|
||||
v_src1 = _mm_movelh_ps(v_src2, v_src3);
|
||||
|
||||
__m128i v_dst = _mm_packus_epi32(_mm_cvtps_epi32(v_src0),
|
||||
_mm_cvtps_epi32(v_src1));
|
||||
_mm_storeu_si128((__m128i *)(dst + x), v_dst);
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
}
|
||||
} // cv::
|
||||
|
||||
/* End of file. */
|
||||
+240
-1582
File diff suppressed because it is too large
Load Diff
@@ -258,7 +258,7 @@ void Mat::copyTo( OutputArray _dst ) const
|
||||
UMat dst = _dst.getUMat();
|
||||
CV_Assert(dst.u != NULL);
|
||||
size_t i, sz[CV_MAX_DIM] = {0}, dstofs[CV_MAX_DIM], esz = elemSize();
|
||||
CV_Assert(dims >= 0 && dims < CV_MAX_DIM);
|
||||
CV_Assert(dims > 0 && dims < CV_MAX_DIM);
|
||||
for( i = 0; i < (size_t)dims; i++ )
|
||||
sz[i] = size.p[i];
|
||||
sz[dims-1] *= esz;
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
|
||||
#include "precomp.hpp"
|
||||
#include <opencv2/core/utils/configuration.private.hpp>
|
||||
#include <opencv2/core/hal/hal.hpp>
|
||||
|
||||
////////////////////////////////////////// kmeans ////////////////////////////////////////////
|
||||
|
||||
@@ -74,7 +75,7 @@ public:
|
||||
|
||||
for (int i = begin; i<end; i++)
|
||||
{
|
||||
tdist2[i] = std::min(normL2Sqr(data.ptr<float>(i), data.ptr<float>(ci), dims), dist[i]);
|
||||
tdist2[i] = std::min(hal::normL2Sqr_(data.ptr<float>(i), data.ptr<float>(ci), dims), dist[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,7 +107,7 @@ static void generateCentersPP(const Mat& data, Mat& _out_centers,
|
||||
|
||||
for (int i = 0; i < N; i++)
|
||||
{
|
||||
dist[i] = normL2Sqr(data.ptr<float>(i), data.ptr<float>(centers[0]), dims);
|
||||
dist[i] = hal::normL2Sqr_(data.ptr<float>(i), data.ptr<float>(centers[0]), dims);
|
||||
sum0 += dist[i];
|
||||
}
|
||||
|
||||
@@ -185,7 +186,7 @@ public:
|
||||
if (onlyDistance)
|
||||
{
|
||||
const float* center = centers.ptr<float>(labels[i]);
|
||||
distances[i] = normL2Sqr(sample, center, dims);
|
||||
distances[i] = hal::normL2Sqr_(sample, center, dims);
|
||||
continue;
|
||||
}
|
||||
else
|
||||
@@ -196,7 +197,7 @@ public:
|
||||
for (int k = 0; k < K; k++)
|
||||
{
|
||||
const float* center = centers.ptr<float>(k);
|
||||
const double dist = normL2Sqr(sample, center, dims);
|
||||
const double dist = hal::normL2Sqr_(sample, center, dims);
|
||||
|
||||
if (min_dist > dist)
|
||||
{
|
||||
@@ -379,7 +380,7 @@ double cv::kmeans( InputArray _data, int K,
|
||||
if (labels[i] != max_k)
|
||||
continue;
|
||||
const float* sample = data.ptr<float>(i);
|
||||
double dist = normL2Sqr(sample, _base_center, dims);
|
||||
double dist = hal::normL2Sqr_(sample, _base_center, dims);
|
||||
|
||||
if (max_dist <= dist)
|
||||
{
|
||||
|
||||
@@ -4,20 +4,24 @@
|
||||
|
||||
// glue
|
||||
|
||||
CvMatND::CvMatND(const cv::Mat& m)
|
||||
CvMatND cvMatND(const cv::Mat& m)
|
||||
{
|
||||
cvInitMatNDHeader(this, m.dims, m.size, m.type(), m.data );
|
||||
CvMatND self;
|
||||
cvInitMatNDHeader(&self, m.dims, m.size, m.type(), m.data );
|
||||
int i, d = m.dims;
|
||||
for( i = 0; i < d; i++ )
|
||||
dim[i].step = (int)m.step[i];
|
||||
type |= m.flags & cv::Mat::CONTINUOUS_FLAG;
|
||||
self.dim[i].step = (int)m.step[i];
|
||||
self.type |= m.flags & cv::Mat::CONTINUOUS_FLAG;
|
||||
return self;
|
||||
}
|
||||
|
||||
_IplImage::_IplImage(const cv::Mat& m)
|
||||
_IplImage cvIplImage(const cv::Mat& m)
|
||||
{
|
||||
_IplImage self;
|
||||
CV_Assert( m.dims <= 2 );
|
||||
cvInitImageHeader(this, m.size(), cvIplDepth(m.flags), m.channels());
|
||||
cvSetData(this, m.data, (int)m.step[0]);
|
||||
cvInitImageHeader(&self, cvSize(m.size()), cvIplDepth(m.flags), m.channels());
|
||||
cvSetData(&self, m.data, (int)m.step[0]);
|
||||
return self;
|
||||
}
|
||||
|
||||
namespace cv {
|
||||
@@ -222,7 +226,7 @@ CV_IMPL void cvSetIdentity( CvArr* arr, CvScalar value )
|
||||
|
||||
CV_IMPL CvScalar cvTrace( const CvArr* arr )
|
||||
{
|
||||
return cv::trace(cv::cvarrToMat(arr));
|
||||
return cvScalar(cv::trace(cv::cvarrToMat(arr)));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -457,12 +457,12 @@ void write( FileStorage& fs, const String& name, const Mat& value )
|
||||
{
|
||||
if( value.dims <= 2 )
|
||||
{
|
||||
CvMat mat = value;
|
||||
CvMat mat = cvMat(value);
|
||||
cvWrite( *fs, name.size() ? name.c_str() : 0, &mat );
|
||||
}
|
||||
else
|
||||
{
|
||||
CvMatND mat = value;
|
||||
CvMatND mat = cvMatND(value);
|
||||
cvWrite( *fs, name.size() ? name.c_str() : 0, &mat );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ static void icvWriteMat( CvFileStorage* fs, const char* name, const void* struct
|
||||
{
|
||||
const CvMat* mat = (const CvMat*)struct_ptr;
|
||||
char dt[16];
|
||||
CvSize size;
|
||||
cv::Size size;
|
||||
int y;
|
||||
|
||||
assert( CV_IS_MAT_HDR_Z(mat) );
|
||||
@@ -380,7 +380,7 @@ static void icvWriteImage( CvFileStorage* fs, const char* name, const void* stru
|
||||
{
|
||||
const IplImage* image = (const IplImage*)struct_ptr;
|
||||
char dt_buf[16], *dt;
|
||||
CvSize size;
|
||||
cv::Size size;
|
||||
int y, depth;
|
||||
|
||||
assert( CV_IS_IMAGE(image) );
|
||||
@@ -435,7 +435,7 @@ static void* icvReadImage( CvFileStorage* fs, CvFileNode* node )
|
||||
CvFileNode* data;
|
||||
CvFileNode* roi_node;
|
||||
CvSeqReader reader;
|
||||
CvRect roi;
|
||||
cv::Rect roi;
|
||||
int y, width, height, elem_type, coi, depth;
|
||||
const char* origin, *data_order;
|
||||
|
||||
@@ -472,7 +472,7 @@ static void* icvReadImage( CvFileStorage* fs, CvFileNode* node )
|
||||
roi.height = cvReadIntByName( fs, roi_node, "height", 0 );
|
||||
coi = cvReadIntByName( fs, roi_node, "coi", 0 );
|
||||
|
||||
cvSetImageROI( image, roi );
|
||||
cvSetImageROI( image, cvRect(roi) );
|
||||
cvSetImageCOI( image, coi );
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ CV_IMPL CvScalar cvSum( const CvArr* srcarr )
|
||||
sum = cv::Scalar(sum[coi-1]);
|
||||
}
|
||||
}
|
||||
return sum;
|
||||
return cvScalar(sum);
|
||||
}
|
||||
|
||||
CV_IMPL int cvCountNonZero( const CvArr* imgarr )
|
||||
@@ -43,7 +43,7 @@ cvAvg( const void* imgarr, const void* maskarr )
|
||||
mean = cv::Scalar(mean[coi-1]);
|
||||
}
|
||||
}
|
||||
return mean;
|
||||
return cvScalar(mean);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1123,7 +1123,6 @@ template<typename R> struct TheTest
|
||||
return *this;
|
||||
}
|
||||
|
||||
#if CV_FP16
|
||||
TheTest & test_loadstore_fp16_f32()
|
||||
{
|
||||
printf("test_loadstore_fp16_f32 ...\n");
|
||||
@@ -1133,14 +1132,14 @@ template<typename R> struct TheTest
|
||||
AlignedData<v_float32> data_f32; data_f32.a.clear();
|
||||
AlignedData<v_uint16> out;
|
||||
|
||||
R r1 = vx_load_fp16_f32((short*)data.a.d);
|
||||
R r1 = vx_load_expand((const cv::float16_t*)data.a.d);
|
||||
R r2(r1);
|
||||
EXPECT_EQ(1.0f, r1.get0());
|
||||
vx_store(data_f32.a.d, r2);
|
||||
EXPECT_EQ(-2.0f, data_f32.a.d[R::nlanes - 1]);
|
||||
|
||||
out.a.clear();
|
||||
vx_store_fp16((short*)out.a.d, r2);
|
||||
v_pack_store((cv::float16_t*)out.a.d, r2);
|
||||
for (int i = 0; i < R::nlanes; ++i)
|
||||
{
|
||||
EXPECT_EQ(data.a[i], out.a[i]) << "i=" << i;
|
||||
@@ -1148,9 +1147,8 @@ template<typename R> struct TheTest
|
||||
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CV_SIMD_FP16
|
||||
#if 0
|
||||
TheTest & test_loadstore_fp16()
|
||||
{
|
||||
printf("test_loadstore_fp16 ...\n");
|
||||
@@ -1165,7 +1163,7 @@ template<typename R> struct TheTest
|
||||
|
||||
// check some initialization methods
|
||||
R r1 = data.u;
|
||||
R r2 = vx_load_f16(data.a.d);
|
||||
R r2 = vx_load_expand((const float16_t*)data.a.d);
|
||||
R r3(r2);
|
||||
EXPECT_EQ(data.u[0], r1.get0());
|
||||
EXPECT_EQ(data.a[0], r2.get0());
|
||||
|
||||
@@ -214,7 +214,7 @@ protected:
|
||||
}
|
||||
|
||||
CvMat* m = (CvMat*)fs["test_mat"].readObj();
|
||||
CvMat _test_mat = test_mat;
|
||||
CvMat _test_mat = cvMat(test_mat);
|
||||
double max_diff = 0;
|
||||
CvMat stub1, _test_stub1;
|
||||
cvReshape(m, &stub1, 1, 0);
|
||||
@@ -234,7 +234,7 @@ protected:
|
||||
cvReleaseMat(&m);
|
||||
|
||||
CvMatND* m_nd = (CvMatND*)fs["test_mat_nd"].readObj();
|
||||
CvMatND _test_mat_nd = test_mat_nd;
|
||||
CvMatND _test_mat_nd = cvMatND(test_mat_nd);
|
||||
|
||||
if( !m_nd || !CV_IS_MATND(m_nd) )
|
||||
{
|
||||
@@ -263,7 +263,7 @@ protected:
|
||||
|
||||
MatND mat_nd2;
|
||||
fs["test_mat_nd"] >> mat_nd2;
|
||||
CvMatND m_nd2 = mat_nd2;
|
||||
CvMatND m_nd2 = cvMatND(mat_nd2);
|
||||
cvGetMat(&m_nd2, &stub, 0, 1);
|
||||
cvReshape(&stub, &stub1, 1, 0);
|
||||
|
||||
|
||||
@@ -415,15 +415,15 @@ TEST(Core_PCA, accuracy)
|
||||
|
||||
#ifdef CHECK_C
|
||||
// 4. check C PCA & ROW
|
||||
_points = rPoints;
|
||||
_testPoints = rTestPoints;
|
||||
_avg = avg;
|
||||
_eval = eval;
|
||||
_evec = evec;
|
||||
_points = cvMat(rPoints);
|
||||
_testPoints = cvMat(rTestPoints);
|
||||
_avg = cvMat(avg);
|
||||
_eval = cvMat(eval);
|
||||
_evec = cvMat(evec);
|
||||
prjTestPoints.create(rTestPoints.rows, maxComponents, rTestPoints.type() );
|
||||
backPrjTestPoints.create(rPoints.size(), rPoints.type() );
|
||||
_prjTestPoints = prjTestPoints;
|
||||
_backPrjTestPoints = backPrjTestPoints;
|
||||
_prjTestPoints = cvMat(prjTestPoints);
|
||||
_backPrjTestPoints = cvMat(backPrjTestPoints);
|
||||
|
||||
cvCalcPCA( &_points, &_avg, &_eval, &_evec, CV_PCA_DATA_AS_ROW );
|
||||
cvProjectPCA( &_testPoints, &_avg, &_evec, &_prjTestPoints );
|
||||
@@ -435,13 +435,13 @@ TEST(Core_PCA, accuracy)
|
||||
ASSERT_LE(err, diffBackPrjEps) << "bad accuracy of cvBackProjectPCA() (CV_PCA_DATA_AS_ROW)";
|
||||
|
||||
// 5. check C PCA & COL
|
||||
_points = cPoints;
|
||||
_testPoints = cTestPoints;
|
||||
avg = avg.t(); _avg = avg;
|
||||
eval = eval.t(); _eval = eval;
|
||||
evec = evec.t(); _evec = evec;
|
||||
prjTestPoints = prjTestPoints.t(); _prjTestPoints = prjTestPoints;
|
||||
backPrjTestPoints = backPrjTestPoints.t(); _backPrjTestPoints = backPrjTestPoints;
|
||||
_points = cvMat(cPoints);
|
||||
_testPoints = cvMat(cTestPoints);
|
||||
avg = avg.t(); _avg = cvMat(avg);
|
||||
eval = eval.t(); _eval = cvMat(eval);
|
||||
evec = evec.t(); _evec = cvMat(evec);
|
||||
prjTestPoints = prjTestPoints.t(); _prjTestPoints = cvMat(prjTestPoints);
|
||||
backPrjTestPoints = backPrjTestPoints.t(); _backPrjTestPoints = cvMat(backPrjTestPoints);
|
||||
|
||||
cvCalcPCA( &_points, &_avg, &_eval, &_evec, CV_PCA_DATA_AS_COL );
|
||||
cvProjectPCA( &_testPoints, &_avg, &_evec, &_prjTestPoints );
|
||||
@@ -615,7 +615,7 @@ void Core_ArrayOpTest::run( int /* start_from */)
|
||||
{
|
||||
int sz3[] = {5, 10, 15};
|
||||
MatND A(3, sz3, CV_32F), B(3, sz3, CV_16SC4);
|
||||
CvMatND matA = A, matB = B;
|
||||
CvMatND matA = cvMatND(A), matB = cvMatND(B);
|
||||
RNG rng;
|
||||
rng.fill(A, CV_RAND_UNI, Scalar::all(-10), Scalar::all(10));
|
||||
rng.fill(B, CV_RAND_UNI, Scalar::all(-10), Scalar::all(10));
|
||||
@@ -625,8 +625,8 @@ void Core_ArrayOpTest::run( int /* start_from */)
|
||||
Scalar val1(-1000, 30, 3, 8);
|
||||
cvSetRealND(&matA, idx0, val0);
|
||||
cvSetReal3D(&matA, idx1[0], idx1[1], idx1[2], -val0);
|
||||
cvSetND(&matB, idx0, val1);
|
||||
cvSet3D(&matB, idx1[0], idx1[1], idx1[2], -val1);
|
||||
cvSetND(&matB, idx0, cvScalar(val1));
|
||||
cvSet3D(&matB, idx1[0], idx1[1], idx1[2], cvScalar(-val1));
|
||||
Ptr<CvMatND> matC(cvCloneMatND(&matB));
|
||||
|
||||
if( A.at<float>(idx0[0], idx0[1], idx0[2]) != val0 ||
|
||||
|
||||
@@ -526,7 +526,7 @@ void Core_CrossProductTest::get_test_array_types_and_sizes( int,
|
||||
RNG& rng = ts->get_rng();
|
||||
int depth = cvtest::randInt(rng) % 2 + CV_32F;
|
||||
int cn = cvtest::randInt(rng) & 1 ? 3 : 1, type = CV_MAKETYPE(depth, cn);
|
||||
CvSize sz;
|
||||
Size sz;
|
||||
|
||||
types[INPUT][0] = types[INPUT][1] = types[OUTPUT][0] = types[REF_OUTPUT][0] = type;
|
||||
|
||||
@@ -549,7 +549,7 @@ void Core_CrossProductTest::run_func()
|
||||
|
||||
void Core_CrossProductTest::prepare_to_validation( int )
|
||||
{
|
||||
CvScalar a(0), b(0), c(0);
|
||||
cv::Scalar a, b, c;
|
||||
|
||||
if( test_mat[INPUT][0].rows > 1 )
|
||||
{
|
||||
@@ -595,7 +595,7 @@ void Core_CrossProductTest::prepare_to_validation( int )
|
||||
}
|
||||
else
|
||||
{
|
||||
cvSet1D( test_array[REF_OUTPUT][0], 0, c );
|
||||
cvSet1D( test_array[REF_OUTPUT][0], 0, cvScalar(c) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -896,7 +896,7 @@ double Core_TransformTest::get_success_error_level( int test_case_idx, int i, in
|
||||
|
||||
void Core_TransformTest::run_func()
|
||||
{
|
||||
CvMat _m = test_mat[INPUT][1], _shift = test_mat[INPUT][2];
|
||||
CvMat _m = cvMat(test_mat[INPUT][1]), _shift = cvMat(test_mat[INPUT][2]);
|
||||
cvTransform( test_array[INPUT][0], test_array[OUTPUT][0], &_m, _shift.data.ptr ? &_shift : 0);
|
||||
}
|
||||
|
||||
@@ -1010,7 +1010,7 @@ double Core_PerspectiveTransformTest::get_success_error_level( int test_case_idx
|
||||
|
||||
void Core_PerspectiveTransformTest::run_func()
|
||||
{
|
||||
CvMat _m = test_mat[INPUT][1];
|
||||
CvMat _m = cvMat(test_mat[INPUT][1]);
|
||||
cvPerspectiveTransform( test_array[INPUT][0], test_array[OUTPUT][0], &_m );
|
||||
}
|
||||
|
||||
@@ -1117,7 +1117,7 @@ static void cvTsPerspectiveTransform( const CvArr* _src, CvArr* _dst, const CvMa
|
||||
|
||||
void Core_PerspectiveTransformTest::prepare_to_validation( int )
|
||||
{
|
||||
CvMat transmat = test_mat[INPUT][1];
|
||||
CvMat transmat = cvMat(test_mat[INPUT][1]);
|
||||
cvTsPerspectiveTransform( test_array[INPUT][0], test_array[REF_OUTPUT][0], &transmat );
|
||||
}
|
||||
|
||||
@@ -1287,9 +1287,9 @@ int Core_CovarMatrixTest::prepare_test_case( int test_case_idx )
|
||||
if( single_matrix )
|
||||
{
|
||||
if( !are_images )
|
||||
*((CvMat*)_hdr_data) = test_mat[INPUT][0];
|
||||
*((CvMat*)_hdr_data) = cvMat(test_mat[INPUT][0]);
|
||||
else
|
||||
*((IplImage*)_hdr_data) = test_mat[INPUT][0];
|
||||
*((IplImage*)_hdr_data) = cvIplImage(test_mat[INPUT][0]);
|
||||
temp_hdrs[0] = _hdr_data;
|
||||
}
|
||||
else
|
||||
@@ -1304,9 +1304,9 @@ int Core_CovarMatrixTest::prepare_test_case( int test_case_idx )
|
||||
part = test_mat[INPUT][0].col(i);
|
||||
|
||||
if( !are_images )
|
||||
*((CvMat*)ptr) = part;
|
||||
*((CvMat*)ptr) = cvMat(part);
|
||||
else
|
||||
*((IplImage*)ptr) = part;
|
||||
*((IplImage*)ptr) = cvIplImage(part);
|
||||
|
||||
temp_hdrs[i] = ptr;
|
||||
}
|
||||
@@ -1539,7 +1539,7 @@ static double cvTsLU( CvMat* a, CvMat* b=NULL, CvMat* x=NULL, int* rank=0 )
|
||||
void Core_DetTest::prepare_to_validation( int )
|
||||
{
|
||||
test_mat[INPUT][0].convertTo(test_mat[TEMP][0], test_mat[TEMP][0].type());
|
||||
CvMat temp0 = test_mat[TEMP][0];
|
||||
CvMat temp0 = cvMat(test_mat[TEMP][0]);
|
||||
test_mat[REF_OUTPUT][0].at<Scalar>(0,0) = cvRealScalar(cvTsLU(&temp0, 0, 0));
|
||||
}
|
||||
|
||||
@@ -1676,7 +1676,7 @@ void Core_InvertTest::prepare_to_validation( int )
|
||||
Mat& temp1 = test_mat[TEMP][1];
|
||||
Mat& dst0 = test_mat[REF_OUTPUT][0];
|
||||
Mat& dst = test_mat[OUTPUT][0];
|
||||
CvMat _input = input;
|
||||
CvMat _input = cvMat(input);
|
||||
double ratio = 0, det = cvTsSVDet( &_input, &ratio );
|
||||
double threshold = (input.depth() == CV_32F ? FLT_EPSILON : DBL_EPSILON)*1000;
|
||||
|
||||
@@ -1733,7 +1733,7 @@ void Core_SolveTest::get_test_array_types_and_sizes( int test_case_idx, vector<v
|
||||
RNG& rng = ts->get_rng();
|
||||
int bits = cvtest::randInt(rng);
|
||||
Base::get_test_array_types_and_sizes( test_case_idx, sizes, types );
|
||||
CvSize in_sz = sizes[INPUT][0];
|
||||
CvSize in_sz = cvSize(sizes[INPUT][0]);
|
||||
if( in_sz.width > in_sz.height )
|
||||
in_sz = cvSize(in_sz.height, in_sz.width);
|
||||
Base::get_test_array_types_and_sizes( test_case_idx, sizes, types );
|
||||
@@ -1813,14 +1813,14 @@ void Core_SolveTest::prepare_to_validation( int )
|
||||
Mat& temp1 = test_mat[TEMP][1];
|
||||
cvtest::convert(input, temp1, temp1.type());
|
||||
dst = Scalar::all(0);
|
||||
CvMat _temp1 = temp1;
|
||||
CvMat _temp1 = cvMat(temp1);
|
||||
double det = cvTsLU( &_temp1, 0, 0 );
|
||||
dst0 = Scalar::all(det != 0);
|
||||
return;
|
||||
}
|
||||
|
||||
double threshold = (input.type() == CV_32F ? FLT_EPSILON : DBL_EPSILON)*1000;
|
||||
CvMat _input = input;
|
||||
CvMat _input = cvMat(input);
|
||||
double ratio = 0, det = cvTsSVDet( &_input, &ratio );
|
||||
if( det < threshold || ratio < threshold )
|
||||
{
|
||||
@@ -2105,7 +2105,7 @@ void Core_SVBkSbTest::get_test_array_types_and_sizes( int test_case_idx, vector<
|
||||
int bits = cvtest::randInt(rng);
|
||||
Base::get_test_array_types_and_sizes( test_case_idx, sizes, types );
|
||||
int min_size, i, m, n;
|
||||
CvSize b_size;
|
||||
cv::Size b_size;
|
||||
|
||||
min_size = MIN( sizes[INPUT][0].width, sizes[INPUT][0].height );
|
||||
|
||||
@@ -2122,7 +2122,7 @@ void Core_SVBkSbTest::get_test_array_types_and_sizes( int test_case_idx, vector<
|
||||
n = sizes[INPUT][0].width;
|
||||
|
||||
sizes[INPUT][1] = Size(0,0);
|
||||
b_size = Size(m,m);
|
||||
b_size = cvSize(m, m);
|
||||
if( have_b )
|
||||
{
|
||||
sizes[INPUT][1].height = sizes[INPUT][0].height;
|
||||
@@ -2174,7 +2174,7 @@ int Core_SVBkSbTest::prepare_test_case( int test_case_idx )
|
||||
cvtest::copy( temp, input );
|
||||
}
|
||||
|
||||
CvMat _input = input;
|
||||
CvMat _input = cvMat(input);
|
||||
cvSVD( &_input, test_array[TEMP][0], test_array[TEMP][1], test_array[TEMP][2], flags );
|
||||
}
|
||||
|
||||
@@ -2210,7 +2210,7 @@ void Core_SVBkSbTest::prepare_to_validation( int )
|
||||
Size w_size = compact ? Size(min_size,min_size) : Size(m,n);
|
||||
Mat& w = test_mat[TEMP][0];
|
||||
Mat wdb( w_size.height, w_size.width, CV_64FC1 );
|
||||
CvMat _w = w, _wdb = wdb;
|
||||
CvMat _w = cvMat(w), _wdb = cvMat(wdb);
|
||||
// use exactly the same threshold as in icvSVD... ,
|
||||
// so the changes in the library and here should be synchronized.
|
||||
double threshold = cv::sum(w)[0]*(DBL_EPSILON*2);//(is_float ? FLT_EPSILON*10 : DBL_EPSILON*2);
|
||||
@@ -3230,6 +3230,22 @@ softdouble naiveExp(softdouble x)
|
||||
}
|
||||
}
|
||||
|
||||
static float makeFP32(int sign, int exponent, int significand)
|
||||
{
|
||||
Cv32suf x;
|
||||
x.u = (unsigned)(((sign & 1) << 31) | ((exponent&255) << 23) | (significand & 0x7fffff));
|
||||
return x.f;
|
||||
}
|
||||
|
||||
static float makeRandomFP32(RNG& rng, int sign, int exprange)
|
||||
{
|
||||
if( sign == -1 )
|
||||
sign = rng() % 2;
|
||||
int exponent = rng() % exprange;
|
||||
int significand = rng() % (1 << 23);
|
||||
return makeFP32(sign, exponent, significand);
|
||||
}
|
||||
|
||||
TEST(Core_SoftFloat, exp32)
|
||||
{
|
||||
//special cases
|
||||
@@ -3246,13 +3262,11 @@ TEST(Core_SoftFloat, exp32)
|
||||
inputs.push_back(softfloat::min());
|
||||
for(int i = 0; i < 50000; i++)
|
||||
{
|
||||
Cv32suf x;
|
||||
x.fmt.sign = rng() % 2;
|
||||
x.fmt.exponent = rng() % (10 + 127); //bigger exponent will produce inf
|
||||
x.fmt.significand = rng() % (1 << 23);
|
||||
if(softfloat(x.f) > ln_max)
|
||||
x.f = rng.uniform(0.0f, (float)ln_max);
|
||||
inputs.push_back(softfloat(x.f));
|
||||
float x = makeRandomFP32(rng, -1, 10+127 //bigger exponent will produce inf
|
||||
);
|
||||
if(softfloat(x) > ln_max)
|
||||
x = rng.uniform(0.0f, (float)ln_max);
|
||||
inputs.push_back(softfloat(x));
|
||||
}
|
||||
|
||||
for(size_t i = 0; i < inputs.size(); i++)
|
||||
@@ -3323,11 +3337,7 @@ TEST(Core_SoftFloat, log32)
|
||||
EXPECT_TRUE(log(softfloat::nan()).isNaN());
|
||||
for(int i = 0; i < nValues; i++)
|
||||
{
|
||||
Cv32suf x;
|
||||
x.fmt.sign = 1;
|
||||
x.fmt.exponent = rng() % 255;
|
||||
x.fmt.significand = rng() % (1 << 23);
|
||||
softfloat x32(x.f);
|
||||
softfloat x32(makeRandomFP32(rng, 1, 255));
|
||||
ASSERT_TRUE(log(x32).isNaN());
|
||||
}
|
||||
EXPECT_TRUE(log(softfloat::zero()).isInf());
|
||||
@@ -3340,11 +3350,7 @@ TEST(Core_SoftFloat, log32)
|
||||
inputs.push_back(softfloat::max());
|
||||
for(int i = 0; i < nValues; i++)
|
||||
{
|
||||
Cv32suf x;
|
||||
x.fmt.sign = 0;
|
||||
x.fmt.exponent = rng() % 255;
|
||||
x.fmt.significand = rng() % (1 << 23);
|
||||
inputs.push_back(softfloat(x.f));
|
||||
inputs.push_back(softfloat(makeRandomFP32(rng, 0, 255)));
|
||||
}
|
||||
|
||||
for(size_t i = 0; i < inputs.size(); i++)
|
||||
@@ -3426,11 +3432,7 @@ TEST(Core_SoftFloat, cbrt32)
|
||||
inputs.push_back(softfloat::min());
|
||||
for(int i = 0; i < 50000; i++)
|
||||
{
|
||||
Cv32suf x;
|
||||
x.fmt.sign = rng() % 2;
|
||||
x.fmt.exponent = rng() % 255;
|
||||
x.fmt.significand = rng() % (1 << 23);
|
||||
inputs.push_back(softfloat(x.f));
|
||||
inputs.push_back(softfloat(makeRandomFP32(rng, -1, 255)));
|
||||
}
|
||||
|
||||
for(size_t i = 0; i < inputs.size(); i++)
|
||||
@@ -3522,11 +3524,8 @@ TEST(Core_SoftFloat, pow32)
|
||||
// inf ** y == inf, if y > 0
|
||||
for(size_t i = 0; i < nValues; i++)
|
||||
{
|
||||
Cv32suf x;
|
||||
x.fmt.sign = 0;
|
||||
x.fmt.exponent = rng() % 255;
|
||||
x.fmt.significand = rng() % (1 << 23);
|
||||
softfloat x32 = softfloat(x.f);
|
||||
float x = makeRandomFP32(rng, 0, 255);
|
||||
softfloat x32 = softfloat(x);
|
||||
ASSERT_TRUE(pow( inf, x32).isInf());
|
||||
ASSERT_TRUE(pow(-inf, x32).isInf());
|
||||
ASSERT_EQ(pow( inf, -x32), zero);
|
||||
@@ -3538,17 +3537,9 @@ TEST(Core_SoftFloat, pow32)
|
||||
// x ** y == nan, if x < 0 and y is not integer
|
||||
for(size_t i = 0; i < nValues; i++)
|
||||
{
|
||||
Cv32suf x;
|
||||
x.fmt.sign = 1;
|
||||
x.fmt.exponent = rng() % 255;
|
||||
x.fmt.significand = rng() % (1 << 23);
|
||||
softfloat x32(x.f);
|
||||
Cv32suf y;
|
||||
y.fmt.sign = rng() % 2;
|
||||
//bigger exponent produces integer numbers only
|
||||
y.fmt.exponent = rng() % (23 + 127);
|
||||
y.fmt.significand = rng() % (1 << 23);
|
||||
softfloat y32(y.f);
|
||||
softfloat x32(makeRandomFP32(rng, 1, 255));
|
||||
softfloat y32(makeRandomFP32(rng, -1, 23+127 //bigger exponent produces integer numbers only
|
||||
));
|
||||
int yi = cvRound(y32);
|
||||
if(y32 != softfloat(yi))
|
||||
ASSERT_TRUE(pow(x32, y32).isNaN());
|
||||
@@ -3565,11 +3556,7 @@ TEST(Core_SoftFloat, pow32)
|
||||
// 0 ** y == 0, if y > 0
|
||||
for(size_t i = 0; i < nValues; i++)
|
||||
{
|
||||
Cv32suf x;
|
||||
x.fmt.sign = 0;
|
||||
x.fmt.exponent = rng() % 255;
|
||||
x.fmt.significand = rng() % (1 << 23);
|
||||
softfloat x32(x.f);
|
||||
softfloat x32(makeRandomFP32(rng, 0, 255));
|
||||
ASSERT_TRUE(pow(zero, -x32).isInf());
|
||||
if(x32 != one)
|
||||
{
|
||||
|
||||
@@ -970,7 +970,7 @@ bool CV_OperationsTest::operations1()
|
||||
Size sz(10, 20);
|
||||
if (sz.area() != 200) throw test_excep();
|
||||
if (sz.width != 10 || sz.height != 20) throw test_excep();
|
||||
if (((CvSize)sz).width != 10 || ((CvSize)sz).height != 20) throw test_excep();
|
||||
if (cvSize(sz).width != 10 || cvSize(sz).height != 20) throw test_excep();
|
||||
|
||||
Vec<double, 5> v5d(1, 1, 1, 1, 1);
|
||||
Vec<double, 6> v6d(1, 1, 1, 1, 1, 1);
|
||||
|
||||
Reference in New Issue
Block a user