1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 07:43:03 +04:00

Merge branch 4.x

This commit is contained in:
Alexander Smorkalov
2024-09-10 10:15:22 +03:00
26 changed files with 237 additions and 204 deletions
@@ -66,6 +66,9 @@
#define __CV_CUDA_HOST_DEVICE__
#endif
#include "opencv2/core/cvdef.h"
#include "opencv2/core.hpp"
namespace cv
{
namespace cuda
@@ -124,6 +127,11 @@ namespace cv
int cols;
int rows;
CV_NODISCARD_STD __CV_CUDA_HOST_DEVICE__ Size size() const { return {cols, rows}; }
CV_NODISCARD_STD __CV_CUDA_HOST_DEVICE__ T& operator ()(const Point &pos) { return (*this)(pos.y, pos.x); }
CV_NODISCARD_STD __CV_CUDA_HOST_DEVICE__ const T& operator ()(const Point &pos) const { return (*this)(pos.y, pos.x); }
using PtrStep<T>::operator();
};
typedef PtrStepSz<unsigned char> PtrStepSzb;
+5 -1
View File
@@ -758,7 +758,11 @@ __CV_ENUM_FLAGS_BITWISE_XOR_EQ (EnumType, EnumType)
# define __has_cpp_attribute(__x) 0
# endif
# if __has_cpp_attribute(nodiscard)
# define CV_NODISCARD_STD [[nodiscard]]
# if defined(__NVCC__) && __CUDACC_VER_MAJOR__ < 12
# define CV_NODISCARD_STD
# else
# define CV_NODISCARD_STD [[nodiscard]]
# endif
# elif __cplusplus >= 201703L
// available when compiler is C++17 compliant
# define CV_NODISCARD_STD [[nodiscard]]
@@ -650,16 +650,18 @@ inline v_float32x8 v256_shuffle(const v_float32x8 &a)
template<int m>
inline v_float64x4 v256_shuffle(const v_float64x4 &a)
{
int imm8 = m & 0b0001; //0 or 1
if (m & 0x0b0010) imm8 |= 0b0100;
//else imm8 |= 0b0000;
if (m & 0x0b0100) imm8 |= 0b110000; //2 or 3
else imm8 |= 0b100000;
if (m & 0x0b1000) imm8 |= 0b11000000;
else imm8 |= 0b10000000;
const int m1 = m & 0b1;
const int m2 = m & 0b10;
const int m3 = m & 0b100;
const int m4 = m & 0b1000;
const int m5 = m2 << 1;
const int m6 = m3 << 2;
const int m7 = m4 << 3;
const int m8 = m1 & m5 & m6 & m7;
return v_float64x4(__lasx_xvpermi_d(*((__m256i*)&a.val), imm8));
return v_float64x4(__lasx_xvshuf4i_d(*((__m256i*)&a.val), *((__m256i*)&a.val), m8));
}
template<typename _Tpvec>
inline void v256_zip(const _Tpvec& a, const _Tpvec& b, _Tpvec& ab0, _Tpvec& ab1)
{
@@ -1100,7 +1102,7 @@ inline v_uint8x32 v_rotate_right(const v_uint8x32& a, const v_uint8x32& b)
template<int imm>
inline v_uint8x32 v_rotate_left(const v_uint8x32& a)
{
enum {IMM_L = (imm - 16) & 0xFF};
enum {IMM_L = ((imm - 16) & 0xFF) > 31 ? 31 : ((imm - 16) & 0xFF)};
enum {IMM_R = (16 - imm) & 0xFF};
if (imm == 0) return a;
@@ -1117,7 +1119,7 @@ inline v_uint8x32 v_rotate_left(const v_uint8x32& a)
template<int imm>
inline v_uint8x32 v_rotate_right(const v_uint8x32& a)
{
enum {IMM_L = (imm - 16) & 0xFF};
enum {IMM_L = ((imm - 16) & 0xFF) > 31 ? 31 : ((imm - 16) & 0xFF)};
if (imm == 0) return a;
if (imm > 32) return v_uint8x32();
+5 -2
View File
@@ -358,7 +358,8 @@ typedef TestBaseWithParam<FlipParams> FlipFixture;
OCL_PERF_TEST_P(FlipFixture, Flip,
::testing::Combine(OCL_TEST_SIZES,
OCL_TEST_TYPES, FlipType::all()))
::testing::Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_16UC1, CV_32FC1, CV_32FC4),
FlipType::all()))
{
const FlipParams params = GetParam();
const Size srcSize = get<0>(params);
@@ -388,7 +389,9 @@ typedef tuple<Size, MatType, RotateType> RotateParams;
typedef TestBaseWithParam<RotateParams> RotateFixture;
OCL_PERF_TEST_P(RotateFixture, rotate,
::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES, RotateType::all()))
::testing::Combine(OCL_TEST_SIZES,
::testing::Values(CV_8UC1, CV_8UC2, CV_8UC4, CV_32FC1, CV_32FC4),
RotateType::all()))
{
const RotateParams params = GetParam();
const Size srcSize = get<0>(params);
+41
View File
@@ -1049,6 +1049,13 @@ void cv::add( InputArray src1, InputArray src2, OutputArray dst,
{
CV_INSTRUMENT_REGION();
CV_Assert(src1.empty() == src2.empty());
if (src1.empty() && src2.empty())
{
dst.release();
return;
}
arithm_op(src1, src2, dst, mask, dtype, getAddTab(), false, 0, OCL_OP_ADD );
}
@@ -1057,6 +1064,13 @@ void cv::subtract( InputArray _src1, InputArray _src2, OutputArray _dst,
{
CV_INSTRUMENT_REGION();
CV_Assert(_src1.empty() == _src2.empty());
if (_src1.empty() && _src2.empty())
{
_dst.release();
return;
}
ExtendedTypeFunc subExtFunc = getSubExtFunc(_src1.depth(), _src2.depth(), dtype < 0 ? _dst.depth() : dtype);
arithm_op(_src1, _src2, _dst, mask, dtype, getSubTab(), false, 0, OCL_OP_SUB,
/* extendedFunc */ subExtFunc);
@@ -1066,6 +1080,13 @@ void cv::absdiff( InputArray src1, InputArray src2, OutputArray dst )
{
CV_INSTRUMENT_REGION();
CV_Assert(src1.empty() == src2.empty());
if (src1.empty() && src2.empty())
{
dst.release();
return;
}
arithm_op(src1, src2, dst, noArray(), -1, getAbsDiffTab(), false, 0, OCL_OP_ABSDIFF);
}
@@ -1186,6 +1207,13 @@ void divide(InputArray src1, InputArray src2,
{
CV_INSTRUMENT_REGION();
CV_Assert(src1.empty() == src2.empty());
if (src1.empty() && src2.empty())
{
dst.release();
return;
}
arithm_op(src1, src2, dst, noArray(), dtype, getDivTab(), true, &scale, OCL_OP_DIV_SCALE);
}
@@ -1194,6 +1222,12 @@ void divide(double scale, InputArray src2,
{
CV_INSTRUMENT_REGION();
if (src2.empty())
{
dst.release();
return;
}
arithm_op(src2, src2, dst, noArray(), dtype, getRecipTab(), true, &scale, OCL_OP_RECIP_SCALE);
}
@@ -1236,6 +1270,13 @@ void cv::addWeighted( InputArray src1, double alpha, InputArray src2,
{
CV_INSTRUMENT_REGION();
CV_Assert(src1.empty() == src2.empty());
if (src1.empty() && src2.empty())
{
dst.release();
return;
}
double scalars[] = {alpha, beta, gamma};
arithm_op(src1, src2, dst, noArray(), dtype, getAddWeightedTab(), true, scalars, OCL_OP_ADDW);
}
+4 -2
View File
@@ -21,6 +21,8 @@ static MinMaxIdxFunc getMinMaxIdxFunc(int depth)
CV_CPU_DISPATCH_MODES_ALL);
}
// The function expects 1-based indexing for ofs
// Zero is treated as invalid offset (not found)
static void ofs2idx(const Mat& a, size_t ofs, int* idx)
{
int i, d = a.dims;
@@ -324,9 +326,9 @@ void cv::minMaxIdx(InputArray _src, double* minVal,
{
// minIdx[0] and minIdx[0] are always 0 for "flatten" version
if (minIdx)
ofs2idx(src, minIdx[1], minIdx);
ofs2idx(src, minIdx[1]+1, minIdx);
if (maxIdx)
ofs2idx(src, maxIdx[1], maxIdx);
ofs2idx(src, maxIdx[1]+1, maxIdx);
return;
}
else if (res != CV_HAL_ERROR_NOT_IMPLEMENTED)