diff --git a/3rdparty/ndsrvp/include/imgproc.hpp b/3rdparty/ndsrvp/include/imgproc.hpp index db0ee05132..16ecc81cfc 100644 --- a/3rdparty/ndsrvp/include/imgproc.hpp +++ b/3rdparty/ndsrvp/include/imgproc.hpp @@ -101,6 +101,24 @@ int filterFree(cvhalFilter2D *context); #undef cv_hal_filterFree #define cv_hal_filterFree (cv::ndsrvp::filterFree) +// ################ medianBlur ################ + +int medianBlur(const uchar* src_data, size_t src_step, + uchar* dst_data, size_t dst_step, + int width, int height, int depth, int cn, int ksize); + +#undef cv_hal_medianBlur +#define cv_hal_medianBlur (cv::ndsrvp::medianBlur) + +// ################ bilateralFilter ################ + +int bilateralFilter(const uchar* src_data, size_t src_step, + uchar* dst_data, size_t dst_step, int width, int height, int depth, + int cn, int d, double sigma_color, double sigma_space, int border_type); + +#undef cv_hal_bilateralFilter +#define cv_hal_bilateralFilter (cv::ndsrvp::bilateralFilter) + } // namespace ndsrvp } // namespace cv diff --git a/3rdparty/ndsrvp/src/bilateralFilter.cpp b/3rdparty/ndsrvp/src/bilateralFilter.cpp new file mode 100644 index 0000000000..c7a51b4199 --- /dev/null +++ b/3rdparty/ndsrvp/src/bilateralFilter.cpp @@ -0,0 +1,270 @@ +// 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 "ndsrvp_hal.hpp" +#include "opencv2/imgproc/hal/interface.h" +#include "cvutils.hpp" + +namespace cv { + +namespace ndsrvp { + +static void bilateralFilterProcess(uchar* dst_data, size_t dst_step, uchar* pad_data, size_t pad_step, + int width, int height, int cn, int radius, int maxk, + int* space_ofs, float *space_weight, float *color_weight) +{ + int i, j, k; + + for( i = 0; i < height; i++ ) + { + const uchar* sptr = pad_data + (i + radius) * pad_step + radius * cn; + uchar* dptr = dst_data + i * dst_step; + + if( cn == 1 ) + { + std::vector buf(width + width, 0.0); + float *sum = &buf[0]; + float *wsum = sum + width; + k = 0; + for(; k <= maxk-4; k+=4) + { + const uchar* ksptr0 = sptr + space_ofs[k]; + const uchar* ksptr1 = sptr + space_ofs[k+1]; + const uchar* ksptr2 = sptr + space_ofs[k+2]; + const uchar* ksptr3 = sptr + space_ofs[k+3]; + j = 0; + for (; j < width; j++) + { + int rval = sptr[j]; + + int val = ksptr0[j]; + float w = space_weight[k] * color_weight[std::abs(val - rval)]; + wsum[j] += w; + sum[j] += val * w; + + val = ksptr1[j]; + w = space_weight[k+1] * color_weight[std::abs(val - rval)]; + wsum[j] += w; + sum[j] += val * w; + + val = ksptr2[j]; + w = space_weight[k+2] * color_weight[std::abs(val - rval)]; + wsum[j] += w; + sum[j] += val * w; + + val = ksptr3[j]; + w = space_weight[k+3] * color_weight[std::abs(val - rval)]; + wsum[j] += w; + sum[j] += val * w; + } + } + for(; k < maxk; k++) + { + const uchar* ksptr = sptr + space_ofs[k]; + j = 0; + for (; j < width; j++) + { + int val = ksptr[j]; + float w = space_weight[k] * color_weight[std::abs(val - sptr[j])]; + wsum[j] += w; + sum[j] += val * w; + } + } + j = 0; + for (; j < width; j++) + { + // overflow is not possible here => there is no need to use cv::saturate_cast + ndsrvp_assert(fabs(wsum[j]) > 0); + dptr[j] = (uchar)(sum[j] / wsum[j] + 0.5); + } + } + else + { + ndsrvp_assert( cn == 3 ); + std::vector buf(width * 3 + width); + float *sum_b = &buf[0]; + float *sum_g = sum_b + width; + float *sum_r = sum_g + width; + float *wsum = sum_r + width; + k = 0; + for(; k <= maxk-4; k+=4) + { + const uchar* ksptr0 = sptr + space_ofs[k]; + const uchar* ksptr1 = sptr + space_ofs[k+1]; + const uchar* ksptr2 = sptr + space_ofs[k+2]; + const uchar* ksptr3 = sptr + space_ofs[k+3]; + const uchar* rsptr = sptr; + j = 0; + for(; j < width; j++, rsptr += 3, ksptr0 += 3, ksptr1 += 3, ksptr2 += 3, ksptr3 += 3) + { + int rb = rsptr[0], rg = rsptr[1], rr = rsptr[2]; + + int b = ksptr0[0], g = ksptr0[1], r = ksptr0[2]; + float w = space_weight[k] * color_weight[std::abs(b - rb) + std::abs(g - rg) + std::abs(r - rr)]; + wsum[j] += w; + sum_b[j] += b * w; sum_g[j] += g * w; sum_r[j] += r * w; + + b = ksptr1[0]; g = ksptr1[1]; r = ksptr1[2]; + w = space_weight[k+1] * color_weight[std::abs(b - rb) + std::abs(g - rg) + std::abs(r - rr)]; + wsum[j] += w; + sum_b[j] += b * w; sum_g[j] += g * w; sum_r[j] += r * w; + + b = ksptr2[0]; g = ksptr2[1]; r = ksptr2[2]; + w = space_weight[k+2] * color_weight[std::abs(b - rb) + std::abs(g - rg) + std::abs(r - rr)]; + wsum[j] += w; + sum_b[j] += b * w; sum_g[j] += g * w; sum_r[j] += r * w; + + b = ksptr3[0]; g = ksptr3[1]; r = ksptr3[2]; + w = space_weight[k+3] * color_weight[std::abs(b - rb) + std::abs(g - rg) + std::abs(r - rr)]; + wsum[j] += w; + sum_b[j] += b * w; sum_g[j] += g * w; sum_r[j] += r * w; + } + } + for(; k < maxk; k++) + { + const uchar* ksptr = sptr + space_ofs[k]; + const uchar* rsptr = sptr; + j = 0; + for(; j < width; j++, ksptr += 3, rsptr += 3) + { + int b = ksptr[0], g = ksptr[1], r = ksptr[2]; + float w = space_weight[k] * color_weight[std::abs(b - rsptr[0]) + std::abs(g - rsptr[1]) + std::abs(r - rsptr[2])]; + wsum[j] += w; + sum_b[j] += b * w; sum_g[j] += g * w; sum_r[j] += r * w; + } + } + j = 0; + for(; j < width; j++) + { + ndsrvp_assert(fabs(wsum[j]) > 0); + wsum[j] = 1.f / wsum[j]; + *(dptr++) = (uchar)(sum_b[j] * wsum[j] + 0.5); + *(dptr++) = (uchar)(sum_g[j] * wsum[j] + 0.5); + *(dptr++) = (uchar)(sum_r[j] * wsum[j] + 0.5); + } + } + } +} + +int bilateralFilter(const uchar* src_data, size_t src_step, + uchar* dst_data, size_t dst_step, int width, int height, int depth, + int cn, int d, double sigma_color, double sigma_space, int border_type) +{ + if( depth != CV_8U || !(cn == 1 || cn == 3) || src_data == dst_data) + return CV_HAL_ERROR_NOT_IMPLEMENTED; + + int i, j, maxk, radius; + + if( sigma_color <= 0 ) + sigma_color = 1; + if( sigma_space <= 0 ) + sigma_space = 1; + + double gauss_color_coeff = -0.5/(sigma_color * sigma_color); + double gauss_space_coeff = -0.5/(sigma_space * sigma_space); + + if( d <= 0 ) + radius = (int)(sigma_space * 1.5 + 0.5); + else + radius = d / 2; + + radius = MAX(radius, 1); + d = radius * 2 + 1; + + // no enough submatrix info + // fetch original image data + const uchar *ogn_data = src_data; + int ogn_step = src_step; + + // ROI fully used in the computation + int cal_width = width + d - 1; + int cal_height = height + d - 1; + int cal_x = 0 - radius; // negative if left border exceeded + int cal_y = 0 - radius; // negative if top border exceeded + + // calculate source border + std::vector padding; + padding.resize(cal_width * cal_height * cn); + uchar* pad_data = &padding[0]; + int pad_step = cal_width * cn; + + uchar* pad_ptr; + const uchar* ogn_ptr; + std::vector vec_zeros(cn, 0); + for(i = 0; i < cal_height; i++) + { + int y = borderInterpolate(i + cal_y, height, border_type); + if(y < 0) { + memset(pad_data + i * pad_step, 0, cn * cal_width); + continue; + } + + // left border + j = 0; + for(; j + cal_x < 0; j++) + { + int x = borderInterpolate(j + cal_x, width, border_type); + if(x < 0) // border constant return value -1 + ogn_ptr = &vec_zeros[0]; + else + ogn_ptr = ogn_data + y * ogn_step + x * cn; + pad_ptr = pad_data + i * pad_step + j * cn; + memcpy(pad_ptr, ogn_ptr, cn); + } + + // center + int rborder = MIN(cal_width, width - cal_x); + ogn_ptr = ogn_data + y * ogn_step + (j + cal_x) * cn; + pad_ptr = pad_data + i * pad_step + j * cn; + memcpy(pad_ptr, ogn_ptr, cn * (rborder - j)); + + // right border + j = rborder; + for(; j < cal_width; j++) + { + int x = borderInterpolate(j + cal_x, width, border_type); + if(x < 0) // border constant return value -1 + ogn_ptr = &vec_zeros[0]; + else + ogn_ptr = ogn_data + y * ogn_step + x * cn; + pad_ptr = pad_data + i * pad_step + j * cn; + memcpy(pad_ptr, ogn_ptr, cn); + } + } + + std::vector _color_weight(cn * 256); + std::vector _space_weight(d * d); + std::vector _space_ofs(d * d); + float* color_weight = &_color_weight[0]; + float* space_weight = &_space_weight[0]; + int* space_ofs = &_space_ofs[0]; + + // initialize color-related bilateral filter coefficients + + for( i = 0; i < 256 * cn; i++ ) + color_weight[i] = (float)std::exp(i * i * gauss_color_coeff); + + // initialize space-related bilateral filter coefficients + for( i = -radius, maxk = 0; i <= radius; i++ ) + { + j = -radius; + + for( ; j <= radius; j++ ) + { + double r = std::sqrt((double)i * i + (double)j * j); + if( r > radius ) + continue; + space_weight[maxk] = (float)std::exp(r * r * gauss_space_coeff); + space_ofs[maxk++] = (int)(i * pad_step + j * cn); + } + } + + bilateralFilterProcess(dst_data, dst_step, pad_data, pad_step, width, height, cn, radius, maxk, space_ofs, space_weight, color_weight); + + return CV_HAL_ERROR_OK; +} + +} // namespace ndsrvp + +} // namespace cv diff --git a/3rdparty/ndsrvp/src/filter.cpp b/3rdparty/ndsrvp/src/filter.cpp index 89508eea11..6dea08df64 100644 --- a/3rdparty/ndsrvp/src/filter.cpp +++ b/3rdparty/ndsrvp/src/filter.cpp @@ -132,8 +132,8 @@ int filter(cvhalFilter2D *context, // ROI fully used in the computation int cal_width = width + ctx->kernel_width - 1; int cal_height = height + ctx->kernel_height - 1; - int cal_x = offset_x - ctx->anchor_x; - int cal_y = offset_y - ctx->anchor_y; + int cal_x = offset_x - ctx->anchor_x; // negative if left border exceeded + int cal_y = offset_y - ctx->anchor_y; // negative if top border exceeded // calculate source border ctx->padding.resize(cal_width * cal_height * cnes); diff --git a/3rdparty/ndsrvp/src/medianBlur.cpp b/3rdparty/ndsrvp/src/medianBlur.cpp new file mode 100644 index 0000000000..c511367f31 --- /dev/null +++ b/3rdparty/ndsrvp/src/medianBlur.cpp @@ -0,0 +1,300 @@ +// 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 "ndsrvp_hal.hpp" +#include "opencv2/imgproc/hal/interface.h" +#include "cvutils.hpp" + +namespace cv { + +namespace ndsrvp { + +struct operators_minmax_t { + inline void vector(uint8x8_t & a, uint8x8_t & b) const { + uint8x8_t t = a; + a = __nds__v_umin8(a, b); + b = __nds__v_umax8(t, b); + } + inline void scalar(uchar & a, uchar & b) const { + uchar t = a; + a = __nds__umin8(a, b); + b = __nds__umax8(t, b); + } + inline void vector(int8x8_t & a, int8x8_t & b) const { + int8x8_t t = a; + a = __nds__v_smin8(a, b); + b = __nds__v_smax8(t, b); + } + inline void scalar(schar & a, schar & b) const { + schar t = a; + a = __nds__smin8(a, b); + b = __nds__smax8(t, b); + } + inline void vector(uint16x4_t & a, uint16x4_t & b) const { + uint16x4_t t = a; + a = __nds__v_umin16(a, b); + b = __nds__v_umax16(t, b); + } + inline void scalar(ushort & a, ushort & b) const { + ushort t = a; + a = __nds__umin16(a, b); + b = __nds__umax16(t, b); + } + inline void vector(int16x4_t & a, int16x4_t & b) const { + int16x4_t t = a; + a = __nds__v_smin16(a, b); + b = __nds__v_smax16(t, b); + } + inline void scalar(short & a, short & b) const { + short t = a; + a = __nds__smin16(a, b); + b = __nds__smax16(t, b); + } +}; + +template // type, widen type, vector type +static void +medianBlur_SortNet( const uchar* src_data, size_t src_step, + uchar* dst_data, size_t dst_step, + int width, int height, int cn, int ksize ) +{ + const T* src = (T*)src_data; + T* dst = (T*)dst_data; + int sstep = (int)(src_step / sizeof(T)); + int dstep = (int)(dst_step / sizeof(T)); + int i, j, k; + operators_minmax_t op; + + if( ksize == 3 ) + { + if( width == 1 || height == 1 ) + { + int len = width + height - 1; + int sdelta = height == 1 ? cn : sstep; + int sdelta0 = height == 1 ? 0 : sstep - cn; + int ddelta = height == 1 ? cn : dstep; + + for( i = 0; i < len; i++, src += sdelta0, dst += ddelta ) + for( j = 0; j < cn; j++, src++ ) + { + T p0 = src[i > 0 ? -sdelta : 0]; + T p1 = src[0]; + T p2 = src[i < len - 1 ? sdelta : 0]; + + op.scalar(p0, p1); op.scalar(p1, p2); op.scalar(p0, p1); + dst[j] = (T)p1; + } + return; + } + + width *= cn; + for( i = 0; i < height; i++, dst += dstep ) + { + const T* row0 = src + std::max(i - 1, 0)*sstep; + const T* row1 = src + i*sstep; + const T* row2 = src + std::min(i + 1, height-1)*sstep; + int limit = cn; + + for(j = 0;; ) + { + for( ; j < limit; j++ ) + { + int j0 = j >= cn ? j - cn : j; + int j2 = j < width - cn ? j + cn : j; + T p0 = row0[j0], p1 = row0[j], p2 = row0[j2]; + T p3 = row1[j0], p4 = row1[j], p5 = row1[j2]; + T p6 = row2[j0], p7 = row2[j], p8 = row2[j2]; + + op.scalar(p1, p2); op.scalar(p4, p5); op.scalar(p7, p8); op.scalar(p0, p1); + op.scalar(p3, p4); op.scalar(p6, p7); op.scalar(p1, p2); op.scalar(p4, p5); + op.scalar(p7, p8); op.scalar(p0, p3); op.scalar(p5, p8); op.scalar(p4, p7); + op.scalar(p3, p6); op.scalar(p1, p4); op.scalar(p2, p5); op.scalar(p4, p7); + op.scalar(p4, p2); op.scalar(p6, p4); op.scalar(p4, p2); + dst[j] = (T)p4; + } + + if( limit == width ) + break; + + int nlanes = 8 / sizeof(T); + + for( ; (cn % nlanes == 0) && (j <= width - nlanes - cn); j += nlanes ) // alignment + { + VT p0 = *(VT*)(row0+j-cn), p1 = *(VT*)(row0+j), p2 = *(VT*)(row0+j+cn); + VT p3 = *(VT*)(row1+j-cn), p4 = *(VT*)(row1+j), p5 = *(VT*)(row1+j+cn); + VT p6 = *(VT*)(row2+j-cn), p7 = *(VT*)(row2+j), p8 = *(VT*)(row2+j+cn); + + op.vector(p1, p2); op.vector(p4, p5); op.vector(p7, p8); op.vector(p0, p1); + op.vector(p3, p4); op.vector(p6, p7); op.vector(p1, p2); op.vector(p4, p5); + op.vector(p7, p8); op.vector(p0, p3); op.vector(p5, p8); op.vector(p4, p7); + op.vector(p3, p6); op.vector(p1, p4); op.vector(p2, p5); op.vector(p4, p7); + op.vector(p4, p2); op.vector(p6, p4); op.vector(p4, p2); + *(VT*)(dst+j) = p4; + } + + limit = width; + } + } + } + else if( ksize == 5 ) + { + if( width == 1 || height == 1 ) + { + int len = width + height - 1; + int sdelta = height == 1 ? cn : sstep; + int sdelta0 = height == 1 ? 0 : sstep - cn; + int ddelta = height == 1 ? cn : dstep; + + for( i = 0; i < len; i++, src += sdelta0, dst += ddelta ) + for( j = 0; j < cn; j++, src++ ) + { + int i1 = i > 0 ? -sdelta : 0; + int i0 = i > 1 ? -sdelta*2 : i1; + int i3 = i < len-1 ? sdelta : 0; + int i4 = i < len-2 ? sdelta*2 : i3; + T p0 = src[i0], p1 = src[i1], p2 = src[0], p3 = src[i3], p4 = src[i4]; + + op.scalar(p0, p1); op.scalar(p3, p4); op.scalar(p2, p3); op.scalar(p3, p4); op.scalar(p0, p2); + op.scalar(p2, p4); op.scalar(p1, p3); op.scalar(p1, p2); + dst[j] = (T)p2; + } + return; + } + + width *= cn; + for( i = 0; i < height; i++, dst += dstep ) + { + const T* row[5]; + row[0] = src + std::max(i - 2, 0)*sstep; + row[1] = src + std::max(i - 1, 0)*sstep; + row[2] = src + i*sstep; + row[3] = src + std::min(i + 1, height-1)*sstep; + row[4] = src + std::min(i + 2, height-1)*sstep; + int limit = cn*2; + + for(j = 0;; ) + { + for( ; j < limit; j++ ) + { + T p[25]; + int j1 = j >= cn ? j - cn : j; + int j0 = j >= cn*2 ? j - cn*2 : j1; + int j3 = j < width - cn ? j + cn : j; + int j4 = j < width - cn*2 ? j + cn*2 : j3; + for( k = 0; k < 5; k++ ) + { + const T* rowk = row[k]; + p[k*5] = rowk[j0]; p[k*5+1] = rowk[j1]; + p[k*5+2] = rowk[j]; p[k*5+3] = rowk[j3]; + p[k*5+4] = rowk[j4]; + } + + op.scalar(p[1], p[2]); op.scalar(p[0], p[1]); op.scalar(p[1], p[2]); op.scalar(p[4], p[5]); op.scalar(p[3], p[4]); + op.scalar(p[4], p[5]); op.scalar(p[0], p[3]); op.scalar(p[2], p[5]); op.scalar(p[2], p[3]); op.scalar(p[1], p[4]); + op.scalar(p[1], p[2]); op.scalar(p[3], p[4]); op.scalar(p[7], p[8]); op.scalar(p[6], p[7]); op.scalar(p[7], p[8]); + op.scalar(p[10], p[11]); op.scalar(p[9], p[10]); op.scalar(p[10], p[11]); op.scalar(p[6], p[9]); op.scalar(p[8], p[11]); + op.scalar(p[8], p[9]); op.scalar(p[7], p[10]); op.scalar(p[7], p[8]); op.scalar(p[9], p[10]); op.scalar(p[0], p[6]); + op.scalar(p[4], p[10]); op.scalar(p[4], p[6]); op.scalar(p[2], p[8]); op.scalar(p[2], p[4]); op.scalar(p[6], p[8]); + op.scalar(p[1], p[7]); op.scalar(p[5], p[11]); op.scalar(p[5], p[7]); op.scalar(p[3], p[9]); op.scalar(p[3], p[5]); + op.scalar(p[7], p[9]); op.scalar(p[1], p[2]); op.scalar(p[3], p[4]); op.scalar(p[5], p[6]); op.scalar(p[7], p[8]); + op.scalar(p[9], p[10]); op.scalar(p[13], p[14]); op.scalar(p[12], p[13]); op.scalar(p[13], p[14]); op.scalar(p[16], p[17]); + op.scalar(p[15], p[16]); op.scalar(p[16], p[17]); op.scalar(p[12], p[15]); op.scalar(p[14], p[17]); op.scalar(p[14], p[15]); + op.scalar(p[13], p[16]); op.scalar(p[13], p[14]); op.scalar(p[15], p[16]); op.scalar(p[19], p[20]); op.scalar(p[18], p[19]); + op.scalar(p[19], p[20]); op.scalar(p[21], p[22]); op.scalar(p[23], p[24]); op.scalar(p[21], p[23]); op.scalar(p[22], p[24]); + op.scalar(p[22], p[23]); op.scalar(p[18], p[21]); op.scalar(p[20], p[23]); op.scalar(p[20], p[21]); op.scalar(p[19], p[22]); + op.scalar(p[22], p[24]); op.scalar(p[19], p[20]); op.scalar(p[21], p[22]); op.scalar(p[23], p[24]); op.scalar(p[12], p[18]); + op.scalar(p[16], p[22]); op.scalar(p[16], p[18]); op.scalar(p[14], p[20]); op.scalar(p[20], p[24]); op.scalar(p[14], p[16]); + op.scalar(p[18], p[20]); op.scalar(p[22], p[24]); op.scalar(p[13], p[19]); op.scalar(p[17], p[23]); op.scalar(p[17], p[19]); + op.scalar(p[15], p[21]); op.scalar(p[15], p[17]); op.scalar(p[19], p[21]); op.scalar(p[13], p[14]); op.scalar(p[15], p[16]); + op.scalar(p[17], p[18]); op.scalar(p[19], p[20]); op.scalar(p[21], p[22]); op.scalar(p[23], p[24]); op.scalar(p[0], p[12]); + op.scalar(p[8], p[20]); op.scalar(p[8], p[12]); op.scalar(p[4], p[16]); op.scalar(p[16], p[24]); op.scalar(p[12], p[16]); + op.scalar(p[2], p[14]); op.scalar(p[10], p[22]); op.scalar(p[10], p[14]); op.scalar(p[6], p[18]); op.scalar(p[6], p[10]); + op.scalar(p[10], p[12]); op.scalar(p[1], p[13]); op.scalar(p[9], p[21]); op.scalar(p[9], p[13]); op.scalar(p[5], p[17]); + op.scalar(p[13], p[17]); op.scalar(p[3], p[15]); op.scalar(p[11], p[23]); op.scalar(p[11], p[15]); op.scalar(p[7], p[19]); + op.scalar(p[7], p[11]); op.scalar(p[11], p[13]); op.scalar(p[11], p[12]); + dst[j] = (T)p[12]; + } + + if( limit == width ) + break; + + int nlanes = 8 / sizeof(T); + + for( ; (cn % nlanes == 0) && (j <= width - nlanes - cn*2); j += nlanes ) + { + VT p0 = *(VT*)(row[0]+j-cn*2), p5 = *(VT*)(row[1]+j-cn*2), p10 = *(VT*)(row[2]+j-cn*2), p15 = *(VT*)(row[3]+j-cn*2), p20 = *(VT*)(row[4]+j-cn*2); + VT p1 = *(VT*)(row[0]+j-cn*1), p6 = *(VT*)(row[1]+j-cn*1), p11 = *(VT*)(row[2]+j-cn*1), p16 = *(VT*)(row[3]+j-cn*1), p21 = *(VT*)(row[4]+j-cn*1); + VT p2 = *(VT*)(row[0]+j-cn*0), p7 = *(VT*)(row[1]+j-cn*0), p12 = *(VT*)(row[2]+j-cn*0), p17 = *(VT*)(row[3]+j-cn*0), p22 = *(VT*)(row[4]+j-cn*0); + VT p3 = *(VT*)(row[0]+j+cn*1), p8 = *(VT*)(row[1]+j+cn*1), p13 = *(VT*)(row[2]+j+cn*1), p18 = *(VT*)(row[3]+j+cn*1), p23 = *(VT*)(row[4]+j+cn*1); + VT p4 = *(VT*)(row[0]+j+cn*2), p9 = *(VT*)(row[1]+j+cn*2), p14 = *(VT*)(row[2]+j+cn*2), p19 = *(VT*)(row[3]+j+cn*2), p24 = *(VT*)(row[4]+j+cn*2); + + op.vector(p1, p2); op.vector(p0, p1); op.vector(p1, p2); op.vector(p4, p5); op.vector(p3, p4); + op.vector(p4, p5); op.vector(p0, p3); op.vector(p2, p5); op.vector(p2, p3); op.vector(p1, p4); + op.vector(p1, p2); op.vector(p3, p4); op.vector(p7, p8); op.vector(p6, p7); op.vector(p7, p8); + op.vector(p10, p11); op.vector(p9, p10); op.vector(p10, p11); op.vector(p6, p9); op.vector(p8, p11); + op.vector(p8, p9); op.vector(p7, p10); op.vector(p7, p8); op.vector(p9, p10); op.vector(p0, p6); + op.vector(p4, p10); op.vector(p4, p6); op.vector(p2, p8); op.vector(p2, p4); op.vector(p6, p8); + op.vector(p1, p7); op.vector(p5, p11); op.vector(p5, p7); op.vector(p3, p9); op.vector(p3, p5); + op.vector(p7, p9); op.vector(p1, p2); op.vector(p3, p4); op.vector(p5, p6); op.vector(p7, p8); + op.vector(p9, p10); op.vector(p13, p14); op.vector(p12, p13); op.vector(p13, p14); op.vector(p16, p17); + op.vector(p15, p16); op.vector(p16, p17); op.vector(p12, p15); op.vector(p14, p17); op.vector(p14, p15); + op.vector(p13, p16); op.vector(p13, p14); op.vector(p15, p16); op.vector(p19, p20); op.vector(p18, p19); + op.vector(p19, p20); op.vector(p21, p22); op.vector(p23, p24); op.vector(p21, p23); op.vector(p22, p24); + op.vector(p22, p23); op.vector(p18, p21); op.vector(p20, p23); op.vector(p20, p21); op.vector(p19, p22); + op.vector(p22, p24); op.vector(p19, p20); op.vector(p21, p22); op.vector(p23, p24); op.vector(p12, p18); + op.vector(p16, p22); op.vector(p16, p18); op.vector(p14, p20); op.vector(p20, p24); op.vector(p14, p16); + op.vector(p18, p20); op.vector(p22, p24); op.vector(p13, p19); op.vector(p17, p23); op.vector(p17, p19); + op.vector(p15, p21); op.vector(p15, p17); op.vector(p19, p21); op.vector(p13, p14); op.vector(p15, p16); + op.vector(p17, p18); op.vector(p19, p20); op.vector(p21, p22); op.vector(p23, p24); op.vector(p0, p12); + op.vector(p8, p20); op.vector(p8, p12); op.vector(p4, p16); op.vector(p16, p24); op.vector(p12, p16); + op.vector(p2, p14); op.vector(p10, p22); op.vector(p10, p14); op.vector(p6, p18); op.vector(p6, p10); + op.vector(p10, p12); op.vector(p1, p13); op.vector(p9, p21); op.vector(p9, p13); op.vector(p5, p17); + op.vector(p13, p17); op.vector(p3, p15); op.vector(p11, p23); op.vector(p11, p15); op.vector(p7, p19); + op.vector(p7, p11); op.vector(p11, p13); op.vector(p11, p12); + *(VT*)(dst+j) = p12; + } + + limit = width; + } + } + } +} + +int medianBlur(const uchar* src_data, size_t src_step, + uchar* dst_data, size_t dst_step, + int width, int height, int depth, int cn, int ksize) +{ + bool useSortNet = ((ksize == 3) || (ksize == 5 && ( depth > CV_8U || cn == 2 || cn > 4 ))); + + if( useSortNet ) + { + uchar* src_data_rep; + if( dst_data == src_data ) { + std::vector src_data_copy(src_step * height); + memcpy(src_data_copy.data(), src_data, src_step * height); + src_data_rep = &src_data_copy[0]; + } + else { + src_data_rep = (uchar*)src_data; + } + + if( depth == CV_8U ) + medianBlur_SortNet( src_data_rep, src_step, dst_data, dst_step, width, height, cn, ksize ); + else if( depth == CV_8S ) + medianBlur_SortNet( src_data_rep, src_step, dst_data, dst_step, width, height, cn, ksize ); + else if( depth == CV_16U ) + medianBlur_SortNet( src_data_rep, src_step, dst_data, dst_step, width, height, cn, ksize ); + else if( depth == CV_16S ) + medianBlur_SortNet( src_data_rep, src_step, dst_data, dst_step, width, height, cn, ksize ); + else + return CV_HAL_ERROR_NOT_IMPLEMENTED; + + return CV_HAL_ERROR_OK; + } + else return CV_HAL_ERROR_NOT_IMPLEMENTED; +} + +} // namespace ndsrvp + +} // namespace cv diff --git a/CMakeLists.txt b/CMakeLists.txt index 14aa0d99c4..d6d37bf6c2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -471,6 +471,7 @@ OCV_OPTION(ENABLE_CONFIG_VERIFICATION "Fail build if actual configuration doesn' OCV_OPTION(OPENCV_ENABLE_MEMALIGN "Enable posix_memalign or memalign usage" ON) OCV_OPTION(OPENCV_DISABLE_FILESYSTEM_SUPPORT "Disable filesystem support" OFF) OCV_OPTION(OPENCV_DISABLE_THREAD_SUPPORT "Build the library without multi-threaded code." OFF) +OCV_OPTION(OPENCV_DISABLE_ENV_SUPPORT "Disable environment variables access (getenv)" (CMAKE_SYSTEM_NAME MATCHES "Windows(CE|Phone|Store)")) OCV_OPTION(OPENCV_SEMIHOSTING "Build the library for semihosting target (Arm). See https://developer.arm.com/documentation/100863/latest." OFF) OCV_OPTION(ENABLE_CUDA_FIRST_CLASS_LANGUAGE "Enable CUDA as a first class language, if enabled dependant projects will need to use CMake >= 3.18" OFF VISIBLE_IF (WITH_CUDA AND NOT CMAKE_VERSION VERSION_LESS 3.18) diff --git a/cmake/OpenCVDetectDirectML.cmake b/cmake/OpenCVDetectDirectML.cmake index 0fc71eca03..0394678a0c 100644 --- a/cmake/OpenCVDetectDirectML.cmake +++ b/cmake/OpenCVDetectDirectML.cmake @@ -6,7 +6,7 @@ if(WIN32) OUTPUT_VARIABLE TRY_OUT ) if(NOT __VALID_DIRECTML) - message(STATUS "No support for DirectML (d3d12, dxcore, directml libs are required)") + message(STATUS "No support for DirectML. d3d12, dxcore, directml libs are required, first bundled with Windows SDK 10.0.19041.0.") return() endif() set(HAVE_DIRECTML ON) diff --git a/cmake/platforms/OpenCV-WinRT.cmake b/cmake/platforms/OpenCV-WinRT.cmake index 0a5e9f3c7d..350c280fd2 100644 --- a/cmake/platforms/OpenCV-WinRT.cmake +++ b/cmake/platforms/OpenCV-WinRT.cmake @@ -1,6 +1,6 @@ set(WINRT TRUE) -add_definitions(-DWINRT -DNO_GETENV) +add_definitions(-DWINRT) # Making definitions available to other configurations and # to filter dependency restrictions at compile time. diff --git a/cmake/platforms/OpenCV-WindowsCE.cmake b/cmake/platforms/OpenCV-WindowsCE.cmake index f5ac590754..1bb8bf6d7f 100644 --- a/cmake/platforms/OpenCV-WindowsCE.cmake +++ b/cmake/platforms/OpenCV-WindowsCE.cmake @@ -1 +1 @@ -add_definitions(-DNO_GETENV) +# empty diff --git a/doc/tutorials/introduction/env_reference/env_reference.markdown b/doc/tutorials/introduction/env_reference/env_reference.markdown index d9145db4d1..ee725f8542 100644 --- a/doc/tutorials/introduction/env_reference/env_reference.markdown +++ b/doc/tutorials/introduction/env_reference/env_reference.markdown @@ -59,7 +59,6 @@ import cv2 # variables set after this may not have effect ## Types -- _non-null_ - set to anything to enable feature, in some cases can be interpreted as other types (e.g. path) - _bool_ - `1`, `True`, `true`, `TRUE` / `0`, `False`, `false`, `FALSE` - _number_/_size_ - unsigned number, suffixes `MB`, `Mb`, `mb`, `KB`, `Kb`, `kb` - _string_ - plain string or can have a structure @@ -70,7 +69,7 @@ import cv2 # variables set after this may not have effect ## General, core | name | type | default | description | |------|------|---------|-------------| -| OPENCV_SKIP_CPU_BASELINE_CHECK | non-null | | do not check that current CPU supports all features used by the build (baseline) | +| OPENCV_SKIP_CPU_BASELINE_CHECK | bool | false | do not check that current CPU supports all features used by the build (baseline) | | OPENCV_CPU_DISABLE | `,` or `;`-separated | | disable code branches which use CPU features (dispatched code) | | OPENCV_SETUP_TERMINATE_HANDLER | bool | true (Windows) | use std::set_terminate to install own termination handler | | OPENCV_LIBVA_RUNTIME | file path | | libva for VA interoperability utils | @@ -78,9 +77,9 @@ import cv2 # variables set after this may not have effect | OPENCV_BUFFER_AREA_ALWAYS_SAFE | bool | false | enable safe mode for multi-buffer allocations (each buffer separately) | | OPENCV_KMEANS_PARALLEL_GRANULARITY | num | 1000 | tune algorithm parallel work distribution parameter `parallel_for_(..., ..., ..., granularity)` | | OPENCV_DUMP_ERRORS | bool | true (Debug or Android), false (others) | print extra information on exception (log to Android) | -| OPENCV_DUMP_CONFIG | non-null | | print build configuration to stderr (`getBuildInformation`) | +| OPENCV_DUMP_CONFIG | bool | false | print build configuration to stderr (`getBuildInformation`) | | OPENCV_PYTHON_DEBUG | bool | false | enable extra warnings in Python bindings | -| OPENCV_TEMP_PATH | non-null / path | `/tmp/` (Linux), `/data/local/tmp/` (Android), `GetTempPathA` (Windows) | directory for temporary files | +| OPENCV_TEMP_PATH | path | `/tmp/` (Linux), `/data/local/tmp/` (Android), `GetTempPathA` (Windows) | directory for temporary files | | OPENCV_DATA_PATH_HINT | paths | | paths for findDataFile | | OPENCV_DATA_PATH | paths | | paths for findDataFile | | OPENCV_SAMPLES_DATA_PATH_HINT | paths | | paths for findDataFile | @@ -271,7 +270,7 @@ Some external dependencies can be detached into a dynamic library, which will be | ⭐ OPENCV_FFMPEG_CAPTURE_OPTIONS | string (see note) | | extra options for VideoCapture FFmpeg backend | | ⭐ OPENCV_FFMPEG_WRITER_OPTIONS | string (see note) | | extra options for VideoWriter FFmpeg backend | | OPENCV_FFMPEG_THREADS | num | | set FFmpeg thread count | -| OPENCV_FFMPEG_DEBUG | non-null | | enable logging messages from FFmpeg | +| OPENCV_FFMPEG_DEBUG | bool | false | enable logging messages from FFmpeg | | OPENCV_FFMPEG_LOGLEVEL | num | | set FFmpeg logging level | | OPENCV_FFMPEG_DLL_DIR | dir path | | directory with FFmpeg plugin (legacy) | | OPENCV_FFMPEG_IS_THREAD_SAFE | bool | false | enabling this option will turn off thread safety locks in the FFmpeg backend (use only if you are sure FFmpeg is built with threading support, tested on Linux) | @@ -285,7 +284,7 @@ Some external dependencies can be detached into a dynamic library, which will be | OPENCV_VIDEOIO_MFX_BITRATE_DIVISOR | num | 300 | this option allows to tune encoding bitrate (video quality/size) | | OPENCV_VIDEOIO_MFX_WRITER_TIMEOUT | num | 1 | timeout for encoding operation (in seconds) | | OPENCV_VIDEOIO_MSMF_ENABLE_HW_TRANSFORMS | bool | true | allow HW-accelerated transformations (DXVA) in MediaFoundation processing graph (may slow down camera probing process) | -| OPENCV_DSHOW_DEBUG | non-null | | enable verbose logging in the DShow backend | +| OPENCV_DSHOW_DEBUG | bool | false | enable verbose logging in the DShow backend | | OPENCV_DSHOW_SAVEGRAPH_FILENAME | file path | | enable processing graph tump in the DShow backend | | OPENCV_VIDEOIO_V4L_RANGE_NORMALIZED | bool | false | use (0, 1) range for properties (V4L) | | OPENCV_VIDEOIO_V4L_SELECT_TIMEOUT | num | 10 | timeout for select call (in seconds) (V4L) | @@ -296,7 +295,7 @@ Some external dependencies can be detached into a dynamic library, which will be ### videoio tests | name | type | default | description | |------|------|---------|-------------| -| OPENCV_TEST_VIDEOIO_BACKEND_REQUIRE_FFMPEG | | | test app will exit if no FFmpeg backend is available | +| OPENCV_TEST_VIDEOIO_BACKEND_REQUIRE_FFMPEG | bool | false | test app will exit if no FFmpeg backend is available | | OPENCV_TEST_V4L2_VIVID_DEVICE | file path | | path to VIVID virtual camera device for V4L2 test (e.g. `/dev/video5`) | | OPENCV_TEST_PERF_CAMERA_LIST | paths | | cameras to use in performance test (waitAny_V4L test) | | OPENCV_TEST_CAMERA_%d_FPS | num | | fps to set for N-th camera (0-based index) (waitAny_V4L test) | diff --git a/modules/core/CMakeLists.txt b/modules/core/CMakeLists.txt index b4003fab7f..0dab95798c 100644 --- a/modules/core/CMakeLists.txt +++ b/modules/core/CMakeLists.txt @@ -184,6 +184,10 @@ if(OPENCV_DISABLE_THREAD_SUPPORT) ocv_target_compile_definitions(${the_module} PUBLIC "OPENCV_DISABLE_THREAD_SUPPORT=1") endif() +if(OPENCV_DISABLE_ENV_SUPPORT) + ocv_append_source_file_compile_definitions(${CMAKE_CURRENT_SOURCE_DIR}/src/system.cpp "NO_GETENV") +endif() + if(OPENCV_SEMIHOSTING) ocv_target_compile_definitions(${the_module} PRIVATE "-DOPENCV_SEMIHOSTING") endif(OPENCV_SEMIHOSTING) diff --git a/modules/core/include/opencv2/core/utils/configuration.private.hpp b/modules/core/include/opencv2/core/utils/configuration.private.hpp index b35f35e9d4..756b477165 100644 --- a/modules/core/include/opencv2/core/utils/configuration.private.hpp +++ b/modules/core/include/opencv2/core/utils/configuration.private.hpp @@ -12,9 +12,9 @@ namespace cv { namespace utils { typedef std::vector Paths; -CV_EXPORTS bool getConfigurationParameterBool(const char* name, bool defaultValue); -CV_EXPORTS size_t getConfigurationParameterSizeT(const char* name, size_t defaultValue); -CV_EXPORTS cv::String getConfigurationParameterString(const char* name, const char* defaultValue); +CV_EXPORTS bool getConfigurationParameterBool(const char* name, bool defaultValue = false); +CV_EXPORTS size_t getConfigurationParameterSizeT(const char* name, size_t defaultValue = 0); +CV_EXPORTS std::string getConfigurationParameterString(const char* name, const std::string & defaultValue = std::string()); CV_EXPORTS Paths getConfigurationParameterPaths(const char* name, const Paths &defaultValue = Paths()); }} // namespace diff --git a/modules/core/src/arithm.cpp b/modules/core/src/arithm.cpp index 7ba4f87f4f..30f57c17fc 100644 --- a/modules/core/src/arithm.cpp +++ b/modules/core/src/arithm.cpp @@ -611,6 +611,10 @@ static bool ocl_arithm_op(InputArray _src1, InputArray _src2, OutputArray _dst, #endif +typedef int (*ScalarFunc)(const uchar* src, size_t step_src, + uchar* dst, size_t step_dst, int width, int height, + void* scalar, bool scalarIsFirst); + typedef int (*ExtendedTypeFunc)(const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, int width, int height, @@ -618,7 +622,8 @@ typedef int (*ExtendedTypeFunc)(const uchar* src1, size_t step1, static void arithm_op(InputArray _src1, InputArray _src2, OutputArray _dst, InputArray _mask, int dtype, BinaryFuncC* tab, bool muldiv=false, - void* usrdata=0, int oclop=-1, ExtendedTypeFunc extendedFunc = nullptr ) + void* usrdata=0, int oclop=-1, ExtendedTypeFunc extendedFunc = nullptr, + ScalarFunc scalarFunc = nullptr) { const _InputArray *psrc1 = &_src1, *psrc2 = &_src2; _InputArray::KindFlag kind1 = psrc1->kind(), kind2 = psrc2->kind(); @@ -664,8 +669,7 @@ static void arithm_op(InputArray _src1, InputArray _src2, OutputArray _dst, (kind1 == _InputArray::MATX && (sz1 == Size(1,4) || sz1 == Size(1,1))) || (kind2 == _InputArray::MATX && (sz2 == Size(1,4) || sz2 == Size(1,1))) ) { - if ((type1 == CV_64F && (sz1.height == 1 || sz1.height == 4)) && - checkScalar(*psrc1, type2, kind1, kind2)) + if ((type1 == CV_64F && (sz1.height == 1 || sz1.height == 4)) && src1Scalar) { // src1 is a scalar; swap it with src2 swap(psrc1, psrc2); @@ -680,7 +684,7 @@ static void arithm_op(InputArray _src1, InputArray _src2, OutputArray _dst, if ( oclop == OCL_OP_DIV_SCALE ) oclop = OCL_OP_RDIV_SCALE; } - else if( !checkScalar(*psrc2, type1, kind2, kind1) ) + else if( !src2Scalar ) CV_Error( cv::Error::StsUnmatchedSizes, "The operation is neither 'array op array' " "(where arrays have the same size and the same number of channels), " @@ -891,32 +895,38 @@ static void arithm_op(InputArray _src1, InputArray _src2, OutputArray _dst, const uchar* extSptr1 = sptr1; const uchar* extSptr2 = sptr2; if( swapped12 ) - std::swap(extSptr1, extSptr1); + std::swap(extSptr1, extSptr2); - // try to perform operation with conversion in one call - // if fail, use converter functions + // try to perform operation in 1 call, fallback to classic way if fail uchar* opconverted = haveMask ? maskbuf : dptr; - if (!extendedFunc || extendedFunc(extSptr1, 1, extSptr2, 1, opconverted, 1, - bszn.width, bszn.height, usrdata) != 0) + if (!scalarFunc || src2.total() != 1 || + scalarFunc(extSptr1, 1, opconverted, 1, bszn.width, bszn.height, (void*)extSptr2, swapped12) != 0) { - if( cvtsrc1 ) + // try to perform operation with conversion in one call + // if fail, use converter functions + + if (!extendedFunc || extendedFunc(extSptr1, 1, extSptr2, 1, opconverted, 1, + bszn.width, bszn.height, usrdata) != 0) { - cvtsrc1( sptr1, 1, 0, 1, buf1, 1, bszn, 0 ); - sptr1 = buf1; + if( cvtsrc1 ) + { + cvtsrc1( sptr1, 1, 0, 1, buf1, 1, bszn, 0 ); + sptr1 = buf1; + } + + if( swapped12 ) + std::swap(sptr1, sptr2); + + uchar* fdst = ( haveMask || cvtdst ) ? wbuf : dptr; + func( sptr1, 1, sptr2, 1, fdst, 1, bszn.width, bszn.height, usrdata ); + + if (cvtdst) + { + uchar* cdst = haveMask ? maskbuf : dptr; + cvtdst(wbuf, 1, 0, 1, cdst, 1, bszn, 0); + } + opconverted = cvtdst ? maskbuf : wbuf; } - - if( swapped12 ) - std::swap(sptr1, sptr2); - - uchar* fdst = ( haveMask || cvtdst ) ? wbuf : dptr; - func( sptr1, 1, sptr2, 1, fdst, 1, bszn.width, bszn.height, usrdata ); - - if (cvtdst) - { - uchar* cdst = haveMask ? maskbuf : dptr; - cvtdst(wbuf, 1, 0, 1, cdst, 1, bszn, 0); - } - opconverted = cvtdst ? maskbuf : wbuf; } if (haveMask) @@ -954,6 +964,48 @@ static BinaryFuncC* getAddTab() return addTab; } +static int addScalar32f32fWrapper(const uchar* src, size_t step_src, uchar* dst, size_t step_dst, int width, int height, + void* scalar, bool /*scalarIsFirst*/) +{ + int res = cv_hal_addScalar32f32f((const float*)src, step_src, (float *)dst, step_dst, width, height, (const float*)scalar); + if (res == CV_HAL_ERROR_OK || res == CV_HAL_ERROR_NOT_IMPLEMENTED) + return res; + else + { + CV_Error_(cv::Error::StsInternal, ("HAL implementation addScalar32f32f ==> " CVAUX_STR(cv_hal_addScalar32f32f) + " returned %d (0x%08x)", res, res)); + } +} + +static int addScalar16s16sWrapper(const uchar* src, size_t step_src, uchar* dst, size_t step_dst, int width, int height, + void* scalar, bool /*scalarIsFirst*/) +{ + int res = cv_hal_addScalar16s16s((const int16_t*)src, step_src, (int16_t *)dst, step_dst, width, height, (const int16_t*)scalar); + if (res == CV_HAL_ERROR_OK || res == CV_HAL_ERROR_NOT_IMPLEMENTED) + return res; + else + { + CV_Error_(cv::Error::StsInternal, ("HAL implementation addScalar16s16s ==> " CVAUX_STR(cv_hal_addScalar16s16s) + " returned %d (0x%08x)", res, res)); + } +} + +static ScalarFunc getAddScalarFunc(int srcType, int dstType) +{ + if (srcType == CV_32F && dstType == CV_32F) + { + return addScalar32f32fWrapper; + } + else if (srcType == CV_16S && dstType == CV_16S) + { + return addScalar16s16sWrapper; + } + else + { + return nullptr; + } +} + static int sub8u32fWrapper(const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* ) { @@ -1056,7 +1108,9 @@ void cv::add( InputArray src1, InputArray src2, OutputArray dst, return; } - arithm_op(src1, src2, dst, mask, dtype, getAddTab(), false, 0, OCL_OP_ADD ); + ScalarFunc scalarFunc = getAddScalarFunc(src1.depth(), dtype < 0 ? dst.depth() : dtype); + arithm_op(src1, src2, dst, mask, dtype, getAddTab(), false, 0, OCL_OP_ADD, nullptr, + /* scalarFunc */ scalarFunc ); } void cv::subtract( InputArray _src1, InputArray _src2, OutputArray _dst, diff --git a/modules/core/src/hal_replacement.hpp b/modules/core/src/hal_replacement.hpp index 79bad5cbc7..944ec60d22 100644 --- a/modules/core/src/hal_replacement.hpp +++ b/modules/core/src/hal_replacement.hpp @@ -109,7 +109,19 @@ inline int hal_ni_sub16bf(const cv_hal_bf16 *src1_data, size_t src1_step, const inline int hal_ni_sub8u32f(const uchar *src1_data, size_t src1_step, const uchar *src2_data, size_t src2_step, float *dst_data, size_t dst_step, int width, int height) { return CV_HAL_ERROR_NOT_IMPLEMENTED; } inline int hal_ni_sub8s32f(const schar *src1_data, size_t src1_step, const schar *src2_data, size_t src2_step, float *dst_data, size_t dst_step, int width, int height) { return CV_HAL_ERROR_NOT_IMPLEMENTED; } +/** +Add scalar: _dst[i] = src[i] + scalar +@param src_data source image data +@param src_step source image step +@param dst_data destination image data +@param dst_step destination image step +@param width width of the images +@param height height of the images +@param scalar_data pointer to scalar value +*/ +inline int hal_ni_addScalar32f32f(const float *src_data, size_t src_step, float *dst_data, size_t dst_step, int width, int height, const float* scalar_data) { return CV_HAL_ERROR_NOT_IMPLEMENTED; } +inline int hal_ni_addScalar16s16s(const int16_t *src_data, size_t src_step, int16_t *dst_data, size_t dst_step, int width, int height, const int16_t* scalar_data) { return CV_HAL_ERROR_NOT_IMPLEMENTED; } //! @} /** @@ -229,6 +241,8 @@ inline int hal_ni_not8u(const uchar *src_data, size_t src_step, uchar *dst_data, #define cv_hal_sub8s32f hal_ni_sub8s32f #define cv_hal_sub16f hal_ni_sub16f #define cv_hal_sub16bf hal_ni_sub16bf +#define cv_hal_addScalar32f32f hal_ni_addScalar32f32f +#define cv_hal_addScalar16s16s hal_ni_addScalar16s16s #define cv_hal_max8u hal_ni_max8u #define cv_hal_max8s hal_ni_max8s #define cv_hal_max16u hal_ni_max16u diff --git a/modules/core/src/ocl.cpp b/modules/core/src/ocl.cpp index 58155e6d0c..bc6f9aefad 100644 --- a/modules/core/src/ocl.cpp +++ b/modules/core/src/ocl.cpp @@ -1170,10 +1170,10 @@ bool haveOpenCL() if (!g_isOpenCLInitialized) { CV_TRACE_REGION("Init_OpenCL_Runtime"); - const char* envPath = getenv("OPENCV_OPENCL_RUNTIME"); - if (envPath) + std::string envPath = utils::getConfigurationParameterString("OPENCV_OPENCL_RUNTIME"); + if (!envPath.empty()) { - if (cv::String(envPath) == "disabled") + if (envPath == "disabled") { g_isOpenCLAvailable = false; g_isOpenCLInitialized = true; @@ -2119,24 +2119,18 @@ static bool parseOpenCLDeviceConfiguration(const std::string& configurationStr, return true; } -#if defined WINRT || defined _WIN32_WCE -static cl_device_id selectOpenCLDevice(const char* configuration = NULL) -{ - CV_UNUSED(configuration) - return NULL; -} -#else -static cl_device_id selectOpenCLDevice(const char* configuration = NULL) +static cl_device_id selectOpenCLDevice(const std::string & configuration_ = std::string()) { std::string platform, deviceName; std::vector deviceTypes; - if (!configuration) - configuration = getenv("OPENCV_OPENCL_DEVICE"); + std::string configuration(configuration_); + if (configuration.empty()) + configuration = utils::getConfigurationParameterString("OPENCV_OPENCL_DEVICE"); - if (configuration && - (strcmp(configuration, "disabled") == 0 || - !parseOpenCLDeviceConfiguration(std::string(configuration), platform, deviceTypes, deviceName) + if (!configuration.empty() && + (configuration == "disabled" || + !parseOpenCLDeviceConfiguration(configuration, platform, deviceTypes, deviceName) )) return NULL; @@ -2204,7 +2198,7 @@ static cl_device_id selectOpenCLDevice(const char* configuration = NULL) if (!isID) { deviceTypes.push_back("GPU"); - if (configuration) + if (!configuration.empty()) deviceTypes.push_back("CPU"); } else @@ -2272,7 +2266,7 @@ static cl_device_id selectOpenCLDevice(const char* configuration = NULL) } not_found: - if (!configuration) + if (configuration.empty()) return NULL; // suppress messages on stderr std::ostringstream msg; @@ -2287,7 +2281,6 @@ not_found: CV_LOG_ERROR(NULL, msg.str()); return NULL; } -#endif #ifdef HAVE_OPENCL_SVM namespace svm { @@ -2340,12 +2333,12 @@ static unsigned int getSVMCapabilitiesMask() static unsigned int mask = 0; if (!initialized) { - const char* envValue = getenv("OPENCV_OPENCL_SVM_CAPABILITIES_MASK"); - if (envValue == NULL) + const std::string envValue = utils::getConfigurationParameterString("OPENCV_OPENCL_SVM_CAPABILITIES_MASK"); + if (envValue.empty()) { return ~0U; // all bits 1 } - mask = atoi(envValue); + mask = atoi(envValue.c_str()); initialized = true; } return mask; @@ -2482,8 +2475,8 @@ public: std::string configuration = configuration_; if (configuration_.empty()) { - const char* c = getenv("OPENCV_OPENCL_DEVICE"); - if (c) + const std::string c = utils::getConfigurationParameterString("OPENCV_OPENCL_DEVICE"); + if (!c.empty()) configuration = c; } Impl* impl = findContext(configuration); @@ -2494,7 +2487,7 @@ public: return impl; } - cl_device_id d = selectOpenCLDevice(configuration.empty() ? NULL : configuration.c_str()); + cl_device_id d = selectOpenCLDevice(configuration); if (d == NULL) return NULL; diff --git a/modules/core/src/opencl/runtime/opencl_core.cpp b/modules/core/src/opencl/runtime/opencl_core.cpp index f264d623c5..35d24eb1cd 100644 --- a/modules/core/src/opencl/runtime/opencl_core.cpp +++ b/modules/core/src/opencl/runtime/opencl_core.cpp @@ -44,6 +44,7 @@ #if defined(HAVE_OPENCL) #include "opencv2/core.hpp" // CV_Error +#include "opencv2/core/utils/configuration.private.hpp" #if defined(HAVE_OPENCL_STATIC) #if defined __APPLE__ @@ -64,18 +65,14 @@ CV_SUPPRESS_DEPRECATED_END #define ERROR_MSG_CANT_LOAD "Failed to load OpenCL runtime\n" #define ERROR_MSG_INVALID_VERSION "Failed to load OpenCL runtime (expected version 1.1+)\n" -static const char* getRuntimePath(const char* defaultPath) +static std::string getRuntimePath(const std::string & defaultPath) { - const char* envPath = getenv("OPENCV_OPENCL_RUNTIME"); - if (envPath) - { - static const char disabled_str[] = "disabled"; - if ((strlen(envPath) == sizeof(disabled_str) - 1) && - (memcmp(envPath, disabled_str, sizeof(disabled_str) - 1) == 0)) - return NULL; - return envPath; - } - return defaultPath; + const std::string res = cv::utils::getConfigurationParameterString( + "OPENCV_OPENCL_RUNTIME", defaultPath); + if (res == "disabled") + return std::string(); + else + return res; } #if defined(__APPLE__) @@ -91,9 +88,9 @@ static void* AppleCLGetProcAddress(const char* name) if (!initialized) { const char* defaultPath = "/System/Library/Frameworks/OpenCL.framework/Versions/Current/OpenCL"; - const char* path = getRuntimePath(defaultPath); - if (path) - handle = dlopen(path, RTLD_LAZY | RTLD_GLOBAL); + std::string path = getRuntimePath(defaultPath); + if (!path.empty()) + handle = dlopen(path.c_str(), RTLD_LAZY | RTLD_GLOBAL); if (handle == NULL) { if (path != NULL && path != defaultPath) @@ -129,13 +126,13 @@ static void* WinGetProcAddress(const char* name) handle = GetModuleHandleA("OpenCL.dll"); if (!handle) { - const char* defaultPath = "OpenCL.dll"; - const char* path = getRuntimePath(defaultPath); - if (path) - handle = LoadLibraryA(path); + const std::string defaultPath = "OpenCL.dll"; + const std::string path = getRuntimePath(defaultPath); + if (!path.empty()) + handle = LoadLibraryA(path.c_str()); if (!handle) { - if (path != NULL && path != defaultPath) + if (!path.empty() && path != defaultPath) fprintf(stderr, ERROR_MSG_CANT_LOAD); } else if (GetProcAddress(handle, OPENCL_FUNC_TO_CHECK_1_1) == NULL) @@ -205,9 +202,9 @@ static void* GetProcAddress(const char* name) bool foundOpenCL = false; for (unsigned int i = 0; i < (sizeof(defaultAndroidPaths)/sizeof(char*)); i++) { - const char* path = (i==0) ? getRuntimePath(defaultAndroidPaths[i]) : defaultAndroidPaths[i]; - if (path) { - handle = GetHandle(path); + const std::string path = (i==0) ? getRuntimePath(defaultAndroidPaths[i]) : defaultAndroidPaths[i]; + if (!path.empty()) { + handle = GetHandle(path.c_str()); if (handle) { foundOpenCL = true; break; @@ -236,10 +233,10 @@ static void* GetProcAddress(const char* name) if (!initialized) { const char* defaultPath = "libOpenCL.so"; - const char* path = getRuntimePath(defaultPath); - if (path) + const std::string path = getRuntimePath(defaultPath); + if (!path.empty()) { - handle = GetHandle(path); + handle = GetHandle(path.c_str()); if (!handle) { if (path == defaultPath) diff --git a/modules/core/src/parallel/registry_parallel.impl.hpp b/modules/core/src/parallel/registry_parallel.impl.hpp index 2208748bb1..471cd681e4 100644 --- a/modules/core/src/parallel/registry_parallel.impl.hpp +++ b/modules/core/src/parallel/registry_parallel.impl.hpp @@ -111,7 +111,7 @@ protected: bool readPrioritySettings() { bool hasChanges = false; - cv::String prioritized_backends = utils::getConfigurationParameterString("OPENCV_PARALLEL_PRIORITY_LIST", NULL); + cv::String prioritized_backends = utils::getConfigurationParameterString("OPENCV_PARALLEL_PRIORITY_LIST"); if (prioritized_backends.empty()) return hasChanges; CV_LOG_INFO(NULL, "core(parallel): Configured priority list (OPENCV_PARALLEL_PRIORITY_LIST): " << prioritized_backends); diff --git a/modules/core/src/system.cpp b/modules/core/src/system.cpp index e8f9dd983a..662469f471 100644 --- a/modules/core/src/system.cpp +++ b/modules/core/src/system.cpp @@ -501,13 +501,11 @@ struct HWFeatures void initialize(void) { -#ifndef NO_GETENV - if (getenv("OPENCV_DUMP_CONFIG")) + if (utils::getConfigurationParameterBool("OPENCV_DUMP_CONFIG")) { fprintf(stderr, "\nOpenCV build configuration is:\n%s\n", cv::getBuildInformation().c_str()); } -#endif initializeNames(); @@ -788,12 +786,10 @@ struct HWFeatures #endif bool skip_baseline_check = false; -#ifndef NO_GETENV - if (getenv("OPENCV_SKIP_CPU_BASELINE_CHECK")) + if (utils::getConfigurationParameterBool("OPENCV_SKIP_CPU_BASELINE_CHECK")) { skip_baseline_check = true; } -#endif int baseline_features[] = { CV_CPU_BASELINE_FEATURES }; if (!checkFeatures(baseline_features, sizeof(baseline_features) / sizeof(baseline_features[0])) && !skip_baseline_check) @@ -843,15 +839,10 @@ struct HWFeatures void readSettings(const int* baseline_features, int baseline_count) { bool dump = true; - const char* disabled_features = -#ifdef NO_GETENV - NULL; -#else - getenv("OPENCV_CPU_DISABLE"); -#endif - if (disabled_features && disabled_features[0] != 0) + std::string disabled_features = utils::getConfigurationParameterString("OPENCV_CPU_DISABLE"); + if (!disabled_features.empty()) { - const char* start = disabled_features; + const char* start = disabled_features.c_str(); for (;;) { while (start[0] != 0 && isSymbolSeparator(start[0])) @@ -1137,20 +1128,19 @@ String tempfile( const char* suffix ) { #if OPENCV_HAVE_FILESYSTEM_SUPPORT String fname; -#ifndef NO_GETENV - const char *temp_dir = getenv("OPENCV_TEMP_PATH"); -#endif + + std::string temp_dir = utils::getConfigurationParameterString("OPENCV_TEMP_PATH"); #if defined _WIN32 #ifdef WINRT RoInitialize(RO_INIT_MULTITHREADED); - std::wstring temp_dir = GetTempPathWinRT(); + std::wstring temp_dir_rt = GetTempPathWinRT(); std::wstring temp_file = GetTempFileNameWinRT(L"ocv"); if (temp_file.empty()) return String(); - temp_file = temp_dir.append(std::wstring(L"\\")).append(temp_file); + temp_file = temp_dir_rt.append(std::wstring(L"\\")).append(temp_file); DeleteFileW(temp_file.c_str()); char aname[MAX_PATH]; @@ -1160,12 +1150,12 @@ String tempfile( const char* suffix ) RoUninitialize(); #elif defined(_WIN32_WCE) const auto kMaxPathSize = MAX_PATH+1; - wchar_t temp_dir[kMaxPathSize] = {0}; + wchar_t temp_dir_ce[kMaxPathSize] = {0}; wchar_t temp_file[kMaxPathSize] = {0}; - ::GetTempPathW(kMaxPathSize, temp_dir); + ::GetTempPathW(kMaxPathSize, temp_dir_ce); - if(0 != ::GetTempFileNameW(temp_dir, L"ocv", 0, temp_file)) { + if(0 != ::GetTempFileNameW(temp_dir_ce, L"ocv", 0, temp_file)) { DeleteFileW(temp_file); char aname[MAX_PATH]; size_t copied = wcstombs(aname, temp_file, MAX_PATH); @@ -1176,12 +1166,12 @@ String tempfile( const char* suffix ) char temp_dir2[MAX_PATH] = { 0 }; char temp_file[MAX_PATH] = { 0 }; - if (temp_dir == 0 || temp_dir[0] == 0) + if (temp_dir.empty()) { ::GetTempPathA(sizeof(temp_dir2), temp_dir2); - temp_dir = temp_dir2; + temp_dir = std::string(temp_dir2); } - if(0 == ::GetTempFileNameA(temp_dir, "ocv", 0, temp_file)) + if(0 == ::GetTempFileNameA(temp_dir.c_str(), "ocv", 0, temp_file)) return String(); DeleteFileA(temp_file); @@ -1196,7 +1186,7 @@ String tempfile( const char* suffix ) char defaultTemplate[] = "/tmp/__opencv_temp.XXXXXX"; # endif - if (temp_dir == 0 || temp_dir[0] == 0) + if (temp_dir.empty()) fname = defaultTemplate; else { @@ -2241,9 +2231,9 @@ size_t utils::getConfigurationParameterSizeT(const char* name, size_t defaultVal return read(name, defaultValue); } -cv::String utils::getConfigurationParameterString(const char* name, const char* defaultValue) +std::string utils::getConfigurationParameterString(const char* name, const std::string & defaultValue) { - return read(name, defaultValue ? cv::String(defaultValue) : cv::String()); + return read(name, defaultValue); } utils::Paths utils::getConfigurationParameterPaths(const char* name, const utils::Paths &defaultValue) @@ -2540,11 +2530,8 @@ public: } ippFeatures = cpuFeatures; - const char* pIppEnv = getenv("OPENCV_IPP"); - cv::String env; - if(pIppEnv != NULL) - env = pIppEnv; - if(env.size()) + std::string env = utils::getConfigurationParameterString("OPENCV_IPP"); + if(!env.empty()) { #if IPP_VERSION_X100 >= 201900 const Ipp64u minorFeatures = ippCPUID_MOVBE|ippCPUID_AES|ippCPUID_CLMUL|ippCPUID_ABR|ippCPUID_RDRAND|ippCPUID_F16C| diff --git a/modules/core/src/utils/datafile.cpp b/modules/core/src/utils/datafile.cpp index 67cc2571ac..380ba59258 100644 --- a/modules/core/src/utils/datafile.cpp +++ b/modules/core/src/utils/datafile.cpp @@ -60,7 +60,7 @@ static std::vector& _getDataSearchSubDirectory() CV_EXPORTS void addDataSearchPath(const cv::String& path) { - if (utils::fs::isDirectory(path)) + if (!path.empty() && utils::fs::isDirectory(path)) _getDataSearchPath().push_back(path); } CV_EXPORTS void addDataSearchSubDirectory(const cv::String& subdir) diff --git a/modules/core/src/utils/filesystem.cpp b/modules/core/src/utils/filesystem.cpp index 0a64bc994f..db16ac3347 100644 --- a/modules/core/src/utils/filesystem.cpp +++ b/modules/core/src/utils/filesystem.cpp @@ -447,8 +447,8 @@ cv::String getCacheDirectory(const char* sub_directory_name, const char* configu #elif defined __ANDROID__ // no defaults #elif defined __APPLE__ - const char* tmpdir_env = getenv("TMPDIR"); - if (tmpdir_env && utils::fs::isDirectory(tmpdir_env)) + const std::string tmpdir_env = utils::getConfigurationParameterString("TMPDIR"); + if (!tmpdir_env.empty() && utils::fs::isDirectory(tmpdir_env)) { default_cache_path = tmpdir_env; } @@ -461,16 +461,16 @@ cv::String getCacheDirectory(const char* sub_directory_name, const char* configu // https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html if (default_cache_path.empty()) { - const char* xdg_cache_env = getenv("XDG_CACHE_HOME"); - if (xdg_cache_env && xdg_cache_env[0] && utils::fs::isDirectory(xdg_cache_env)) + const std::string xdg_cache_env = utils::getConfigurationParameterString("XDG_CACHE_HOME"); + if (!xdg_cache_env.empty() && utils::fs::isDirectory(xdg_cache_env)) { default_cache_path = xdg_cache_env; } } if (default_cache_path.empty()) { - const char* home_env = getenv("HOME"); - if (home_env && home_env[0] && utils::fs::isDirectory(home_env)) + const std::string home_env = utils::getConfigurationParameterString("HOME"); + if (!home_env.empty() && utils::fs::isDirectory(home_env)) { cv::String home_path = home_env; cv::String home_cache_path = utils::fs::join(home_path, ".cache/"); diff --git a/modules/core/src/va_wrapper.impl.hpp b/modules/core/src/va_wrapper.impl.hpp index 77faa984d0..23b1b69dcb 100644 --- a/modules/core/src/va_wrapper.impl.hpp +++ b/modules/core/src/va_wrapper.impl.hpp @@ -7,6 +7,7 @@ // #include "opencv2/core/utils/plugin_loader.private.hpp" // DynamicLib +#include "opencv2/core/utils/configuration.private.hpp" namespace cv { namespace detail { @@ -47,8 +48,8 @@ static FN_vaGetImage fn_vaGetImage = NULL; static std::shared_ptr loadLibVA() { std::shared_ptr lib; - const char* envPath = getenv("OPENCV_LIBVA_RUNTIME"); - if (envPath) + const std::string envPath = utils::getConfigurationParameterString("OPENCV_LIBVA_RUNTIME"); + if (!envPath.empty()) { lib = std::make_shared(envPath); return lib; diff --git a/modules/core/test/test_io.cpp b/modules/core/test/test_io.cpp index e6fffa2594..f59fefa988 100644 --- a/modules/core/test/test_io.cpp +++ b/modules/core/test/test_io.cpp @@ -2,6 +2,7 @@ // 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 "test_precomp.hpp" + #include namespace opencv_test { namespace { diff --git a/modules/dnn/perf/perf_main.cpp b/modules/dnn/perf/perf_main.cpp index 073921efaf..bdb360fcb2 100644 --- a/modules/dnn/perf/perf_main.cpp +++ b/modules/dnn/perf/perf_main.cpp @@ -1,16 +1,7 @@ #include "perf_precomp.hpp" -static const char* extraTestDataPath = -#ifdef WINRT - NULL; -#else - getenv("OPENCV_DNN_TEST_DATA_PATH"); -#endif - #if defined(HAVE_HPX) #include #endif -CV_PERF_TEST_MAIN(dnn, - extraTestDataPath ? (void)cvtest::addDataSearchPath(extraTestDataPath) : (void)0 -) +CV_PERF_TEST_MAIN(dnn, cvtest::addDataSearchEnv("OPENCV_DNN_TEST_DATA_PATH")) diff --git a/modules/dnn/src/precomp.hpp b/modules/dnn/src/precomp.hpp index 178a8f42cf..cf17e0109d 100644 --- a/modules/dnn/src/precomp.hpp +++ b/modules/dnn/src/precomp.hpp @@ -47,6 +47,7 @@ #endif #include +#include "opencv2/core/utils/configuration.private.hpp" #ifndef CV_OCL4DNN #define CV_OCL4DNN 0 @@ -89,4 +90,4 @@ #include #include -#include "dnn_common.hpp" \ No newline at end of file +#include "dnn_common.hpp" diff --git a/modules/dnn/src/vkcom/vulkan/vk_loader.cpp b/modules/dnn/src/vkcom/vulkan/vk_loader.cpp index 4640d0a0cb..64cb7741b9 100644 --- a/modules/dnn/src/vkcom/vulkan/vk_loader.cpp +++ b/modules/dnn/src/vkcom/vulkan/vk_loader.cpp @@ -115,21 +115,12 @@ bool loadVulkanLibrary() if (handle != nullptr) return true; - const char* path; - const char* envPath = getenv("OPENCV_VULKAN_RUNTIME"); - if (envPath) - { - path = envPath; - } - else - { - path = DEFAULT_VK_LIBRARY_PATH; - } + const std::string path = cv::utils::getConfigurationParameterString("OPENCV_VULKAN_RUNTIME", DEFAULT_VK_LIBRARY_PATH); - handle = LOAD_VK_LIBRARY(path); + handle = LOAD_VK_LIBRARY(path.c_str()); if( handle == nullptr ) { - fprintf(stderr, "Could not load Vulkan library: %s!\n", path); + fprintf(stderr, "Could not load Vulkan library: %s!\n", path.c_str()); fprintf(stderr, "Please download the Vulkan SDK and set the environment variable of OPENCV_VULKAN_RUNTIME according " "to your system environment.\n"); fprintf(stderr, "For M1 Mac and IOS, we use MoltenVK to map the Vulkan code to native apple Metal code.\n"); diff --git a/modules/dnn/test/test_common.impl.hpp b/modules/dnn/test/test_common.impl.hpp index 70e1505f69..54c1bc6675 100644 --- a/modules/dnn/test/test_common.impl.hpp +++ b/modules/dnn/test/test_common.impl.hpp @@ -430,14 +430,7 @@ bool validateVPUType() void initDNNTests() { - const char* extraTestDataPath = -#ifdef WINRT - NULL; -#else - getenv("OPENCV_DNN_TEST_DATA_PATH"); -#endif - if (extraTestDataPath) - cvtest::addDataSearchPath(extraTestDataPath); + cvtest::addDataSearchEnv("OPENCV_DNN_TEST_DATA_PATH"); registerGlobalSkipTag( CV_TEST_TAG_DNN_SKIP_OPENCV_BACKEND, diff --git a/modules/dnn/test/test_ie_models.cpp b/modules/dnn/test/test_ie_models.cpp index eff389035d..647ee907bc 100644 --- a/modules/dnn/test/test_ie_models.cpp +++ b/modules/dnn/test/test_ie_models.cpp @@ -40,15 +40,11 @@ static void initDLDTDataPath() if (!initialized) { #if INF_ENGINE_RELEASE <= 2018050000 - const char* dldtTestDataPath = getenv("INTEL_CVSDK_DIR"); - if (dldtTestDataPath) - cvtest::addDataSearchPath(dldtTestDataPath); + cvtest::addDataSearchEnv("INTEL_CVSDK_DIR"); #else - const char* omzDataPath = getenv("OPENCV_OPEN_MODEL_ZOO_DATA_PATH"); - if (omzDataPath) - cvtest::addDataSearchPath(omzDataPath); - const char* dnnDataPath = getenv("OPENCV_DNN_TEST_DATA_PATH"); - if (dnnDataPath) + cvtest::addDataSearchEnv("OPENCV_OPEN_MODEL_ZOO_DATA_PATH"); + const std::string dnnDataPath = cv::utils::getConfigurationParameterString("OPENCV_DNN_TEST_DATA_PATH"); + if (!dnnDataPath.empty()) cvtest::addDataSearchPath(std::string(dnnDataPath) + "/omz_intel_models"); #endif initialized = true; diff --git a/modules/dnn/test/test_precomp.hpp b/modules/dnn/test/test_precomp.hpp index cc1ea639f7..931ae7698d 100644 --- a/modules/dnn/test/test_precomp.hpp +++ b/modules/dnn/test/test_precomp.hpp @@ -45,6 +45,7 @@ #include "opencv2/ts/ts_perf.hpp" #include "opencv2/core/utility.hpp" #include "opencv2/core/ocl.hpp" +#include "opencv2/core/utils/configuration.private.hpp" #include "opencv2/dnn.hpp" #include "test_common.hpp" diff --git a/modules/gapi/src/compiler/gcompiler.cpp b/modules/gapi/src/compiler/gcompiler.cpp index 568251f19e..666271d7ba 100644 --- a/modules/gapi/src/compiler/gcompiler.cpp +++ b/modules/gapi/src/compiler/gcompiler.cpp @@ -99,9 +99,9 @@ namespace auto dump_info = cv::gapi::getCompileArg(args); if (!dump_info.has_value()) { - const char* path = std::getenv("GRAPH_DUMP_PATH"); - return path - ? cv::util::make_optional(std::string(path)) + const std::string path = cv::utils::getConfigurationParameterString("GRAPH_DUMP_PATH"); + return !path.empty() + ? cv::util::make_optional(path) : cv::util::optional(); } else diff --git a/modules/gapi/src/precomp.hpp b/modules/gapi/src/precomp.hpp index f72d0a1ecc..6aeaa0e58b 100644 --- a/modules/gapi/src/precomp.hpp +++ b/modules/gapi/src/precomp.hpp @@ -10,6 +10,7 @@ #if !defined(GAPI_STANDALONE) # include +# include # include # include # include diff --git a/modules/gapi/test/infer/gapi_infer_ie_test.cpp b/modules/gapi/test/infer/gapi_infer_ie_test.cpp index a7c9637a4f..ff27489434 100644 --- a/modules/gapi/test/infer/gapi_infer_ie_test.cpp +++ b/modules/gapi/test/infer/gapi_infer_ie_test.cpp @@ -101,22 +101,18 @@ public: // FIXME: taken from DNN module static void initDLDTDataPath() { -#ifndef WINRT static bool initialized = false; if (!initialized) { - const char* omzDataPath = getenv("OPENCV_OPEN_MODEL_ZOO_DATA_PATH"); - if (omzDataPath) - cvtest::addDataSearchPath(omzDataPath); - const char* dnnDataPath = getenv("OPENCV_DNN_TEST_DATA_PATH"); - if (dnnDataPath) { + cvtest::addDataSearchEnv("OPENCV_OPEN_MODEL_ZOO_DATA_PATH"); + const std::string dnnDataPath = cv::utils::getConfigurationParameterString("OPENCV_DNN_TEST_DATA_PATH"); + if (!dnnDataPath.empty()) { // Add the dnnDataPath itself - G-API is using some images there directly cvtest::addDataSearchPath(dnnDataPath); cvtest::addDataSearchPath(dnnDataPath + std::string("/omz_intel_models")); } initialized = true; } -#endif // WINRT } #if INF_ENGINE_RELEASE >= 2020010000 diff --git a/modules/gapi/test/infer/gapi_infer_onnx_test.cpp b/modules/gapi/test/infer/gapi_infer_onnx_test.cpp index dff91c597e..6ca394aef2 100644 --- a/modules/gapi/test/infer/gapi_infer_onnx_test.cpp +++ b/modules/gapi/test/infer/gapi_infer_onnx_test.cpp @@ -58,10 +58,7 @@ public: }; struct ONNXInitPath { ONNXInitPath() { - const char* env_path = getenv("OPENCV_GAPI_ONNX_MODEL_PATH"); - if (env_path) { - cvtest::addDataSearchPath(env_path); - } + cvtest::addDataSearchEnv("OPENCV_GAPI_ONNX_MODEL_PATH"); } }; static ONNXInitPath g_init_path; diff --git a/modules/gapi/test/infer/gapi_infer_ov_tests.cpp b/modules/gapi/test/infer/gapi_infer_ov_tests.cpp index 49652db387..85df0b24da 100644 --- a/modules/gapi/test/infer/gapi_infer_ov_tests.cpp +++ b/modules/gapi/test/infer/gapi_infer_ov_tests.cpp @@ -25,11 +25,9 @@ void initDLDTDataPath() static bool initialized = false; if (!initialized) { - const char* omzDataPath = getenv("OPENCV_OPEN_MODEL_ZOO_DATA_PATH"); - if (omzDataPath) - cvtest::addDataSearchPath(omzDataPath); - const char* dnnDataPath = getenv("OPENCV_DNN_TEST_DATA_PATH"); - if (dnnDataPath) { + cvtest::addDataSearchEnv("OPENCV_OPEN_MODEL_ZOO_DATA_PATH"); + const std::string dnnDataPath = cv::utils::getConfigurationParameterString("OPENCV_DNN_TEST_DATA_PATH"); + if (!dnnDataPath.empty()) { // Add the dnnDataPath itself - G-API is using some images there directly cvtest::addDataSearchPath(dnnDataPath); cvtest::addDataSearchPath(dnnDataPath + std::string("/omz_intel_models")); diff --git a/modules/gapi/test/test_precomp.hpp b/modules/gapi/test/test_precomp.hpp index e92b1d03bf..708964dfe6 100644 --- a/modules/gapi/test/test_precomp.hpp +++ b/modules/gapi/test/test_precomp.hpp @@ -16,6 +16,8 @@ #include +#include + #include #include #include diff --git a/modules/highgui/src/precomp.hpp b/modules/highgui/src/precomp.hpp index fe0cd89940..6bab49cdd4 100644 --- a/modules/highgui/src/precomp.hpp +++ b/modules/highgui/src/precomp.hpp @@ -55,6 +55,7 @@ #include "opencv2/core/utility.hpp" #if defined(__OPENCV_BUILD) #include "opencv2/core/private.hpp" +#include "opencv2/core/utils/configuration.private.hpp" #endif #include "opencv2/imgproc.hpp" diff --git a/modules/highgui/src/registry.impl.hpp b/modules/highgui/src/registry.impl.hpp index 782738a820..9cdf6b17eb 100644 --- a/modules/highgui/src/registry.impl.hpp +++ b/modules/highgui/src/registry.impl.hpp @@ -133,7 +133,7 @@ protected: bool readPrioritySettings() { bool hasChanges = false; - cv::String prioritized_backends = utils::getConfigurationParameterString("OPENCV_UI_PRIORITY_LIST", NULL); + cv::String prioritized_backends = utils::getConfigurationParameterString("OPENCV_UI_PRIORITY_LIST"); if (prioritized_backends.empty()) return hasChanges; CV_LOG_INFO(NULL, "UI: Configured priority list (OPENCV_UI_PRIORITY_LIST): " << prioritized_backends); diff --git a/modules/highgui/src/window_wayland.cpp b/modules/highgui/src/window_wayland.cpp index b8f6fcfcf3..6c85df28df 100644 --- a/modules/highgui/src/window_wayland.cpp +++ b/modules/highgui/src/window_wayland.cpp @@ -1378,7 +1378,7 @@ int cv_wl_buffer::create_tmpfile(std::string const &tmpname) { } int cv_wl_buffer::create_anonymous_file(off_t size) { - auto path = getenv("XDG_RUNTIME_DIR") + std::string("/opencv-shared-XXXXXX"); + auto path = cv::utils::getConfigurationParameterString("XDG_RUNTIME_DIR") + std::string("/opencv-shared-XXXXXX"); int fd = create_tmpfile(path); int ret = posix_fallocate(fd, 0, size); diff --git a/modules/objdetect/test/test_main.cpp b/modules/objdetect/test/test_main.cpp index 4031f0522b..a7e31f2dd8 100644 --- a/modules/objdetect/test/test_main.cpp +++ b/modules/objdetect/test/test_main.cpp @@ -11,14 +11,7 @@ static void initTests() { #ifdef HAVE_OPENCV_DNN - const char* extraTestDataPath = -#ifdef WINRT - NULL; -#else - getenv("OPENCV_DNN_TEST_DATA_PATH"); -#endif - if (extraTestDataPath) - cvtest::addDataSearchPath(extraTestDataPath); + cvtest::addDataSearchEnv("OPENCV_DNN_TEST_DATA_PATH"); #endif // HAVE_OPENCV_DNN } diff --git a/modules/ts/include/opencv2/ts.hpp b/modules/ts/include/opencv2/ts.hpp index 0c86794392..72512e74d8 100644 --- a/modules/ts/include/opencv2/ts.hpp +++ b/modules/ts/include/opencv2/ts.hpp @@ -843,6 +843,7 @@ void smoothBorder(Mat& img, const Scalar& color, int delta = 3) // Utility functions void addDataSearchPath(const std::string& path); +void addDataSearchEnv(const std::string& env_name); void addDataSearchSubDirectory(const std::string& subdir); /*! @brief Try to find requested data file diff --git a/modules/ts/src/precomp.hpp b/modules/ts/src/precomp.hpp index 2725f63429..8508765079 100644 --- a/modules/ts/src/precomp.hpp +++ b/modules/ts/src/precomp.hpp @@ -1,5 +1,6 @@ #include "opencv2/ts.hpp" #include +#include "opencv2/core/utils/configuration.private.hpp" #include "opencv2/core/utility.hpp" #if !defined(__EMSCRIPTEN__) #include "opencv2/core/private.hpp" diff --git a/modules/ts/src/ts.cpp b/modules/ts/src/ts.cpp index 905b248473..83def40c7f 100644 --- a/modules/ts/src/ts.cpp +++ b/modules/ts/src/ts.cpp @@ -551,13 +551,9 @@ static int tsErrorCallback( int status, const char* func_name, const char* err_m void TS::init( const string& modulename ) { data_search_subdir.push_back(modulename); -#ifndef WINRT - char* datapath_dir = getenv("OPENCV_TEST_DATA_PATH"); -#else - char* datapath_dir = OPENCV_TEST_DATA_PATH; -#endif + std::string datapath_dir = cv::utils::getConfigurationParameterString("OPENCV_TEST_DATA_PATH"); - if( datapath_dir ) + if( !datapath_dir.empty() ) { data_path = path_join(path_join(datapath_dir, modulename), ""); } @@ -850,11 +846,7 @@ void parseCustomOptions(int argc, char **argv) test_ipp_check = parser.get("test_ipp_check"); if (!test_ipp_check) -#ifndef WINRT - test_ipp_check = getenv("OPENCV_IPP_CHECK") != NULL; -#else - test_ipp_check = false; -#endif + test_ipp_check = cv::utils::getConfigurationParameterBool("OPENCV_IPP_CHECK"); param_seed = parser.get("test_seed"); @@ -900,9 +892,14 @@ static bool isDirectory(const std::string& path) void addDataSearchPath(const std::string& path) { - if (isDirectory(path)) + if (!path.empty() && isDirectory(path)) TS::ptr()->data_search_path.push_back(path); } +void addDataSearchEnv(const std::string& env_name) +{ + const std::string val = cv::utils::getConfigurationParameterString(env_name.c_str()); + cvtest::addDataSearchPath(val); +} void addDataSearchSubDirectory(const std::string& subdir) { TS::ptr()->data_search_subdir.push_back(subdir); @@ -948,14 +945,10 @@ static std::string findData(const std::string& relative_path, bool required, boo const std::vector& search_subdir = TS::ptr()->data_search_subdir; -#ifndef WINRT - char* datapath_dir = getenv("OPENCV_TEST_DATA_PATH"); -#else - char* datapath_dir = OPENCV_TEST_DATA_PATH; -#endif + std::string datapath_dir = cv::utils::getConfigurationParameterString("OPENCV_TEST_DATA_PATH"); std::string datapath; - if (datapath_dir) + if (!datapath_dir.empty()) { datapath = datapath_dir; //CV_Assert(isDirectory(datapath) && "OPENCV_TEST_DATA_PATH is specified but it doesn't exist"); diff --git a/modules/ts/src/ts_perf.cpp b/modules/ts/src/ts_perf.cpp index 09b9ac1a9b..638978246f 100644 --- a/modules/ts/src/ts_perf.cpp +++ b/modules/ts/src/ts_perf.cpp @@ -192,22 +192,18 @@ void Regression::init(const std::string& testSuitName, const std::string& ext) return; } -#ifndef WINRT - const char *data_path_dir = getenv("OPENCV_TEST_DATA_PATH"); -#else - const char *data_path_dir = OPENCV_TEST_DATA_PATH; -#endif + const std::string data_path_dir = utils::getConfigurationParameterString("OPENCV_TEST_DATA_PATH"); cvtest::addDataSearchSubDirectory(""); cvtest::addDataSearchSubDirectory(testSuitName); const char *path_separator = "/"; - if (data_path_dir) + if (!data_path_dir.empty()) { - int len = (int)strlen(data_path_dir)-1; + int len = (int)data_path_dir.size()-1; if (len < 0) len = 0; - std::string path_base = (data_path_dir[0] == 0 ? std::string(".") : std::string(data_path_dir)) + std::string path_base = (data_path_dir[0] == 0 ? std::string(".") : data_path_dir) + (data_path_dir[len] == '/' || data_path_dir[len] == '\\' ? "" : path_separator) + "perf" + path_separator; @@ -1051,7 +1047,7 @@ void TestBase::Init(const std::vector & availableImpls, param_verify_sanity = args.get("perf_verify_sanity"); #ifdef HAVE_IPP - test_ipp_check = !args.get("perf_ipp_check") ? getenv("OPENCV_IPP_CHECK") != NULL : true; + test_ipp_check = !args.get("perf_ipp_check") ? utils::getConfigurationParameterBool("OPENCV_IPP_CHECK") : true; #endif testThreads = args.get("perf_threads"); #ifdef CV_COLLECT_IMPL_DATA @@ -1134,12 +1130,11 @@ void TestBase::Init(const std::vector & availableImpls, #endif { -#ifndef WINRT - const char* path = getenv("OPENCV_PERF_VALIDATION_DIR"); -#else - const char* path = OPENCV_PERF_VALIDATION_DIR; + std::string path = utils::getConfigurationParameterString("OPENCV_PERF_VALIDATION_DIR"); +#ifdef WINRT + path = OPENCV_PERF_VALIDATION_DIR; #endif - if (path) + if (!path.empty()) perf_validation_results_directory = path; } @@ -1897,17 +1892,16 @@ std::string TestBase::getDataPath(const std::string& relativePath) throw PerfEarlyExitException(); } -#ifndef WINRT - const char *data_path_dir = getenv("OPENCV_TEST_DATA_PATH"); -#else - const char *data_path_dir = OPENCV_TEST_DATA_PATH; + std::string data_path_dir = utils::getConfigurationParameterString("OPENCV_TEST_DATA_PATH"); +#ifdef WINRT + data_path_dir = OPENCV_TEST_DATA_PATH; #endif const char *path_separator = "/"; std::string path; - if (data_path_dir) + if (!data_path_dir.empty()) { - int len = (int)strlen(data_path_dir) - 1; + int len = (int)data_path_dir.size() - 1; if (len < 0) len = 0; path = (data_path_dir[0] == 0 ? std::string(".") : std::string(data_path_dir)) + (data_path_dir[len] == '/' || data_path_dir[len] == '\\' ? "" : path_separator); diff --git a/modules/video/perf/perf_main.cpp b/modules/video/perf/perf_main.cpp index 1879aeff90..2bf9123d96 100644 --- a/modules/video/perf/perf_main.cpp +++ b/modules/video/perf/perf_main.cpp @@ -7,15 +7,7 @@ static void initTests() { - const char* extraTestDataPath = -#ifdef WINRT - NULL; -#else - getenv("OPENCV_DNN_TEST_DATA_PATH"); -#endif - if (extraTestDataPath) - cvtest::addDataSearchPath(extraTestDataPath); - + cvtest::addDataSearchEnv("OPENCV_DNN_TEST_DATA_PATH"); cvtest::addDataSearchSubDirectory(""); // override "cv" prefix below to access without "../dnn" hacks } diff --git a/modules/video/perf/perf_precomp.hpp b/modules/video/perf/perf_precomp.hpp index ccc1865ff7..529a1436f9 100644 --- a/modules/video/perf/perf_precomp.hpp +++ b/modules/video/perf/perf_precomp.hpp @@ -7,6 +7,7 @@ #include "opencv2/ts.hpp" #include #include "opencv2/ts/ts_perf.hpp" +#include "opencv2/core/utils/configuration.private.hpp" namespace cvtest { diff --git a/modules/video/test/test_main.cpp b/modules/video/test/test_main.cpp index 9968380a17..68c90f775e 100644 --- a/modules/video/test/test_main.cpp +++ b/modules/video/test/test_main.cpp @@ -10,15 +10,7 @@ static void initTests() { - const char* extraTestDataPath = -#ifdef WINRT - NULL; -#else - getenv("OPENCV_DNN_TEST_DATA_PATH"); -#endif - if (extraTestDataPath) - cvtest::addDataSearchPath(extraTestDataPath); - + cvtest::addDataSearchEnv("OPENCV_DNN_TEST_DATA_PATH"); cvtest::addDataSearchSubDirectory(""); // override "cv" prefix below to access without "../dnn" hacks } diff --git a/modules/video/test/test_precomp.hpp b/modules/video/test/test_precomp.hpp index ba1f10998f..a6810ccc1f 100644 --- a/modules/video/test/test_precomp.hpp +++ b/modules/video/test/test_precomp.hpp @@ -7,6 +7,7 @@ #include "opencv2/ts.hpp" #include "opencv2/video.hpp" #include +#include "opencv2/core/utils/configuration.private.hpp" namespace opencv_test { using namespace perf; diff --git a/modules/videoio/src/backend_plugin.cpp b/modules/videoio/src/backend_plugin.cpp index 5e65137cd4..0f4243fb9e 100644 --- a/modules/videoio/src/backend_plugin.cpp +++ b/modules/videoio/src/backend_plugin.cpp @@ -336,16 +336,14 @@ std::vector getPluginCandidates(const std::string& baseName) std::vector results; #ifdef _WIN32 FileSystemPath_t moduleName = toFileSystemPath(libraryPrefix() + "opencv_videoio_" + baseName_l + librarySuffix()); -#ifndef WINRT if (baseName_u == "FFMPEG") // backward compatibility { - const wchar_t* ffmpeg_env_path = _wgetenv(L"OPENCV_FFMPEG_DLL_DIR"); - if (ffmpeg_env_path) + const std::string ffmpeg_env_path = cv::utils::getConfigurationParameterString("OPENCV_FFMPEG_DLL_DIR"); + if (!ffmpeg_env_path.empty()) { - results.push_back(FileSystemPath_t(ffmpeg_env_path) + L"\\" + moduleName); + results.push_back(toFileSystemPath(ffmpeg_env_path + "\\" + toPrintablePath(moduleName))); } } -#endif if (plugin_expr != default_expr) { moduleName = toFileSystemPath(plugin_expr); diff --git a/modules/videoio/src/cap_dshow.cpp b/modules/videoio/src/cap_dshow.cpp index 7cc0469200..d46bb08a0d 100644 --- a/modules/videoio/src/cap_dshow.cpp +++ b/modules/videoio/src/cap_dshow.cpp @@ -303,15 +303,7 @@ interface ISampleGrabber : public IUnknown static void DebugPrintOut(const char *format, ...) { - static int gs_verbose = -1; - if (gs_verbose < 0) - { - // Fetch initial debug state from environment - defaults to disabled - const char* s = getenv("OPENCV_DSHOW_DEBUG"); - gs_verbose = s != NULL && atoi(s) != 0; - } - - + static const bool gs_verbose = utils::getConfigurationParameterBool("OPENCV_DSHOW_DEBUG"); if (gs_verbose) { va_list args; @@ -2982,18 +2974,18 @@ int videoInput::start(int deviceID, videoDevice *VD){ VD->readyToCapture = true; // check for optional saving the direct show graph to a file - const char* graph_filename = getenv("OPENCV_DSHOW_SAVEGRAPH_FILENAME"); - if (graph_filename) { - size_t filename_len = strlen(graph_filename); + std::string graph_filename = utils::getConfigurationParameterString("OPENCV_DSHOW_SAVEGRAPH_FILENAME"); + if (!graph_filename.empty()) { + size_t filename_len = graph_filename.size(); std::vector wfilename(filename_len + 1); - size_t len = mbstowcs(&wfilename[0], graph_filename, filename_len + 1); + size_t len = mbstowcs(&wfilename[0], &graph_filename[0], filename_len + 1); CV_Assert(len == filename_len); HRESULT res = SaveGraphFile(VD->pGraph, &wfilename[0]); if (SUCCEEDED(res)) { - DebugPrintOut("Saved DSHOW graph to %s\n", graph_filename); + DebugPrintOut("Saved DSHOW graph to %s\n", graph_filename.c_str()); } else { - DebugPrintOut("Failed to save DSHOW graph to %s\n", graph_filename); + DebugPrintOut("Failed to save DSHOW graph to %s\n", graph_filename.c_str()); } } diff --git a/modules/videoio/src/cap_ffmpeg_impl.hpp b/modules/videoio/src/cap_ffmpeg_impl.hpp index 17e9f4903f..f13cb8462b 100644 --- a/modules/videoio/src/cap_ffmpeg_impl.hpp +++ b/modules/videoio/src/cap_ffmpeg_impl.hpp @@ -928,21 +928,19 @@ public: } static void initLogger_() { -#ifndef NO_GETENV - char* debug_option = getenv("OPENCV_FFMPEG_DEBUG"); - char* level_option = getenv("OPENCV_FFMPEG_LOGLEVEL"); + const bool debug_option = utils::getConfigurationParameterBool("OPENCV_FFMPEG_DEBUG"); + std::string level_option = utils::getConfigurationParameterString("OPENCV_FFMPEG_LOGLEVEL"); int level = AV_LOG_VERBOSE; - if (level_option != NULL) + if (!level_option.empty()) { - level = atoi(level_option); + level = atoi(level_option.c_str()); } - if ( (debug_option != NULL) || (level_option != NULL) ) + if ( debug_option || (!level_option.empty()) ) { av_log_set_level(level); av_log_set_callback(ffmpeg_log_callback); } else -#endif { av_log_set_level(AV_LOG_ERROR); } @@ -979,10 +977,10 @@ inline void fill_codec_context(AVCodecContext * enc, AVDictionary * dict) { int nCpus = cv::getNumberOfCPUs(); int requestedThreads = std::min(nCpus, 16); // [OPENCV:FFMPEG:24] Application has requested XX threads. Using a thread count greater than 16 is not recommended. - char* threads_option = getenv("OPENCV_FFMPEG_THREADS"); - if (threads_option != NULL) + std::string threads_option = utils::getConfigurationParameterString("OPENCV_FFMPEG_THREADS"); + if (!threads_option.empty()) { - requestedThreads = atoi(threads_option); + requestedThreads = atoi(threads_option.c_str()); } enc->thread_count = requestedThreads; } @@ -1122,9 +1120,8 @@ bool CvCapture_FFMPEG::open(const char* _filename, const VideoCaptureParameters& ic->interrupt_callback.opaque = &interrupt_metadata; #endif -#ifndef NO_GETENV - char* options = getenv("OPENCV_FFMPEG_CAPTURE_OPTIONS"); - if(options == NULL) + std::string options = utils::getConfigurationParameterString("OPENCV_FFMPEG_CAPTURE_OPTIONS"); + if(!options.empty()) { #if LIBAVFORMAT_VERSION_MICRO >= 100 && LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(55, 48, 100) av_dict_set(&dict, "rtsp_flags", "prefer_tcp", 0); @@ -1136,14 +1133,11 @@ bool CvCapture_FFMPEG::open(const char* _filename, const VideoCaptureParameters& { CV_LOG_DEBUG(NULL, "VIDEOIO/FFMPEG: using capture options from environment: " << options); #if LIBAVUTIL_BUILD >= (LIBAVUTIL_VERSION_MICRO >= 100 ? CALC_FFMPEG_VERSION(52, 17, 100) : CALC_FFMPEG_VERSION(52, 7, 0)) - av_dict_parse_string(&dict, options, ";", "|", 0); + av_dict_parse_string(&dict, options.c_str(), ";", "|", 0); #else av_dict_set(&dict, "rtsp_transport", "tcp", 0); #endif } -#else - av_dict_set(&dict, "rtsp_transport", "tcp", 0); -#endif CV_FFMPEG_FMT_CONST AVInputFormat* input_format = NULL; AVDictionaryEntry* entry = av_dict_get(dict, "input_format", NULL, 0); if (entry != 0) @@ -3095,12 +3089,12 @@ bool CvVideoWriter_FFMPEG::open( const char * filename, int fourcc, } AVDictionary *dict = NULL; -#if !defined(NO_GETENV) && (LIBAVUTIL_VERSION_MAJOR >= 53) - char* options = getenv("OPENCV_FFMPEG_WRITER_OPTIONS"); - if (options) +#if (LIBAVUTIL_VERSION_MAJOR >= 53) + std::string options = utils::getConfigurationParameterString("OPENCV_FFMPEG_WRITER_OPTIONS"); + if (!options.empty()) { CV_LOG_DEBUG(NULL, "VIDEOIO/FFMPEG: using writer options from environment: " << options); - av_dict_parse_string(&dict, options, ";", "|", 0); + av_dict_parse_string(&dict, options.c_str(), ";", "|", 0); } #endif diff --git a/modules/videoio/src/videoio_registry.cpp b/modules/videoio/src/videoio_registry.cpp index 6535daaafd..641c1f6850 100644 --- a/modules/videoio/src/videoio_registry.cpp +++ b/modules/videoio/src/videoio_registry.cpp @@ -253,7 +253,7 @@ protected: bool readPrioritySettings() { bool hasChanges = false; - cv::String prioritized_backends = utils::getConfigurationParameterString("OPENCV_VIDEOIO_PRIORITY_LIST", NULL); + cv::String prioritized_backends = utils::getConfigurationParameterString("OPENCV_VIDEOIO_PRIORITY_LIST"); if (prioritized_backends.empty()) return hasChanges; CV_LOG_INFO(NULL, "VIDEOIO: Configured priority list (OPENCV_VIDEOIO_PRIORITY_LIST): " << prioritized_backends); diff --git a/modules/videoio/test/test_main.cpp b/modules/videoio/test/test_main.cpp index d57a611c4b..db82968d76 100644 --- a/modules/videoio/test/test_main.cpp +++ b/modules/videoio/test/test_main.cpp @@ -11,15 +11,13 @@ static void initTests() { -#ifndef WINRT // missing getenv const std::vector backends = cv::videoio_registry::getStreamBackends(); - const char* requireFFmpeg = getenv("OPENCV_TEST_VIDEOIO_BACKEND_REQUIRE_FFMPEG"); + bool requireFFmpeg = cv::utils::getConfigurationParameterBool("OPENCV_TEST_VIDEOIO_BACKEND_REQUIRE_FFMPEG"); if (requireFFmpeg && !isBackendAvailable(cv::CAP_FFMPEG, backends)) { CV_LOG_FATAL(NULL, "OpenCV-Test: required FFmpeg backend is not available (broken plugin?). STOP."); exit(1); } -#endif } CV_TEST_MAIN("highgui", initTests()) diff --git a/modules/videoio/test/test_precomp.hpp b/modules/videoio/test/test_precomp.hpp index cf37b09559..f5ab4f8f84 100644 --- a/modules/videoio/test/test_precomp.hpp +++ b/modules/videoio/test/test_precomp.hpp @@ -13,6 +13,7 @@ #include "opencv2/videoio.hpp" #include "opencv2/videoio/registry.hpp" #include "opencv2/core/private.hpp" +#include "opencv2/core/utils/configuration.private.hpp" namespace cv {