1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 15:23:05 +04:00

Merge remote-tracking branch 'upstream/3.4' into merge-3.4

This commit is contained in:
Alexander Alekhin
2018-09-07 12:40:27 +03:00
141 changed files with 3074 additions and 4777 deletions
+1 -1
View File
@@ -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
+110 -12
View File
@@ -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() {}
+384 -105
View File
@@ -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. */