mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 23:33:05 +04:00
Merge remote-tracking branch 'upstream/3.4' into merge-3.4
This commit is contained in:
@@ -664,6 +664,8 @@ inline void v_mul_expand(const v_uint32x8& a, const v_uint32x8& b,
|
||||
v_zip(v_uint64x4(v0), v_uint64x4(v1), c, d);
|
||||
}
|
||||
|
||||
inline v_int16x16 v_mul_hi(const v_int16x16& a, const v_int16x16& b) { return v_int16x16(_mm256_mulhi_epi16(a.val, b.val)); }
|
||||
inline v_uint16x16 v_mul_hi(const v_uint16x16& a, const v_uint16x16& b) { return v_uint16x16(_mm256_mulhi_epu16(a.val, b.val)); }
|
||||
|
||||
/** Non-saturating arithmetics **/
|
||||
#define OPENCV_HAL_IMPL_AVX_BIN_FUNC(func, _Tpvec, intrin) \
|
||||
|
||||
@@ -891,6 +891,20 @@ template<typename _Tp, int n> inline void v_mul_expand(const v_reg<_Tp, n>& a, c
|
||||
}
|
||||
}
|
||||
|
||||
/** @brief Multiply and extract high part
|
||||
|
||||
Multiply values two registers and store high part of the results.
|
||||
Implemented only for 16-bit source types (v_int16x8, v_uint16x8). Returns \f$ a*b >> 16 \f$
|
||||
*/
|
||||
template<typename _Tp, int n> inline v_reg<_Tp, n> v_mul_hi(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b)
|
||||
{
|
||||
typedef typename V_TypeTraits<_Tp>::w_type w_type;
|
||||
v_reg<_Tp, n> c;
|
||||
for (int i = 0; i < n; i++)
|
||||
c.s[i] = (_Tp)(((w_type)a.s[i] * b.s[i]) >> sizeof(_Tp)*8);
|
||||
return c;
|
||||
}
|
||||
|
||||
//! @cond IGNORED
|
||||
template<typename _Tp, int n> inline void v_hsum(const v_reg<_Tp, n>& a,
|
||||
v_reg<typename V_TypeTraits<_Tp>::w_type, n/2>& c)
|
||||
|
||||
@@ -553,6 +553,21 @@ inline void v_mul_expand(const v_uint32x4& a, const v_uint32x4& b,
|
||||
d.val = vmull_u32(vget_high_u32(a.val), vget_high_u32(b.val));
|
||||
}
|
||||
|
||||
inline v_int16x8 v_mul_hi(const v_int16x8& a, const v_int16x8& b)
|
||||
{
|
||||
return v_int16x8(vcombine_s16(
|
||||
vshrn_n_s32(vmull_s16( vget_low_s16(a.val), vget_low_s16(b.val)), 16),
|
||||
vshrn_n_s32(vmull_s16(vget_high_s16(a.val), vget_high_s16(b.val)), 16)
|
||||
));
|
||||
}
|
||||
inline v_uint16x8 v_mul_hi(const v_uint16x8& a, const v_uint16x8& b)
|
||||
{
|
||||
return v_uint16x8(vcombine_u16(
|
||||
vshrn_n_u32(vmull_u16( vget_low_u16(a.val), vget_low_u16(b.val)), 16),
|
||||
vshrn_n_u32(vmull_u16(vget_high_u16(a.val), vget_high_u16(b.val)), 16)
|
||||
));
|
||||
}
|
||||
|
||||
inline v_int32x4 v_dotprod(const v_int16x8& a, const v_int16x8& b)
|
||||
{
|
||||
int32x4_t c = vmull_s16(vget_low_s16(a.val), vget_low_s16(b.val));
|
||||
|
||||
@@ -737,6 +737,9 @@ inline void v_mul_expand(const v_uint32x4& a, const v_uint32x4& b,
|
||||
d.val = _mm_unpackhi_epi64(c0, c1);
|
||||
}
|
||||
|
||||
inline v_int16x8 v_mul_hi(const v_int16x8& a, const v_int16x8& b) { return v_int16x8(_mm_mulhi_epi16(a.val, b.val)); }
|
||||
inline v_uint16x8 v_mul_hi(const v_uint16x8& a, const v_uint16x8& b) { return v_uint16x8(_mm_mulhi_epu16(a.val, b.val)); }
|
||||
|
||||
inline v_int32x4 v_dotprod(const v_int16x8& a, const v_int16x8& b)
|
||||
{
|
||||
return v_int32x4(_mm_madd_epi16(a.val, b.val));
|
||||
|
||||
@@ -457,6 +457,21 @@ inline void v_mul_expand(const v_uint32x4& a, const v_uint32x4& b, v_uint64x2& c
|
||||
d.val = vec_mul(vec_unpacklu(a.val), vec_unpacklu(b.val));
|
||||
}
|
||||
|
||||
inline v_int16x8 v_mul_hi(const v_int16x8& a, const v_int16x8& b)
|
||||
{
|
||||
return v_int16x8(vec_packs(
|
||||
vec_sra(vec_mul(vec_unpackh(a.val), vec_unpackh(b.val)), vec_uint4_sp(16)),
|
||||
vec_sra(vec_mul(vec_unpackl(a.val), vec_unpackl(b.val)), vec_uint4_sp(16))
|
||||
));
|
||||
}
|
||||
inline v_uint16x8 v_mul_hi(const v_uint16x8& a, const v_uint16x8& b)
|
||||
{
|
||||
return v_uint16x8(vec_packs(
|
||||
vec_sr(vec_mul(vec_unpackhu(a.val), vec_unpackhu(b.val)), vec_uint4_sp(16)),
|
||||
vec_sr(vec_mul(vec_unpacklu(a.val), vec_unpacklu(b.val)), vec_uint4_sp(16))
|
||||
));
|
||||
}
|
||||
|
||||
/** Non-saturating arithmetics **/
|
||||
#define OPENCV_HAL_IMPL_VSX_BIN_FUNC(func, intrin) \
|
||||
template<typename _Tpvec> \
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
#ifndef OPENCV_CORE_IPPASYNC_HPP
|
||||
#define OPENCV_CORE_IPPASYNC_HPP
|
||||
|
||||
#ifdef HAVE_IPP_A
|
||||
#ifdef HAVE_IPP_A // this file will be removed in OpenCV 4.0
|
||||
|
||||
#include "opencv2/core.hpp"
|
||||
#include <ipp_async_op.h>
|
||||
|
||||
@@ -146,6 +146,12 @@ synonym is needed to generate Python/Java etc. wrappers properly. At the functio
|
||||
level their use is similar, but _InputArray::getMat(idx) should be used to get header for the
|
||||
idx-th component of the outer vector and _InputArray::size().area() should be used to find the
|
||||
number of components (vectors/matrices) of the outer vector.
|
||||
|
||||
In general, type support is limited to cv::Mat types. Other types are forbidden.
|
||||
But in some cases we need to support passing of custom non-general Mat types, like arrays of cv::KeyPoint, cv::DMatch, etc.
|
||||
This data is not intented to be interpreted as an image data, or processed somehow like regular cv::Mat.
|
||||
To pass such custom type use rawIn() / rawOut() / rawInOut() wrappers.
|
||||
Custom type is wrapped as Mat-compatible `CV_8UC<N>` values (N = sizeof(T), N <= CV_CN_MAX).
|
||||
*/
|
||||
class CV_EXPORTS _InputArray
|
||||
{
|
||||
@@ -199,6 +205,9 @@ public:
|
||||
template<typename _Tp, std::size_t _Nm> _InputArray(const std::array<_Tp, _Nm>& arr);
|
||||
template<std::size_t _Nm> _InputArray(const std::array<Mat, _Nm>& arr);
|
||||
|
||||
template<typename _Tp> static _InputArray rawIn(const std::vector<_Tp>& vec);
|
||||
template<typename _Tp, std::size_t _Nm> static _InputArray rawIn(const std::array<_Tp, _Nm>& arr);
|
||||
|
||||
Mat getMat(int idx=-1) const;
|
||||
Mat getMat_(int idx=-1) const;
|
||||
UMat getUMat(int idx=-1) const;
|
||||
@@ -328,12 +337,13 @@ public:
|
||||
_OutputArray(const UMat& m);
|
||||
_OutputArray(const std::vector<UMat>& vec);
|
||||
|
||||
#ifdef CV_CXX_STD_ARRAY
|
||||
template<typename _Tp, std::size_t _Nm> _OutputArray(std::array<_Tp, _Nm>& arr);
|
||||
template<typename _Tp, std::size_t _Nm> _OutputArray(const std::array<_Tp, _Nm>& arr);
|
||||
template<std::size_t _Nm> _OutputArray(std::array<Mat, _Nm>& arr);
|
||||
template<std::size_t _Nm> _OutputArray(const std::array<Mat, _Nm>& arr);
|
||||
#endif
|
||||
|
||||
template<typename _Tp> static _OutputArray rawOut(std::vector<_Tp>& vec);
|
||||
template<typename _Tp, std::size_t _Nm> static _OutputArray rawOut(std::array<_Tp, _Nm>& arr);
|
||||
|
||||
bool fixedSize() const;
|
||||
bool fixedType() const;
|
||||
@@ -397,15 +407,23 @@ public:
|
||||
_InputOutputArray(const UMat& m);
|
||||
_InputOutputArray(const std::vector<UMat>& vec);
|
||||
|
||||
#ifdef CV_CXX_STD_ARRAY
|
||||
template<typename _Tp, std::size_t _Nm> _InputOutputArray(std::array<_Tp, _Nm>& arr);
|
||||
template<typename _Tp, std::size_t _Nm> _InputOutputArray(const std::array<_Tp, _Nm>& arr);
|
||||
template<std::size_t _Nm> _InputOutputArray(std::array<Mat, _Nm>& arr);
|
||||
template<std::size_t _Nm> _InputOutputArray(const std::array<Mat, _Nm>& arr);
|
||||
#endif
|
||||
|
||||
template<typename _Tp> static _InputOutputArray rawInOut(std::vector<_Tp>& vec);
|
||||
template<typename _Tp, std::size_t _Nm> _InputOutputArray rawInOut(std::array<_Tp, _Nm>& arr);
|
||||
|
||||
};
|
||||
|
||||
/** Helper to wrap custom types. @see InputArray */
|
||||
template<typename _Tp> static inline _InputArray rawIn(_Tp& v);
|
||||
/** Helper to wrap custom types. @see InputArray */
|
||||
template<typename _Tp> static inline _OutputArray rawOut(_Tp& v);
|
||||
/** Helper to wrap custom types. @see InputArray */
|
||||
template<typename _Tp> static inline _InputOutputArray rawInOut(_Tp& v);
|
||||
|
||||
CV__DEBUG_NS_END
|
||||
|
||||
typedef const _InputArray& InputArray;
|
||||
@@ -991,11 +1009,9 @@ public:
|
||||
*/
|
||||
template<typename _Tp> explicit Mat(const std::initializer_list<int> sizes, const std::initializer_list<_Tp> list);
|
||||
|
||||
#ifdef CV_CXX_STD_ARRAY
|
||||
/** @overload
|
||||
*/
|
||||
template<typename _Tp, size_t _Nm> explicit Mat(const std::array<_Tp, _Nm>& arr, bool copyData=false);
|
||||
#endif
|
||||
|
||||
/** @overload
|
||||
*/
|
||||
@@ -1630,9 +1646,7 @@ public:
|
||||
template<typename _Tp, int n> operator Vec<_Tp, n>() const;
|
||||
template<typename _Tp, int m, int n> operator Matx<_Tp, m, n>() const;
|
||||
|
||||
#ifdef CV_CXX_STD_ARRAY
|
||||
template<typename _Tp, std::size_t _Nm> operator std::array<_Tp, _Nm>() const;
|
||||
#endif
|
||||
|
||||
/** @brief Reports whether the matrix is continuous or not.
|
||||
|
||||
@@ -2214,9 +2228,7 @@ public:
|
||||
Mat_(std::initializer_list<_Tp> values);
|
||||
explicit Mat_(const std::initializer_list<int> sizes, const std::initializer_list<_Tp> values);
|
||||
|
||||
#ifdef CV_CXX_STD_ARRAY
|
||||
template <std::size_t _Nm> explicit Mat_(const std::array<_Tp, _Nm>& arr, bool copyData=false);
|
||||
#endif
|
||||
|
||||
Mat_& operator = (const Mat& m);
|
||||
Mat_& operator = (const Mat_& m);
|
||||
@@ -2314,10 +2326,8 @@ public:
|
||||
//! conversion to vector.
|
||||
operator std::vector<_Tp>() const;
|
||||
|
||||
#ifdef CV_CXX_STD_ARRAY
|
||||
//! conversion to array.
|
||||
template<std::size_t _Nm> operator std::array<_Tp, _Nm>() const;
|
||||
#endif
|
||||
|
||||
//! conversion to Vec
|
||||
template<int n> operator Vec<typename DataType<_Tp>::channel_type, n>() const;
|
||||
|
||||
@@ -61,6 +61,16 @@ CV__DEBUG_NS_BEGIN
|
||||
|
||||
//! @cond IGNORED
|
||||
|
||||
////////////////////////// Custom (raw) type wrapper //////////////////////////
|
||||
|
||||
template<typename _Tp> static inline
|
||||
int rawType()
|
||||
{
|
||||
CV_StaticAssert(sizeof(_Tp) <= CV_CN_MAX, "sizeof(_Tp) is too large");
|
||||
const int elemSize = sizeof(_Tp);
|
||||
return (int)CV_MAKETYPE(CV_8U, elemSize);
|
||||
}
|
||||
|
||||
//////////////////////// Input/Output Arrays ////////////////////////
|
||||
|
||||
inline void _InputArray::init(int _flags, const void* _obj)
|
||||
@@ -134,6 +144,25 @@ inline _InputArray::_InputArray(const ogl::Buffer& buf)
|
||||
inline _InputArray::_InputArray(const cuda::HostMem& cuda_mem)
|
||||
{ init(CUDA_HOST_MEM + ACCESS_READ, &cuda_mem); }
|
||||
|
||||
template<typename _Tp> inline
|
||||
_InputArray _InputArray::rawIn(const std::vector<_Tp>& vec)
|
||||
{
|
||||
_InputArray v;
|
||||
v.flags = _InputArray::FIXED_TYPE + _InputArray::STD_VECTOR + rawType<_Tp>() + ACCESS_READ;
|
||||
v.obj = (void*)&vec;
|
||||
return v;
|
||||
}
|
||||
|
||||
template<typename _Tp, std::size_t _Nm> inline
|
||||
_InputArray _InputArray::rawIn(const std::array<_Tp, _Nm>& arr)
|
||||
{
|
||||
_InputArray v;
|
||||
v.flags = FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_READ;
|
||||
v.obj = (void*)arr.data();
|
||||
v.sz = Size(1, _Nm);
|
||||
return v;
|
||||
}
|
||||
|
||||
inline _InputArray::~_InputArray() {}
|
||||
|
||||
inline Mat _InputArray::getMat(int i) const
|
||||
@@ -261,6 +290,25 @@ inline _OutputArray::_OutputArray(const ogl::Buffer& buf)
|
||||
inline _OutputArray::_OutputArray(const cuda::HostMem& cuda_mem)
|
||||
{ init(FIXED_TYPE + FIXED_SIZE + CUDA_HOST_MEM + ACCESS_WRITE, &cuda_mem); }
|
||||
|
||||
template<typename _Tp> inline
|
||||
_OutputArray _OutputArray::rawOut(std::vector<_Tp>& vec)
|
||||
{
|
||||
_OutputArray v;
|
||||
v.flags = _InputArray::FIXED_TYPE + _InputArray::STD_VECTOR + rawType<_Tp>() + ACCESS_WRITE;
|
||||
v.obj = (void*)&vec;
|
||||
return v;
|
||||
}
|
||||
|
||||
template<typename _Tp, std::size_t _Nm> inline
|
||||
_OutputArray _OutputArray::rawOut(std::array<_Tp, _Nm>& arr)
|
||||
{
|
||||
_OutputArray v;
|
||||
v.flags = FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_WRITE;
|
||||
v.obj = (void*)arr.data();
|
||||
v.sz = Size(1, _Nm);
|
||||
return v;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline _InputOutputArray::_InputOutputArray() { init(ACCESS_RW, 0); }
|
||||
@@ -370,6 +418,30 @@ inline _InputOutputArray::_InputOutputArray(const ogl::Buffer& buf)
|
||||
inline _InputOutputArray::_InputOutputArray(const cuda::HostMem& cuda_mem)
|
||||
{ init(FIXED_TYPE + FIXED_SIZE + CUDA_HOST_MEM + ACCESS_RW, &cuda_mem); }
|
||||
|
||||
template<typename _Tp> inline
|
||||
_InputOutputArray _InputOutputArray::rawInOut(std::vector<_Tp>& vec)
|
||||
{
|
||||
_InputOutputArray v;
|
||||
v.flags = _InputArray::FIXED_TYPE + _InputArray::STD_VECTOR + rawType<_Tp>() + ACCESS_RW;
|
||||
v.obj = (void*)&vec;
|
||||
return v;
|
||||
}
|
||||
|
||||
template<typename _Tp, std::size_t _Nm> inline
|
||||
_InputOutputArray _InputOutputArray::rawInOut(std::array<_Tp, _Nm>& arr)
|
||||
{
|
||||
_InputOutputArray v;
|
||||
v.flags = FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_RW;
|
||||
v.obj = (void*)arr.data();
|
||||
v.sz = Size(1, _Nm);
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
template<typename _Tp> static inline _InputArray rawIn(_Tp& v) { return _InputArray::rawIn(v); }
|
||||
template<typename _Tp> static inline _OutputArray rawOut(_Tp& v) { return _OutputArray::rawOut(v); }
|
||||
template<typename _Tp> static inline _InputOutputArray rawInOut(_Tp& v) { return _InputOutputArray::rawInOut(v); }
|
||||
|
||||
CV__DEBUG_NS_END
|
||||
|
||||
//////////////////////////////////////////// Mat //////////////////////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user