mirror of
https://github.com/opencv/opencv.git
synced 2026-07-31 00:03:03 +04:00
Merge branch 4.x
This commit is contained in:
@@ -2825,7 +2825,7 @@ void accW_simd_(const ushort* src, float* dst, const uchar* mask, int len, int c
|
||||
v_expand(v_src1, v_src10, v_src11);
|
||||
v_expand(v_src2, v_src20, v_src21);
|
||||
|
||||
v_float32 v_dst00, v_dst01, v_dst02, v_dst10, v_dst11, v_dst20, v_dst21;
|
||||
v_float32 v_dst00, v_dst01, v_dst10, v_dst11, v_dst20, v_dst21;
|
||||
v_load_deinterleave(dst + x * cn , v_dst00, v_dst10, v_dst20);
|
||||
v_load_deinterleave(dst + (x + step) * cn, v_dst01, v_dst11, v_dst21);
|
||||
|
||||
|
||||
@@ -75,10 +75,12 @@ static bool ocl_bilateralFilter_8u(InputArray _src, OutputArray _dst, int d,
|
||||
if (depth != CV_8U || cn > 4)
|
||||
return false;
|
||||
|
||||
if (sigma_color <= 0)
|
||||
sigma_color = 1;
|
||||
if (sigma_space <= 0)
|
||||
sigma_space = 1;
|
||||
constexpr double eps = 1e-6;
|
||||
if( sigma_color <= eps || sigma_space <= eps )
|
||||
{
|
||||
_src.copyTo(_dst);
|
||||
return true;
|
||||
}
|
||||
|
||||
double gauss_color_coeff = -0.5 / (sigma_color * sigma_color);
|
||||
double gauss_space_coeff = -0.5 / (sigma_space * sigma_space);
|
||||
@@ -165,10 +167,12 @@ bilateralFilter_8u( const Mat& src, Mat& dst, int d,
|
||||
|
||||
CV_Assert( (src.type() == CV_8UC1 || src.type() == CV_8UC3) && src.data != dst.data );
|
||||
|
||||
if( sigma_color <= 0 )
|
||||
sigma_color = 1;
|
||||
if( sigma_space <= 0 )
|
||||
sigma_space = 1;
|
||||
constexpr double eps = 1e-6;
|
||||
if( sigma_color <= eps || sigma_space <= eps )
|
||||
{
|
||||
src.copyTo(dst);
|
||||
return;
|
||||
}
|
||||
|
||||
double gauss_color_coeff = -0.5/(sigma_color*sigma_color);
|
||||
double gauss_space_coeff = -0.5/(sigma_space*sigma_space);
|
||||
@@ -232,10 +236,12 @@ bilateralFilter_32f( const Mat& src, Mat& dst, int d,
|
||||
|
||||
CV_Assert( (src.type() == CV_32FC1 || src.type() == CV_32FC3) && src.data != dst.data );
|
||||
|
||||
if( sigma_color <= 0 )
|
||||
sigma_color = 1;
|
||||
if( sigma_space <= 0 )
|
||||
sigma_space = 1;
|
||||
constexpr double eps = 1e-6;
|
||||
if( sigma_color <= eps || sigma_space <= eps )
|
||||
{
|
||||
src.copyTo(dst);
|
||||
return;
|
||||
}
|
||||
|
||||
double gauss_color_coeff = -0.5/(sigma_color*sigma_color);
|
||||
double gauss_space_coeff = -0.5/(sigma_space*sigma_space);
|
||||
@@ -358,9 +364,16 @@ static bool ipp_bilateralFilter(Mat &src, Mat &dst, int d, double sigmaColor, do
|
||||
#ifdef HAVE_IPP_IW
|
||||
CV_INSTRUMENT_REGION_IPP();
|
||||
|
||||
constexpr double eps = 1e-6;
|
||||
if( sigmaColor <= eps || sigmaSpace <= eps )
|
||||
{
|
||||
src.copyTo(dst);
|
||||
return true;
|
||||
}
|
||||
|
||||
int radius = IPP_MAX(((d <= 0)?cvRound(sigmaSpace*1.5):d/2), 1);
|
||||
Ipp32f valSquareSigma = (Ipp32f)((sigmaColor <= 0)?1:sigmaColor*sigmaColor);
|
||||
Ipp32f posSquareSigma = (Ipp32f)((sigmaSpace <= 0)?1:sigmaSpace*sigmaSpace);
|
||||
Ipp32f valSquareSigma = (Ipp32f)(sigmaColor*sigmaColor);
|
||||
Ipp32f posSquareSigma = (Ipp32f)(sigmaSpace*sigmaSpace);
|
||||
|
||||
// Acquire data and begin processing
|
||||
try
|
||||
|
||||
@@ -257,6 +257,41 @@ bool oclCvtColorBGR2HLS( InputArray _src, OutputArray _dst, int bidx, bool full
|
||||
return h.run();
|
||||
}
|
||||
|
||||
static UMat init_sdiv_table()
|
||||
{
|
||||
cv::Mat sdiv_mat(1, 256, CV_32SC1);
|
||||
int* sdiv = sdiv_mat.ptr<int>();
|
||||
|
||||
const int hsv_shift = 12;
|
||||
const int v = 255 << hsv_shift;
|
||||
|
||||
sdiv[0] = 0;
|
||||
for(int i = 1; i < 256; i++ )
|
||||
sdiv[i] = saturate_cast<int>(v/(1.*i));
|
||||
|
||||
cv::UMat result;
|
||||
sdiv_mat.copyTo(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
static UMat init_hdiv_table(int hrange)
|
||||
{
|
||||
cv::Mat hdiv_mat(1, 256, CV_32SC1);
|
||||
int* hdiv = hdiv_mat.ptr<int>();
|
||||
|
||||
const int hsv_shift = 12;
|
||||
const int v = hrange << hsv_shift;
|
||||
|
||||
hdiv[0] = 0;
|
||||
for (int i = 1; i < 256; i++ )
|
||||
hdiv[i] = saturate_cast<int>(v/(6.*i));
|
||||
|
||||
cv::UMat result;
|
||||
hdiv_mat.copyTo(result);
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
bool oclCvtColorBGR2HSV( InputArray _src, OutputArray _dst, int bidx, bool full )
|
||||
{
|
||||
OclHelper< Set<3, 4>, Set<3>, Set<CV_8U, CV_32F> > h(_src, _dst, 3);
|
||||
@@ -274,41 +309,22 @@ bool oclCvtColorBGR2HSV( InputArray _src, OutputArray _dst, int bidx, bool full
|
||||
|
||||
if(_src.depth() == CV_8U)
|
||||
{
|
||||
static UMat sdiv_data;
|
||||
static UMat hdiv_data180;
|
||||
static UMat hdiv_data256;
|
||||
static int sdiv_table[256];
|
||||
static int hdiv_table180[256];
|
||||
static int hdiv_table256[256];
|
||||
static volatile bool initialized180 = false, initialized256 = false;
|
||||
volatile bool & initialized = hrange == 180 ? initialized180 : initialized256;
|
||||
static UMat sdiv_data = init_sdiv_table();
|
||||
UMat hdiv_data;
|
||||
|
||||
if (!initialized)
|
||||
if (hrange == 180)
|
||||
{
|
||||
int * const hdiv_table = hrange == 180 ? hdiv_table180 : hdiv_table256, hsv_shift = 12;
|
||||
UMat & hdiv_data = hrange == 180 ? hdiv_data180 : hdiv_data256;
|
||||
|
||||
sdiv_table[0] = hdiv_table180[0] = hdiv_table256[0] = 0;
|
||||
|
||||
int v = 255 << hsv_shift;
|
||||
if (!initialized180 && !initialized256)
|
||||
{
|
||||
for(int i = 1; i < 256; i++ )
|
||||
sdiv_table[i] = saturate_cast<int>(v/(1.*i));
|
||||
Mat(1, 256, CV_32SC1, sdiv_table).copyTo(sdiv_data);
|
||||
}
|
||||
|
||||
v = hrange << hsv_shift;
|
||||
for (int i = 1; i < 256; i++ )
|
||||
hdiv_table[i] = saturate_cast<int>(v/(6.*i));
|
||||
|
||||
Mat(1, 256, CV_32SC1, hdiv_table).copyTo(hdiv_data);
|
||||
initialized = true;
|
||||
static UMat hdiv_data180 = init_hdiv_table(180);
|
||||
hdiv_data = hdiv_data180;
|
||||
}
|
||||
else
|
||||
{
|
||||
static UMat hdiv_data256 = init_hdiv_table(256);
|
||||
hdiv_data = hdiv_data256;
|
||||
}
|
||||
|
||||
h.setArg(ocl::KernelArg::PtrReadOnly(sdiv_data));
|
||||
h.setArg(hrange == 256 ? ocl::KernelArg::PtrReadOnly(hdiv_data256) :
|
||||
ocl::KernelArg::PtrReadOnly(hdiv_data180));
|
||||
h.setArg(ocl::KernelArg::PtrReadOnly(hdiv_data));
|
||||
}
|
||||
|
||||
return h.run();
|
||||
|
||||
@@ -850,7 +850,7 @@ struct RGB2HLS_b
|
||||
for ( ; j <= dn*bufChannels - nBlock*bufChannels;
|
||||
j += nBlock*bufChannels, src += nBlock*4)
|
||||
{
|
||||
v_uint8 rgb0, rgb1, rgb2, rgb3, dummy;
|
||||
v_uint8 rgb0, rgb1, rgb2, dummy;
|
||||
v_load_deinterleave(src, rgb0, rgb1, rgb2, dummy);
|
||||
|
||||
v_uint16 d0,d1,d2,d3,d4,d5;
|
||||
|
||||
@@ -1395,6 +1395,26 @@ inline int hal_ni_polygonMoments(const uchar* src_data, size_t src_size, int src
|
||||
#define cv_hal_polygonMoments hal_ni_polygonMoments
|
||||
//! @endcond
|
||||
|
||||
/**
|
||||
@brief Calculates a histogram of a set of arrays
|
||||
@param src_data Source imgage data
|
||||
@param src_step Source image step
|
||||
@param src_type Source image type
|
||||
@param src_width Source image width
|
||||
@param src_height Source image height
|
||||
@param hist_data Histogram data
|
||||
@param hist_size Histogram size
|
||||
@param ranges Array of dims arrays of the histogram bin boundaries
|
||||
@param uniform Flag indicating whether the histogram is uniform or not
|
||||
@param accumulate Accumulation flag
|
||||
*/
|
||||
inline int hal_ni_calcHist(const uchar* src_data, size_t src_step, int src_type, int src_width, int src_height, float* hist_data, int hist_size, const float** ranges, bool uniform, bool accumulate)
|
||||
{ return CV_HAL_ERROR_NOT_IMPLEMENTED; }
|
||||
|
||||
//! @cond IGNORED
|
||||
#define cv_hal_calcHist hal_ni_calcHist
|
||||
//! @endcond
|
||||
|
||||
//! @}
|
||||
|
||||
#if defined(__clang__)
|
||||
|
||||
@@ -910,6 +910,11 @@ void cv::calcHist( const Mat* images, int nimages, const int* channels,
|
||||
&& _mask.empty() && images[0].dims <= 2 && ranges && ranges[0],
|
||||
ipp_calchist(images[0], hist, histSize[0], ranges, uniform, accumulate));
|
||||
|
||||
if (nimages == 1 && dims == 1 && channels && channels[0] == 0 && _mask.empty() && images[0].dims <= 2 && ranges && ranges[0]) {
|
||||
CALL_HAL(calcHist, cv_hal_calcHist, images[0].data, images[0].step, images[0].type(), images[0].cols, images[0].rows,
|
||||
hist.ptr<float>(), histSize[0], ranges, uniform, accumulate);
|
||||
}
|
||||
|
||||
Mat ihist = hist;
|
||||
ihist.flags = (ihist.flags & ~CV_MAT_TYPE_MASK)|CV_32S;
|
||||
|
||||
@@ -1986,6 +1991,46 @@ double cv::compareHist( InputArray _H1, InputArray _H2, int method )
|
||||
|
||||
if( (method == cv::HISTCMP_CHISQR) || (method == cv::HISTCMP_CHISQR_ALT))
|
||||
{
|
||||
#if CV_SIMD_64F || CV_SIMD_SCALABLE_64F
|
||||
v_float64 v_eps = vx_setall_f64(DBL_EPSILON);
|
||||
v_float64 v_one = vx_setall_f64(1.f);
|
||||
v_float64 v_zero = vx_setzero_f64();
|
||||
v_float64 v_res = vx_setzero_f64();
|
||||
for ( ; j <= len - VTraits<v_float32>::vlanes(); j += VTraits<v_float32>::vlanes())
|
||||
{
|
||||
v_float32 v_h1 = vx_load(h1 + j), v_h2 = vx_load(h2 + j);
|
||||
v_float64 v_h1_l = v_cvt_f64(v_h1), v_h1_h = v_cvt_f64_high(v_h1);
|
||||
v_float64 v_h2_l = v_cvt_f64(v_h2), v_h2_h = v_cvt_f64_high(v_h2);
|
||||
|
||||
v_float64 v_a_l, v_a_h;
|
||||
v_a_l = v_sub(v_h1_l, v_h2_l);
|
||||
v_a_h = v_sub(v_h1_h, v_h2_h);
|
||||
|
||||
v_float64 v_b_l, v_b_h;
|
||||
if (method == cv::HISTCMP_CHISQR)
|
||||
{
|
||||
v_b_l = v_h1_l;
|
||||
v_b_h = v_h1_h;
|
||||
}
|
||||
else
|
||||
{
|
||||
v_b_l = v_add(v_h1_l, v_h2_l);
|
||||
v_b_h = v_add(v_h1_h, v_h2_h);
|
||||
}
|
||||
|
||||
// low part
|
||||
auto v_res_l = v_mul(v_mul(v_a_l, v_a_l), v_div(v_one, v_b_l));
|
||||
auto mask = v_gt(v_abs(v_b_l), v_eps);
|
||||
v_res_l = v_select(mask, v_res_l, v_zero);
|
||||
v_res = v_add(v_res, v_res_l);
|
||||
// high part
|
||||
auto v_res_h = v_mul(v_mul(v_a_h, v_a_h), v_div(v_one, v_b_h));
|
||||
mask = v_gt(v_abs(v_b_h), v_eps);
|
||||
v_res_h = v_select(mask, v_res_h, v_zero);
|
||||
v_res = v_add(v_res, v_res_h);
|
||||
}
|
||||
result += v_reduce_sum(v_res);
|
||||
#endif
|
||||
for( ; j < len; j++ )
|
||||
{
|
||||
double a = h1[j] - h2[j];
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
// Copyright (C) 2000-2008, 2018, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Copyright (C) 2014-2015, Itseez Inc., all rights reserved.
|
||||
// Copyright (C) 2025, Advanced Micro Devices, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
@@ -693,8 +694,16 @@ medianBlur_SortNet( const Mat& _src, Mat& _dst, int m )
|
||||
#else
|
||||
int nlanes = 1;
|
||||
#endif
|
||||
for( ; j <= size.width - nlanes - cn; j += nlanes )
|
||||
for (; j < size.width - cn; j += nlanes)
|
||||
{
|
||||
//handling tail in vectorized path itself
|
||||
if ( j > size.width - cn - nlanes ) {
|
||||
if (j == cn || src == dst) {
|
||||
break;
|
||||
}
|
||||
j = size.width - cn - nlanes;
|
||||
}
|
||||
|
||||
VT p0 = vop.load(row0+j-cn), p1 = vop.load(row0+j), p2 = vop.load(row0+j+cn);
|
||||
VT p3 = vop.load(row1+j-cn), p4 = vop.load(row1+j), p5 = vop.load(row1+j+cn);
|
||||
VT p6 = vop.load(row2+j-cn), p7 = vop.load(row2+j), p8 = vop.load(row2+j+cn);
|
||||
@@ -705,6 +714,7 @@ medianBlur_SortNet( const Mat& _src, Mat& _dst, int m )
|
||||
vop(p3, p6); vop(p1, p4); vop(p2, p5); vop(p4, p7);
|
||||
vop(p4, p2); vop(p6, p4); vop(p4, p2);
|
||||
vop.store(dst+j, p4);
|
||||
|
||||
}
|
||||
|
||||
limit = size.width;
|
||||
@@ -798,8 +808,14 @@ medianBlur_SortNet( const Mat& _src, Mat& _dst, int m )
|
||||
#else
|
||||
int nlanes = 1;
|
||||
#endif
|
||||
for( ; j <= size.width - nlanes - cn*2; j += nlanes )
|
||||
for( ; j < size.width - cn*2; j += nlanes)
|
||||
{
|
||||
if ( j > size.width - cn*2 - nlanes ) {
|
||||
if (j == cn*2 || src == dst) {
|
||||
break;
|
||||
}
|
||||
j = size.width - cn*2 - nlanes;
|
||||
}
|
||||
VT p0 = vop.load(row[0]+j-cn*2), p5 = vop.load(row[1]+j-cn*2), p10 = vop.load(row[2]+j-cn*2), p15 = vop.load(row[3]+j-cn*2), p20 = vop.load(row[4]+j-cn*2);
|
||||
VT p1 = vop.load(row[0]+j-cn*1), p6 = vop.load(row[1]+j-cn*1), p11 = vop.load(row[2]+j-cn*1), p16 = vop.load(row[3]+j-cn*1), p21 = vop.load(row[4]+j-cn*1);
|
||||
VT p2 = vop.load(row[0]+j-cn*0), p7 = vop.load(row[1]+j-cn*0), p12 = vop.load(row[2]+j-cn*0), p17 = vop.load(row[3]+j-cn*0), p22 = vop.load(row[4]+j-cn*0);
|
||||
@@ -830,6 +846,7 @@ medianBlur_SortNet( const Mat& _src, Mat& _dst, int m )
|
||||
vop(p13, p17); vop(p3, p15); vop(p11, p23); vop(p11, p15); vop(p7, p19);
|
||||
vop(p7, p11); vop(p11, p13); vop(p11, p12);
|
||||
vop.store(dst+j, p12);
|
||||
|
||||
}
|
||||
|
||||
limit = size.width;
|
||||
|
||||
@@ -769,7 +769,6 @@ template <> int PyrUpVecVOneRow<int, uchar>(int** src, uchar* dst, int width)
|
||||
r20 = *(row2 + x);
|
||||
int _2r10 = r10 + r10;
|
||||
int d = r00 + r20 + (_2r10 + _2r10 + _2r10);
|
||||
int d_shifted = (r10 + r20) << 2;
|
||||
// Similar to v_rshr_pack_u<6>(d, vx_setzero_s16()).get0()
|
||||
*(dst + x) = (int)((((unsigned int)d) + ((1 << (6 - 1)))) >> 6);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user