diff --git a/modules/calib/src/calibration.cpp b/modules/calib/src/calibration.cpp index c45d6aca0a..67dd00d04d 100644 --- a/modules/calib/src/calibration.cpp +++ b/modules/calib/src/calibration.cpp @@ -924,7 +924,7 @@ static double calibrateCameraInternalBouguet( const Mat& objectPoints, bool optimizeObjPoints = releaseObject; Mat_ param_m = _param.getMat(); - param_m = param_m.reshape(1, max(param_m.rows, param_m.cols)); + param_m = param_m.reshape(1, std::max(param_m.rows, param_m.cols)); if( flags & CALIB_FIX_ASPECT_RATIO ) { diff --git a/modules/calib/src/calibration_handeye.cpp b/modules/calib/src/calibration_handeye.cpp index 909bcedee6..e409eaa501 100644 --- a/modules/calib/src/calibration_handeye.cpp +++ b/modules/calib/src/calibration_handeye.cpp @@ -40,22 +40,22 @@ static Mat rot2quatMinimal(const Mat& R) double qx, qy, qz; if (trace > 0) { - double S = sqrt(trace + 1.0) * 2; // S=4*qw + double S = std::sqrt(trace + 1.0) * 2; // S=4*qw qx = (m21 - m12) / S; qy = (m02 - m20) / S; qz = (m10 - m01) / S; } else if (m00 > m11 && m00 > m22) { - double S = sqrt(1.0 + m00 - m11 - m22) * 2; // S=4*qx + double S = std::sqrt(1.0 + m00 - m11 - m22) * 2; // S=4*qx qx = 0.25 * S; qy = (m01 + m10) / S; qz = (m02 + m20) / S; } else if (m11 > m22) { - double S = sqrt(1.0 + m11 - m00 - m22) * 2; // S=4*qy + double S = std::sqrt(1.0 + m11 - m00 - m22) * 2; // S=4*qy qx = (m01 + m10) / S; qy = 0.25 * S; qz = (m12 + m21) / S; } else { - double S = sqrt(1.0 + m22 - m00 - m11) * 2; // S=4*qz + double S = std::sqrt(1.0 + m22 - m00 - m11) * 2; // S=4*qz qx = (m02 + m20) / S; qy = (m12 + m21) / S; qz = 0.25 * S; @@ -88,7 +88,7 @@ static Mat quatMinimal2rot(const Mat& q) CV_Assert(q.type() == CV_64FC1 && q.rows == 3 && q.cols == 1); Mat p = q.t()*q; - double w = sqrt(1 - p.at(0,0)); + double w = std::sqrt(1 - p.at(0,0)); Mat diag_p = Mat::eye(3,3,CV_64FC1)*p.at(0,0); return 2*q*q.t() + 2*w*skew(q) + Mat::eye(3,3,CV_64FC1) - 2*diag_p; @@ -110,25 +110,25 @@ static Mat rot2quat(const Mat& R) double qw, qx, qy, qz; if (trace > 0) { - double S = sqrt(trace + 1.0) * 2; // S=4*qw + double S = std::sqrt(trace + 1.0) * 2; // S=4*qw qw = 0.25 * S; qx = (m21 - m12) / S; qy = (m02 - m20) / S; qz = (m10 - m01) / S; } else if (m00 > m11 && m00 > m22) { - double S = sqrt(1.0 + m00 - m11 - m22) * 2; // S=4*qx + double S = std::sqrt(1.0 + m00 - m11 - m22) * 2; // S=4*qx qw = (m21 - m12) / S; qx = 0.25 * S; qy = (m01 + m10) / S; qz = (m02 + m20) / S; } else if (m11 > m22) { - double S = sqrt(1.0 + m11 - m00 - m22) * 2; // S=4*qy + double S = std::sqrt(1.0 + m11 - m00 - m22) * 2; // S=4*qy qw = (m02 - m20) / S; qx = (m01 + m10) / S; qy = 0.25 * S; qz = (m12 + m21) / S; } else { - double S = sqrt(1.0 + m22 - m00 - m11) * 2; // S=4*qz + double S = std::sqrt(1.0 + m22 - m00 - m11) * 2; // S=4*qz qw = (m10 - m01) / S; qx = (m02 + m20) / S; qy = (m12 + m21) / S; @@ -345,7 +345,7 @@ static void calibrateHandEyeTsai(const std::vector& Hg, const std::vector(0,0)); //eq 14 + Mat Pcg = 2 * Pcg_ / std::sqrt(1 + Pcg_norm.at(0,0)); //eq 14 Mat Rcg = quatMinimal2rot(Pcg/2.0); @@ -410,7 +410,7 @@ static void calibrateHandEyePark(const std::vector& Hg, const std::vector(i,i) = 1.0 / sqrt(eigenvalues.at(i,0)); + v.at(i,i) = 1.0 / std::sqrt(eigenvalues.at(i,0)); } Mat R = eigenvectors.t() * v * eigenvectors * M.t(); @@ -691,8 +691,8 @@ static void calibrateHandEyeDaniilidis(const std::vector& Hg, const std::ve double b = mb.at(0,0); double c = mc.at(0,0); - double s1 = (-b + sqrt(b*b - 4*a*c)) / (2*a); - double s2 = (-b - sqrt(b*b - 4*a*c)) / (2*a); + double s1 = (-b + std::sqrt(b*b - 4*a*c)) / (2*a); + double s2 = (-b - std::sqrt(b*b - 4*a*c)) / (2*a); Mat sol1 = s1*s1*u1.t()*u1 + 2*s1*u1.t()*u2 + u2.t()*u2; Mat sol2 = s2*s2*u1.t()*u1 + 2*s2*u1.t()*u2 + u2.t()*u2; @@ -708,7 +708,7 @@ static void calibrateHandEyeDaniilidis(const std::vector& Hg, const std::ve val = sol2.at(0,0); } - double lambda2 = sqrt(1.0 / val); + double lambda2 = std::sqrt(1.0 / val); double lambda1 = s * lambda2; Mat dualq = lambda1 * v(Rect(6, 0, 1, 8)) + lambda2*v(Rect(7, 0, 1, 8)); diff --git a/modules/calib/src/fisheye.cpp b/modules/calib/src/fisheye.cpp index ca0a7a8d5a..3adb818aca 100644 --- a/modules/calib/src/fisheye.cpp +++ b/modules/calib/src/fisheye.cpp @@ -98,8 +98,6 @@ static double normalizePoints(const Mat& points, Mat& normalizedPoints, Mat& pointMean) { - using std::fpclassify; - using std::sqrt; constexpr double defaultPointScale = 1.0; const Mat pointCoordinates = points.reshape(1, static_cast(points.total())); @@ -110,14 +108,14 @@ static double normalizePoints(const Mat& points, // Apply Hartley normalization. The maximum coordinate is an intermediate // preconditioner that prevents the squared norm from underflowing. double maximumCoordinate = norm(centeredPoints, NORM_INF); - if (fpclassify(maximumCoordinate) == FP_ZERO) + if (std::fpclassify(maximumCoordinate) == FP_ZERO) { maximumCoordinate = defaultPointScale; } Mat scaledPoints = centeredPoints / maximumCoordinate; double standardDeviation = - norm(scaledPoints, NORM_L2) / sqrt(scaledPoints.total()); - if (fpclassify(standardDeviation) == FP_ZERO) + norm(scaledPoints, NORM_L2) / std::sqrt(scaledPoints.total()); + if (std::fpclassify(standardDeviation) == FP_ZERO) { standardDeviation = defaultPointScale; } @@ -251,7 +249,7 @@ double cv::fisheye::calibrate(InputArrayOfArrays objectPoints, InputArrayOfArray } else { - finalParam.Init(Vec2d(max(image_size.width, image_size.height) / 2., max(image_size.width, image_size.height) / 2.), + finalParam.Init(Vec2d(std::max(image_size.width, image_size.height) / 2., std::max(image_size.width, image_size.height) / 2.), Vec2d(image_size.width / 2.0 - 0.5, image_size.height / 2.0 - 0.5)); } @@ -617,7 +615,7 @@ double cv::fisheye::stereoCalibrate(InputArrayOfArrays objectPoints, InputArrayO } rms /= ((double)e.total() / 2.0); - rms = sqrt(rms); + rms = std::sqrt(rms); _K1 = Matx33d(intrinsicLeft.f[0], intrinsicLeft.f[0] * intrinsicLeft.alpha, intrinsicLeft.c[0], 0, intrinsicLeft.f[1], intrinsicLeft.c[1], @@ -1127,7 +1125,7 @@ void cv::internal::EstimateUncertainties(InputArrayOfArrays objectPoints, InputA } meanStdDev(ex, noArray(), std_err); - std_err *= sqrt((double)ex.total()/((double)ex.total() - 1.0)); + std_err *= std::sqrt((double)ex.total()/((double)ex.total() - 1.0)); Vec sigma_x; meanStdDev(ex.reshape(1, 1), noArray(), sigma_x); @@ -1141,10 +1139,10 @@ void cv::internal::EstimateUncertainties(InputArrayOfArrays objectPoints, InputA // an explanation of that denominator correction can be found here: // R. Hartley, A. Zisserman, Multiple View Geometry in Computer Vision, 2004, section 5.1.3, page 134 // see the discussion for more details: https://github.com/opencv/opencv/pull/22992 - sigma_x *= sqrt(2.0 * (double)ex.total()/(2.0 * (double)ex.total() - nParams)); + sigma_x *= std::sqrt(2.0 * (double)ex.total()/(2.0 * (double)ex.total() - nParams)); errors = 3 * sigma_x(0) * JJ2.diag(); - rms = sqrt(norm(ex, NORM_L2SQR)/ex.total()); + rms = std::sqrt(norm(ex, NORM_L2SQR)/ex.total()); } void cv::internal::dAB(InputArray A, InputArray B, OutputArray dABdA, OutputArray dABdB) diff --git a/modules/calib/src/multiview_calibration.cpp b/modules/calib/src/multiview_calibration.cpp index 56117cd521..fc3185ba1e 100644 --- a/modules/calib/src/multiview_calibration.cpp +++ b/modules/calib/src/multiview_calibration.cpp @@ -39,7 +39,7 @@ public: // err > 0 float getError(float err) const override { - return exp(minvScale * err); + return std::exp(minvScale * err); } }; #endif @@ -233,7 +233,7 @@ static void thresholdPatternCameraAngles (int NUM_PATTERN_PTS, double THR_PATTER pattern1 = p1; pattern2 = p2; pattern3 = p3; - norm_normal = sqrt(norm_normal); + norm_normal = std::sqrt(norm_normal); break; } } @@ -255,7 +255,7 @@ static void thresholdPatternCameraAngles (int NUM_PATTERN_PTS, double THR_PATTER Rodrigues(rvecs_all[c][f], R); opt_axes[c][f] = Vec3d(Mat(R.row(2))); const double angle = acos(opt_axes[c][f].dot(pattern_normal)); - is_valid_angle2pattern[c][f] = min(M_PI-angle, angle) < THR_PATTERN_CAMERA_ANGLES; + is_valid_angle2pattern[c][f] = std::min(M_PI-angle, angle) < THR_PATTERN_CAMERA_ANGLES; } } } @@ -730,7 +730,7 @@ double calibrateMultiview( for (int f = 0; f < (int) obj_points_.size(); f++) { double err2 = multiview::computeReprojectionMSE(obj_points_[f], img_points_[f], K, dist, rvecs.row(f), tvecs.row(f), noArray(), noArray(), cv::CALIB_MODEL_FISHEYE); - errors_per_view[f] = sqrt(err2); + errors_per_view[f] = std::sqrt(err2); } } else { repr_err = calibrateCamera(obj_points_, img_points_, imageSize[camera], K, dist, @@ -962,7 +962,7 @@ double calibrateMultiview( const double err2 = multiview::computeReprojectionMSE(objPoints_norm[f] * scale_3d_pts, imagePoints[c][f], Ks_vec[c], distortions_vec[c], rvec0, tvec0, rvec, tvec, models_mat.at(c)); - (*errs_ptr++) = sqrt(err2); + (*errs_ptr++) = std::sqrt(err2); sum_errors += err2; cnt_errors += 1; } else (*errs_ptr++) = -1.0; @@ -973,7 +973,7 @@ double calibrateMultiview( errs.copyTo(perFrameErrors); } - return sqrt(sum_errors / cnt_errors); + return std::sqrt(sum_errors / cnt_errors); } double calibrateMultiview( diff --git a/modules/calib/test/test_fisheye.cpp b/modules/calib/test/test_fisheye.cpp index 38ab5d50ab..a67991acbc 100644 --- a/modules/calib/test/test_fisheye.cpp +++ b/modules/calib/test/test_fisheye.cpp @@ -505,7 +505,7 @@ TEST_F(fisheyeTest, Homography) fs_object.release(); cv::internal::IntrinsicParams param; - param.Init(cv::Vec2d(cv::max(imageSize.width, imageSize.height) / CV_PI, cv::max(imageSize.width, imageSize.height) / CV_PI), + param.Init(cv::Vec2d(std::max(imageSize.width, imageSize.height) / CV_PI, std::max(imageSize.width, imageSize.height) / CV_PI), cv::Vec2d(imageSize.width / 2.0 - 0.5, imageSize.height / 2.0 - 0.5)); cv::Mat _imagePoints (imagePoints[0]); diff --git a/modules/core/include/opencv2/core.hpp b/modules/core/include/opencv2/core.hpp index 4ea03963bc..95294a2a63 100644 --- a/modules/core/include/opencv2/core.hpp +++ b/modules/core/include/opencv2/core.hpp @@ -1649,14 +1649,6 @@ or array and a scalar: @sa max, compare, inRange, minMaxLoc */ CV_EXPORTS_W void min(InputArray src1, InputArray src2, OutputArray dst); -/** @overload -needed to avoid conflicts with const _Tp& std::min(const _Tp&, const _Tp&, _Compare) -*/ -CV_EXPORTS void min(const Mat& src1, const Mat& src2, Mat& dst); -/** @overload -needed to avoid conflicts with const _Tp& std::min(const _Tp&, const _Tp&, _Compare) -*/ -CV_EXPORTS void min(const UMat& src1, const UMat& src2, UMat& dst); /** @brief Calculates per-element maximum of two arrays or an array and a scalar. @@ -1670,14 +1662,6 @@ or array and a scalar: @sa min, compare, inRange, minMaxLoc, @ref MatrixExpressions */ CV_EXPORTS_W void max(InputArray src1, InputArray src2, OutputArray dst); -/** @overload -needed to avoid conflicts with const _Tp& std::min(const _Tp&, const _Tp&, _Compare) -*/ -CV_EXPORTS void max(const Mat& src1, const Mat& src2, Mat& dst); -/** @overload -needed to avoid conflicts with const _Tp& std::min(const _Tp&, const _Tp&, _Compare) -*/ -CV_EXPORTS void max(const UMat& src1, const UMat& src2, UMat& dst); /** @brief Calculates a square root of array elements. diff --git a/modules/core/include/opencv2/core/cvstd.hpp b/modules/core/include/opencv2/core/cvstd.hpp index f2e37b8e16..8c2025992b 100644 --- a/modules/core/include/opencv2/core/cvstd.hpp +++ b/modules/core/include/opencv2/core/cvstd.hpp @@ -68,14 +68,7 @@ namespace cv inline unsigned abs(unsigned a) { return a; } inline uint64 abs(uint64 a) { return a; } - using std::min; - using std::max; using std::abs; - using std::swap; - using std::sqrt; - using std::exp; - using std::pow; - using std::log; } #include "cvstd_wrapper.hpp" @@ -135,7 +128,7 @@ public: void construct(pointer p, const _Tp& v) { new(static_cast(p)) _Tp(v); } void destroy(pointer p) { p->~_Tp(); } - size_type max_size() const { return cv::max(static_cast<_Tp>(-1)/sizeof(_Tp), 1); } + size_type max_size() const { return std::max(static_cast<_Tp>(-1)/sizeof(_Tp), 1); } }; //! @} core_utils diff --git a/modules/core/include/opencv2/core/cvstd_wrapper.hpp b/modules/core/include/opencv2/core/cvstd_wrapper.hpp index 7720d87ea5..f1ecd2b9e3 100644 --- a/modules/core/include/opencv2/core/cvstd_wrapper.hpp +++ b/modules/core/include/opencv2/core/cvstd_wrapper.hpp @@ -7,14 +7,13 @@ #include "opencv2/core/cvdef.h" +#include // std::nullptr_t #include #include // std::shared_ptr #include // std::enable_if namespace cv { -using std::nullptr_t; - //! @addtogroup core_basic //! @{ @@ -71,9 +70,9 @@ struct Ptr : public std::shared_ptr using std::shared_ptr::shared_ptr; // GCC 5.x can't handle this #else inline Ptr() CV_NOEXCEPT : std::shared_ptr() {} - inline Ptr(nullptr_t) CV_NOEXCEPT : std::shared_ptr(nullptr) {} + inline Ptr(std::nullptr_t) CV_NOEXCEPT : std::shared_ptr(nullptr) {} template inline Ptr(Y* p, D d) : std::shared_ptr(p, d) {} - template inline Ptr(nullptr_t, D d) : std::shared_ptr(nullptr, d) {} + template inline Ptr(std::nullptr_t, D d) : std::shared_ptr(nullptr, d) {} template inline Ptr(const Ptr& r, T* ptr) CV_NOEXCEPT : std::shared_ptr(r, ptr) {} diff --git a/modules/core/include/opencv2/core/hal/intrin_avx512.hpp b/modules/core/include/opencv2/core/hal/intrin_avx512.hpp index 60943c9603..558edd667b 100644 --- a/modules/core/include/opencv2/core/hal/intrin_avx512.hpp +++ b/modules/core/include/opencv2/core/hal/intrin_avx512.hpp @@ -1177,11 +1177,11 @@ inline v_float64x8 v_reverse(const v_float64x8 &a) sctype CV_DECL_ALIGNED(64) idx[2]; \ _mm_store_si128((__m128i*)idx, _mm_##ifunc(_mm256_castsi256_si128(half), _mm256_extracti128_si256(half, 1))); \ return scop(idx[0], idx[1]); } -OPENCV_HAL_IMPL_AVX512_REDUCE_8(uint64, min, v_uint64x8, min_epu64, min) -OPENCV_HAL_IMPL_AVX512_REDUCE_8(uint64, max, v_uint64x8, max_epu64, max) +OPENCV_HAL_IMPL_AVX512_REDUCE_8(uint64, min, v_uint64x8, min_epu64, std::min) +OPENCV_HAL_IMPL_AVX512_REDUCE_8(uint64, max, v_uint64x8, max_epu64, std::max) OPENCV_HAL_IMPL_AVX512_REDUCE_8(uint64, sum, v_uint64x8, add_epi64, OPENCV_HAL_IMPL_AVX512_REDUCE_ADD64) -OPENCV_HAL_IMPL_AVX512_REDUCE_8(int64, min, v_int64x8, min_epi64, min) -OPENCV_HAL_IMPL_AVX512_REDUCE_8(int64, max, v_int64x8, max_epi64, max) +OPENCV_HAL_IMPL_AVX512_REDUCE_8(int64, min, v_int64x8, min_epi64, std::min) +OPENCV_HAL_IMPL_AVX512_REDUCE_8(int64, max, v_int64x8, max_epi64, std::max) OPENCV_HAL_IMPL_AVX512_REDUCE_8(int64, sum, v_int64x8, add_epi64, OPENCV_HAL_IMPL_AVX512_REDUCE_ADD64) #define OPENCV_HAL_IMPL_AVX512_REDUCE_8F(func, ifunc, scop) \ @@ -1190,8 +1190,8 @@ OPENCV_HAL_IMPL_AVX512_REDUCE_8(int64, sum, v_int64x8, add_epi64, OPENCV_HAL_I double CV_DECL_ALIGNED(64) idx[2]; \ _mm_store_pd(idx, _mm_##ifunc(_mm256_castpd256_pd128(half), _mm256_extractf128_pd(half, 1))); \ return scop(idx[0], idx[1]); } -OPENCV_HAL_IMPL_AVX512_REDUCE_8F(min, min_pd, min) -OPENCV_HAL_IMPL_AVX512_REDUCE_8F(max, max_pd, max) +OPENCV_HAL_IMPL_AVX512_REDUCE_8F(min, min_pd, std::min) +OPENCV_HAL_IMPL_AVX512_REDUCE_8F(max, max_pd, std::max) OPENCV_HAL_IMPL_AVX512_REDUCE_8F(sum, add_pd, OPENCV_HAL_IMPL_AVX512_REDUCE_ADD64) #define OPENCV_HAL_IMPL_AVX512_REDUCE_16(sctype, func, _Tpvec, ifunc) \ diff --git a/modules/core/src/arithm.cpp b/modules/core/src/arithm.cpp index 6c67d551f2..cf1fe95f9c 100644 --- a/modules/core/src/arithm.cpp +++ b/modules/core/src/arithm.cpp @@ -250,37 +250,6 @@ void cv::min( InputArray src1, InputArray src2, OutputArray dst ) arithm_op(ew::OP_MIN, src1, src2, dst, noArray(), -1, OCL_OP_MIN, false); } -// The concrete Mat/UMat overloads of min/max exist because C++ overload resolution needs them (a -// bare cv::min(mat, mat, mat) binds Mat& more tightly than InputArray); they must run the SAME engine -// path as the InputArray forms - NOT the legacy binary_op - so mixed types and broadcasting work. -void cv::max(const Mat& src1, const Mat& src2, Mat& dst) -{ - CV_INSTRUMENT_REGION(); - - arithm_op(ew::OP_MAX, src1, src2, dst, noArray(), -1, OCL_OP_MAX, false); -} - -void cv::min(const Mat& src1, const Mat& src2, Mat& dst) -{ - CV_INSTRUMENT_REGION(); - - arithm_op(ew::OP_MIN, src1, src2, dst, noArray(), -1, OCL_OP_MIN, false); -} - -void cv::max(const UMat& src1, const UMat& src2, UMat& dst) -{ - CV_INSTRUMENT_REGION(); - - arithm_op(ew::OP_MAX, src1, src2, dst, noArray(), -1, OCL_OP_MAX, false); -} - -void cv::min(const UMat& src1, const UMat& src2, UMat& dst) -{ - CV_INSTRUMENT_REGION(); - - arithm_op(ew::OP_MIN, src1, src2, dst, noArray(), -1, OCL_OP_MIN, false); -} - /****************************************************************************************\ * add/subtract * diff --git a/modules/core/src/dxt.cpp b/modules/core/src/dxt.cpp index 5fa92a4de0..448f884a22 100644 --- a/modules/core/src/dxt.cpp +++ b/modules/core/src/dxt.cpp @@ -1754,7 +1754,7 @@ private: radixes.push_back(radix); blocks.push_back(block); - min_radix = min(min_radix, block*radix); + min_radix = std::min(min_radix, block*radix); n *= radix; } factor_index++; @@ -1780,7 +1780,7 @@ private: } radixes.push_back(radix); blocks.push_back(block); - min_radix = min(min_radix, block*radix); + min_radix = std::min(min_radix, block*radix); } } diff --git a/modules/core/src/mathfuncs.cpp b/modules/core/src/mathfuncs.cpp index b3cd3b017c..c7380f23b8 100644 --- a/modules/core/src/mathfuncs.cpp +++ b/modules/core/src/mathfuncs.cpp @@ -1518,8 +1518,8 @@ int cv::solveCubic( InputArray _coeffs, OutputArray _roots ) if( d > 0 ) { - double theta = acos(R / sqrt(Qcubed)); - double sqrtQ = sqrt(Q); + double theta = acos(R / std::sqrt(Qcubed)); + double sqrtQ = std::sqrt(Q); double t0 = -2 * sqrtQ; double t1 = theta * (1./3); double t2 = a1 * (1./3); @@ -1539,7 +1539,7 @@ int cv::solveCubic( InputArray _coeffs, OutputArray _roots ) else { double e; - d = sqrt(-d); + d = std::sqrt(-d); e = std::cbrt(d + fabs(R)); if( R > 0 ) e = -e; @@ -1620,9 +1620,9 @@ double cv::solvePoly( InputArray _coeffs0, OutputArray _roots0, int maxIters ) if( coeff > DBL_EPSILON ) { if( i != n ) - u.at(i) = 2.0 * pow(coeff / absCoeffs.at(n), 1.0 / (n - i)); + u.at(i) = 2.0 * std::pow(coeff / absCoeffs.at(n), 1.0 / (n - i)); if( i != 0 ) - v.at(i - 1) = 0.5 * pow(absCoeffs.at(0) / coeff, 1.0 / i); + v.at(i - 1) = 0.5 * std::pow(absCoeffs.at(0) / coeff, 1.0 / i); nonZeroCoeffs++; } } @@ -1675,14 +1675,14 @@ double cv::solvePoly( InputArray _coeffs0, OutputArray _roots0, int maxIters ) for( j = 0; j < square_root_times; j++) { num.re = old_num_re*old_num_re + old_num_im*old_num_im; - num.re = sqrt(num.re); + num.re = std::sqrt(num.re); num.re += old_num_re; num.im = num.re - old_num_re; num.re /= 2; - num.re = sqrt(num.re); + num.re = std::sqrt(num.re); num.im /= 2; - num.im = sqrt(num.im); + num.im = std::sqrt(num.im); if( old_num_re < 0 ) num.im = -num.im; } @@ -1696,7 +1696,7 @@ double cv::solvePoly( InputArray _coeffs0, OutputArray _roots0, int maxIters ) solveCubic(cube_coefs, cube_roots); num.re = std::cbrt(cube_roots.at(0)); - num.im = sqrt(std::pow(num.re, 2) / 3 - old_num_re / (3*num.re)); + num.im = std::sqrt(std::pow(num.re, 2) / 3 - old_num_re / (3*num.re)); } } roots[i] = p - num; diff --git a/modules/core/src/matrix_operations.cpp b/modules/core/src/matrix_operations.cpp index 9de1bc661a..eb1bf318c1 100644 --- a/modules/core/src/matrix_operations.cpp +++ b/modules/core/src/matrix_operations.cpp @@ -716,7 +716,7 @@ static bool ocl_reduce(InputArray _src, OutputArray _dst, if (defDev.isIntel()) { static const size_t maxItemInGroupCount = 16; - tileHeight = min(tileHeight, defDev.localMemSize() / buf_cols / CV_ELEM_SIZE(CV_MAKETYPE(wdepth, cn)) / maxItemInGroupCount); + tileHeight = std::min(tileHeight, defDev.localMemSize() / buf_cols / CV_ELEM_SIZE(CV_MAKETYPE(wdepth, cn)) / maxItemInGroupCount); } char cvt[3][50]; cv::String build_opt = format("-D OP_REDUCE_PRE -D BUF_COLS=%d -D TILE_HEIGHT=%zu -D %s -D dim=1" diff --git a/modules/core/src/mean.simd.hpp b/modules/core/src/mean.simd.hpp index 96764c2437..abc6b13ad7 100644 --- a/modules/core/src/mean.simd.hpp +++ b/modules/core/src/mean.simd.hpp @@ -77,7 +77,7 @@ struct SumSqr_SIMD const int len0 = len & -VTraits::vlanes(); while(x < len0) { - const int len_tmp = min(x + 256*VTraits::vlanes(), len0); + const int len_tmp = std::min(x + 256*VTraits::vlanes(), len0); v_uint16 v_sum16 = vx_setzero_u16(); for ( ; x < len_tmp; x += VTraits::vlanes()) { @@ -169,7 +169,7 @@ struct SumSqr_SIMD const int len0 = len & -VTraits::vlanes(); while (x < len0) { - const int len_tmp = min(x + 256 * VTraits::vlanes(), len0); + const int len_tmp = std::min(x + 256 * VTraits::vlanes(), len0); v_int16 v_sum16 = vx_setzero_s16(); for (; x < len_tmp; x += VTraits::vlanes()) { diff --git a/modules/core/src/parallel.cpp b/modules/core/src/parallel.cpp index b87aba828d..0b9b31f61a 100644 --- a/modules/core/src/parallel.cpp +++ b/modules/core/src/parallel.cpp @@ -933,7 +933,7 @@ unsigned getNumberOfCPUsCFSv2() if (ss_cpu_max.fail() || cfs_quota < 1 || cfs_period < 1) /* values must not be 0 or negative */ return 0; - return (unsigned)max(1, cfs_quota/cfs_period); + return (unsigned)std::max(1, cfs_quota/cfs_period); } static inline @@ -957,7 +957,7 @@ unsigned getNumberOfCPUsCFSv1() return 0; } - return (unsigned)max(1, cfs_quota/cfs_period); + return (unsigned)std::max(1, cfs_quota/cfs_period); } #endif diff --git a/modules/core/src/types.cpp b/modules/core/src/types.cpp index 3a1b5a06ce..8255606dea 100644 --- a/modules/core/src/types.cpp +++ b/modules/core/src/types.cpp @@ -153,7 +153,7 @@ RotatedRect::RotatedRect(const Point2f& _point1, const Point2f& _point2, const P Vec2f vecs[2]; vecs[0] = Vec2f(_point1 - _point2); vecs[1] = Vec2f(_point2 - _point3); - double x = std::max(norm(_point1), std::max(norm(_point2), norm(_point3))); + double x = std::max({norm(_point1), norm(_point2), norm(_point3)}); double a = std::min(norm(vecs[0]), norm(vecs[1])); // check that given sides are perpendicular CV_Assert( std::fabs(vecs[0].ddot(vecs[1])) * a <= FLT_EPSILON * 9 * x * (norm(vecs[0]) * norm(vecs[1])) ); @@ -202,10 +202,10 @@ Rect RotatedRect::boundingRect() const { Point2f pt[4]; points(pt); - Rect r(cvFloor(std::min(std::min(std::min(pt[0].x, pt[1].x), pt[2].x), pt[3].x)), - cvFloor(std::min(std::min(std::min(pt[0].y, pt[1].y), pt[2].y), pt[3].y)), - cvCeil(std::max(std::max(std::max(pt[0].x, pt[1].x), pt[2].x), pt[3].x)), - cvCeil(std::max(std::max(std::max(pt[0].y, pt[1].y), pt[2].y), pt[3].y))); + Rect r(cvFloor(std::min({pt[0].x, pt[1].x, pt[2].x, pt[3].x})), + cvFloor(std::min({pt[0].y, pt[1].y, pt[2].y, pt[3].y})), + cvCeil(std::max({pt[0].x, pt[1].x, pt[2].x, pt[3].x})), + cvCeil(std::max({pt[0].y, pt[1].y, pt[2].y, pt[3].y}))); r.width -= r.x - 1; r.height -= r.y - 1; return r; @@ -216,8 +216,8 @@ Rect_ RotatedRect::boundingRect2f() const { Point2f pt[4]; points(pt); - Rect_ r(Point_(min(min(min(pt[0].x, pt[1].x), pt[2].x), pt[3].x), min(min(min(pt[0].y, pt[1].y), pt[2].y), pt[3].y)), - Point_(max(max(max(pt[0].x, pt[1].x), pt[2].x), pt[3].x), max(max(max(pt[0].y, pt[1].y), pt[2].y), pt[3].y))); + Rect_ r(Point_(std::min({pt[0].x, pt[1].x, pt[2].x, pt[3].x}), std::min({pt[0].y, pt[1].y, pt[2].y, pt[3].y})), + Point_(std::max({pt[0].x, pt[1].x, pt[2].x, pt[3].x}), std::max({pt[0].y, pt[1].y, pt[2].y, pt[3].y}))); return r; } diff --git a/modules/core/test/test_arithm.cpp b/modules/core/test/test_arithm.cpp index 8be85bf58f..36c35b16e0 100644 --- a/modules/core/test/test_arithm.cpp +++ b/modules/core/test/test_arithm.cpp @@ -5502,4 +5502,15 @@ INSTANTIATE_TEST_CASE_P(/**/, Core_CompareBool_nonCanonical, INSTANTIATE_TEST_CASE_P(/**/, Core_CompareBool_scalarAgreement, testing::Values(CMP_EQ, CMP_NE, CMP_GT, CMP_GE, CMP_LT, CMP_LE)); +TEST(SanityTest, MinMat) { + cv::Mat1b a(2, 2, uchar{10}); + cv::Mat1b b(2, 2, uchar{20}); + cv::Mat dst; + cv::min(a, b, dst); + EXPECT_EQ(dst.at(0, 0), 10); + + cv::Mat roi_dst(4, 4, CV_8UC1, cv::Scalar(0)); + cv::min(cv::Mat(a), cv::Mat(b), roi_dst(cv::Rect(0, 0, 2, 2))); + EXPECT_EQ(roi_dst.at(0, 0), 10); +} }} // namespace diff --git a/modules/core/test/test_operations.cpp b/modules/core/test/test_operations.cpp index e2f39d3e6b..30fe8c6078 100644 --- a/modules/core/test/test_operations.cpp +++ b/modules/core/test/test_operations.cpp @@ -126,7 +126,7 @@ bool CV_OperationsTest::TestMat() Mat shi_2x1(2, 1, CV_32F, Scalar(-1)); Scalar shift = Scalar::all(15); - float data[] = { sqrt(2.f)/2, -sqrt(2.f)/2, 1.f, sqrt(2.f)/2, sqrt(2.f)/2, 10.f }; + float data[] = { std::sqrt(2.f)/2, -std::sqrt(2.f)/2, 1.f, std::sqrt(2.f)/2, std::sqrt(2.f)/2, 10.f }; Mat rot_2x3(2, 3, CV_32F, data); Mat res = one_3x1 + shi_3x1 + shi_3x1 + shi_3x1; @@ -497,7 +497,7 @@ bool CV_OperationsTest::TestTemplateMat() Mat_ shi_2x1(2, 1, -2); Scalar shift = Scalar::all(15); - float data[] = { sqrt(2.f)/2, -sqrt(2.f)/2, 1.f, sqrt(2.f)/2, sqrt(2.f)/2, 10.f }; + float data[] = { std::sqrt(2.f)/2, -std::sqrt(2.f)/2, 1.f, std::sqrt(2.f)/2, std::sqrt(2.f)/2, 10.f }; Mat_ rot_2x3(2, 3, data); Mat_ res = Mat(Mat(2 * rot_2x3) * Mat(one_3x1 + shi_3x1 + shi_3x1 + shi_3x1) - shi_2x1) + shift; diff --git a/modules/dnn/src/cuda/reduce.cu b/modules/dnn/src/cuda/reduce.cu index b97a55f1a8..b2d6a0a312 100644 --- a/modules/dnn/src/cuda/reduce.cu +++ b/modules/dnn/src/cuda/reduce.cu @@ -382,7 +382,7 @@ namespace cv { namespace dnn { namespace cuda4dnn { namespace kernels { template static __device__ __forceinline__ void Accumulate(TAccum& acc, T, TAccum value, const TAccum&) { acc += value * value; } template - static __device__ __forceinline__ TAccum Finalize(TAccum acc, const TAccum&) { return sqrt(acc); } + static __device__ __forceinline__ TAccum Finalize(TAccum acc, const TAccum&) { return std::sqrt(acc); } }; template <> @@ -398,15 +398,15 @@ namespace cv { namespace dnn { namespace cuda4dnn { namespace kernels { template static __device__ __forceinline__ void Accumulate(TAccum& acc, T, TAccum value, const TAccum&) { acc += value; } template - static __device__ __forceinline__ TAccum Finalize(TAccum acc, const TAccum&) { return log(acc); } + static __device__ __forceinline__ TAccum Finalize(TAccum acc, const TAccum&) { return std::log(acc); } }; template <> struct GenericReduceStep { template - static __device__ __forceinline__ void Accumulate(TAccum& acc, T, TAccum value, const TAccum& shared_max) { acc += exp(value - shared_max); } + static __device__ __forceinline__ void Accumulate(TAccum& acc, T, TAccum value, const TAccum& shared_max) { acc += std::exp(value - shared_max); } template - static __device__ __forceinline__ TAccum Finalize(TAccum acc, const TAccum& shared_max) { return log(acc) + shared_max; } + static __device__ __forceinline__ TAccum Finalize(TAccum acc, const TAccum& shared_max) { return std::log(acc) + shared_max; } }; template diff --git a/modules/dnn/src/int8layers/convolution_layer.cpp b/modules/dnn/src/int8layers/convolution_layer.cpp index e6b57f6de3..36e8d85644 100644 --- a/modules/dnn/src/int8layers/convolution_layer.cpp +++ b/modules/dnn/src/int8layers/convolution_layer.cpp @@ -914,7 +914,7 @@ public: // for now only 3x3 depth-wise convolutions are supported depthWiseConvolution = depthWiseConvolution && kernel_w == 3 && kernel_h == 3 && // computing at most 1 pixel from each side can involve padding - max(stride_w, dilation_w) >= pad_l && max(stride_h, dilation_h) >= pad_t && + std::max(stride_w, dilation_w) >= pad_l && std::max(stride_h, dilation_h) >= pad_t && pad_l <= 1 && pad_t <= 1; if( !depthWiseConvolution && nstripes >= batchSize*2 ) @@ -942,13 +942,13 @@ public: int* data_out0_ = output_->ptr(); int8_t* rowbuf0 = 0; bool use_rowbuf = !depthWiseConvolution; - int blk_size = depthWiseConvolution ? outPlaneSize : min((int)BLK_SIZE, stripeSize); + int blk_size = depthWiseConvolution ? outPlaneSize : std::min((int)BLK_SIZE, stripeSize); // im2row buffer is not used for depth-wise convolution // Use thread_local to avoid repeated allocation across layers if(use_rowbuf) { - size_t rowbufsz = alignSize(karea*blk_size_cn, valign)*min((int)BLK_SIZE, blk_size); + size_t rowbufsz = alignSize(karea*blk_size_cn, valign)*std::min((int)BLK_SIZE, blk_size); thread_local AutoBuffer rowbuf0_tls; rowbuf0_tls.allocate(rowbufsz + valign); rowbuf0 = alignPtr(rowbuf0_tls.data(), (int)(valign*sizeof(int8_t))); @@ -1024,7 +1024,7 @@ public: const int8_t w00_ = wptr[0], w01_ = wptr[1], w02_ = wptr[2], w10 = wptr[3], w11 = wptr[4], w12 = wptr[5], w20_ = wptr[6], w21_ = wptr[7], w22_ = wptr[8]; - int outW1 = min(outW, (width - dilation_w*(kernel_w - 1) + pad_l)/stride_w); + int outW1 = std::min(outW, (width - dilation_w*(kernel_w - 1) + pad_l)/stride_w); int bias = biasptr[out_d], biasCopy; float mult = multptr[out_d]; @@ -1062,7 +1062,7 @@ public: (int)imgptr2[0]*w21 + (int)imgptr2[dilation_w]*w22 + biasCopy + inpZp*(w00 + w10 + w20); out1 = outZp + (int)std::round(out*mult); - outptr[0] = std::min(std::max(out1, -128), 127); + outptr[0] = std::clamp(out1, -128, 127); out_j = 1; } #if CV_SIMD128 @@ -1129,7 +1129,7 @@ public: (int)imgptr1[in_j]*w10 + (int)imgptr1[in_j + dilation_w]*w11 + (int)imgptr1[in_j + dilation_w*2]*w12 + (int)imgptr2[in_j]*w20 + (int)imgptr2[in_j + dilation_w]*w21 + (int)imgptr2[in_j + dilation_w*2]*w22 + biasCopy; out1 = outZp + (int)std::round(out*mult); - outptr[out_j] = std::min(std::max(out1, -128), 127); + outptr[out_j] = std::clamp(out1, -128, 127); } for (; out_j < outW; out_j++ ) @@ -1158,7 +1158,7 @@ public: (int)imgptr1[in_j0]*w10*s0 + (int)imgptr1[in_j1]*w11*s1 + (int)imgptr1[in_j2]*w12*s2 + (int)imgptr2[in_j0]*w20*s0 + (int)imgptr2[in_j1]*w21*s1 + (int)imgptr2[in_j2]*w22*s2 + biasCopy; out1 = outZp + (int)std::round(out*mult); - outptr[out_j] = std::min(std::max(out1, -128), 127); + outptr[out_j] = std::clamp(out1, -128, 127); } } } @@ -1513,8 +1513,8 @@ public: int out0 = outZp + (int)std::round(s00*mult0); int out1 = outZp + (int)std::round(s10*mult1); - s00 = std::min(std::max(out0, -128), 127); - s10 = std::min(std::max(out1, -128), 127); + s00 = std::clamp(out0, -128, 127); + s10 = std::clamp(out1, -128, 127); } outptr0[j] = s00; @@ -1552,7 +1552,7 @@ public: } #endif for( ; j < len; j++ ) - dst[j] = (uint8_t)std::min(std::max(src[j] + 128, 0), 255); + dst[j] = (uint8_t)std::clamp(src[j] + 128, 0, 255); } } } diff --git a/modules/dnn/src/int8layers/layers_common.simd.hpp b/modules/dnn/src/int8layers/layers_common.simd.hpp index 21d2be1cb4..d485ba7d6a 100644 --- a/modules/dnn/src/int8layers/layers_common.simd.hpp +++ b/modules/dnn/src/int8layers/layers_common.simd.hpp @@ -376,7 +376,7 @@ void fastDepthwiseConv( const int8_t* wptr, const int8_t w00_ = wptr[0], w01_ = wptr[1], w02_ = wptr[2], w10 = wptr[3], w11 = wptr[4], w12 = wptr[5], w20_ = wptr[6], w21_ = wptr[7], w22_ = wptr[8]; - int outW1 = min(outW, (width - dilation_w*(kernel_w - 1) + pad_l)/stride_w); + int outW1 = std::min(outW, (width - dilation_w*(kernel_w - 1) + pad_l)/stride_w); float mult = multptr[out_d]; int bias = biasptr[out_d]; int biasCopy; @@ -973,7 +973,7 @@ void fastDepthwiseConv( const int8_t* wptr, const int8_t w00_ = wptr[0], w01_ = wptr[1], w02_ = wptr[2], w10 = wptr[3], w11 = wptr[4], w12 = wptr[5], w20_ = wptr[6], w21_ = wptr[7], w22_ = wptr[8]; - int outW1 = min(outW, (width - dilation_w*(kernel_w - 1) + pad_l)/stride_w); + int outW1 = std::min(outW, (width - dilation_w*(kernel_w - 1) + pad_l)/stride_w); float mult = multptr[out_d]; int bias = biasptr[out_d]; int biasCopy; diff --git a/modules/dnn/src/int8layers/layers_rvp052.cpp b/modules/dnn/src/int8layers/layers_rvp052.cpp index 628882a43f..6bed34c42f 100644 --- a/modules/dnn/src/int8layers/layers_rvp052.cpp +++ b/modules/dnn/src/int8layers/layers_rvp052.cpp @@ -78,7 +78,7 @@ void fastDepthwiseConv(const int8_t *wptr, const int8_t w00_ = wptr[0], w01_ = wptr[1], w02_ = wptr[2], w10 = wptr[3], w11 = wptr[4], w12 = wptr[5], w20_ = wptr[6], w21_ = wptr[7], w22_ = wptr[8]; - int outW1 = min(outW, (width - dilation_w * (kernel_w - 1) + pad_l) / stride_w); + int outW1 = std::min(outW, (width - dilation_w * (kernel_w - 1) + pad_l) / stride_w); int bias = biasptr[out_d], biasCopy; float mult = multptr[out_d]; diff --git a/modules/dnn/src/int8layers/pooling_layer.cpp b/modules/dnn/src/int8layers/pooling_layer.cpp index fa4ae2cb5f..2ab26d7566 100644 --- a/modules/dnn/src/int8layers/pooling_layer.cpp +++ b/modules/dnn/src/int8layers/pooling_layer.cpp @@ -12,8 +12,6 @@ #include #include -using std::max; -using std::min; namespace cv { @@ -495,18 +493,18 @@ public: const int8_t *srcData = 0; int pad_d_begin = (pads_begin.size() == 3) ? pads_begin[0] : 0; dstart = d0 * stride_d - pad_d_begin; - dend = min(dstart + kernel_d, (int)(inp_depth + pads_end[0])); + dend = std::min(dstart + kernel_d, (int)(inp_depth + pads_end[0])); ystart = y0 * stride_h - pad_t; - yend = min(ystart + kernel_h, inp_height + pad_b); + yend = std::min(ystart + kernel_h, inp_height + pad_b); srcData = src->ptr(n, c); int ddelta = dend - dstart; - dstart = max(dstart, 0); - dend = min(dend, inp_depth); + dstart = std::max(dstart, 0); + dend = std::min(dend, inp_depth); int ydelta = yend - ystart; - ystart = max(ystart, 0); - yend = min(yend, inp_height); + ystart = std::max(ystart, 0); + yend = std::min(yend, inp_height); int8_t *dstData = &dst->ptr(n, c, d0)[y0 * width]; int delta = std::min((int)(stripeEnd - ofs0), width - x0); @@ -517,8 +515,8 @@ public: for( ; x0 < x1; x0++ ) { int xstart = x0 * stride_w - pad_l; - int xend = min(xstart + kernel_w, inp_width); - xstart = max(xstart, 0); + int xend = std::min(xstart + kernel_w, inp_width); + xstart = std::max(xstart, 0); if (xstart >= xend || ystart >= yend) { dstData[x0] = (int8_t)outZp; @@ -615,10 +613,10 @@ public: for( ; x0 < x1; ++x0) { int xstart = x0 * stride_w - pad_l; - int xend = min(xstart + kernel_w, inp_width + pad_r); + int xend = std::min(xstart + kernel_w, inp_width + pad_r); int xdelta = xend - xstart; - xstart = max(xstart, 0); - xend = min(xend, inp_width); + xstart = std::max(xstart, 0); + xend = std::min(xend, inp_width); int real_kernel_area = (dend - dstart) * (yend - ystart) * (xend - xstart); int padded_kernel_area = xdelta * ydelta * ddelta; diff --git a/modules/dnn/src/layers/attention_layer.cpp b/modules/dnn/src/layers/attention_layer.cpp index 7fb145358d..26132a3a82 100644 --- a/modules/dnn/src/layers/attention_layer.cpp +++ b/modules/dnn/src/layers/attention_layer.cpp @@ -153,7 +153,7 @@ class AttentionLayerImpl CV_FINAL : public AttentionLayer { qkv_head_sizes[0] = static_cast(qkv_hidden_sizes[0] / num_heads); qkv_head_sizes[1] = static_cast(qkv_hidden_sizes[1] / num_heads); - scale = 1.f / params.get("scale", sqrt(qkv_head_sizes[0])); + scale = 1.f / params.get("scale", std::sqrt(qkv_head_sizes[0])); output_ndims = params.get("output_ndims", 3); diff --git a/modules/dnn/src/layers/batch_norm_layer.cpp b/modules/dnn/src/layers/batch_norm_layer.cpp index 5219c599f4..66dcd43e2e 100644 --- a/modules/dnn/src/layers/batch_norm_layer.cpp +++ b/modules/dnn/src/layers/batch_norm_layer.cpp @@ -104,7 +104,7 @@ public: for (size_t i = 0; i < n; ++i) { - float w = (hasWeights ? weightsData[i] : 1.0f) / sqrt(stdData[i] * varMeanScale + epsilon); + float w = (hasWeights ? weightsData[i] : 1.0f) / std::sqrt(stdData[i] * varMeanScale + epsilon); dstWeightsData[i] = w; dstBiasData[i] = (hasBias ? biasData[i] : 0.0f) - w * meanData[i] * varMeanScale; } diff --git a/modules/dnn/src/layers/cpu_kernels/conv_depthwise.cpp b/modules/dnn/src/layers/cpu_kernels/conv_depthwise.cpp index bfaf431d06..0cb162eb0c 100644 --- a/modules/dnn/src/layers/cpu_kernels/conv_depthwise.cpp +++ b/modules/dnn/src/layers/cpu_kernels/conv_depthwise.cpp @@ -156,7 +156,7 @@ void depthWiseBlockConv2D(const float* wptr, const float w00_ = wptr[0], w01_ = wptr[1], w02_ = wptr[2], w10 = wptr[3], w11 = wptr[4], w12 = wptr[5], w20_ = wptr[6], w21_ = wptr[7], w22_ = wptr[8]; - const int outW1 = min(outW, (width - dilation_w*(kernel_w - 1) + pad_l)/stride_w); + const int outW1 = std::min(outW, (width - dilation_w*(kernel_w - 1) + pad_l)/stride_w); float relu_coeff = relu ? relu[out_d] : 1.f, bias = biasptr[out_d]; for (int out_i = 0; out_i < outH; out_i++) @@ -330,7 +330,7 @@ void depthWiseBlockConv1D(const float* wptr, int out_d, int outW, bool fusedAdd) { const float w00_ = wptr[0], w01_ = wptr[1], w02_ = wptr[2]; - const int outW1 = min(outW, (width - dilation_w * (kernel_w - 1) + pad_l)/stride_w); + const int outW1 = std::min(outW, (width - dilation_w * (kernel_w - 1) + pad_l)/stride_w); float relu_coeff = relu ? relu[out_d] : 1.f, bias = biasptr[out_d]; int out_j = 0; diff --git a/modules/dnn/src/layers/cpu_kernels/conv_depthwise.simd.hpp b/modules/dnn/src/layers/cpu_kernels/conv_depthwise.simd.hpp index bd5dec0cb1..925a47be35 100644 --- a/modules/dnn/src/layers/cpu_kernels/conv_depthwise.simd.hpp +++ b/modules/dnn/src/layers/cpu_kernels/conv_depthwise.simd.hpp @@ -51,7 +51,7 @@ void fastDepthwiseConv( const float* wptr, const float w00_ = wptr[0], w01_ = wptr[1], w02_ = wptr[2], w10 = wptr[3], w11 = wptr[4], w12 = wptr[5], w20_ = wptr[6], w21_ = wptr[7], w22_ = wptr[8]; - int outW1 = min(outW, (width - dilation_w*(kernel_w - 1) + pad_l)/stride_w); + int outW1 = std::min(outW, (width - dilation_w*(kernel_w - 1) + pad_l)/stride_w); float relu_coeff = relu ? relu[out_d] : 1.f, bias = biasptr[out_d]; for (int out_i = 0; out_i < outH; out_i++) @@ -379,7 +379,7 @@ void fastDepthwiseConv( const float* wptr, const float w00_ = wptr[0], w01_ = wptr[1], w02_ = wptr[2], w10 = wptr[3], w11 = wptr[4], w12 = wptr[5], w20_ = wptr[6], w21_ = wptr[7], w22_ = wptr[8]; - int outW1 = min(outW, (width - dilation_w*(kernel_w - 1) + pad_l)/stride_w); + int outW1 = std::min(outW, (width - dilation_w*(kernel_w - 1) + pad_l)/stride_w); float relu_coeff = relu ? relu[out_d] : 1.f, bias = biasptr[out_d]; for (int out_i = 0; out_i < outH; out_i++) diff --git a/modules/dnn/src/layers/cpu_kernels/convolution.cpp b/modules/dnn/src/layers/cpu_kernels/convolution.cpp index e4f086e48f..49597bf5b0 100644 --- a/modules/dnn/src/layers/cpu_kernels/convolution.cpp +++ b/modules/dnn/src/layers/cpu_kernels/convolution.cpp @@ -147,12 +147,12 @@ Ptr initFastConv( if (conv_dim == CONV_1D) { ifRunDepthWise &= Hk == 1 && Wk == 3 && (stride_w == 1 || (stride_w == 2 && dilation_w == 1)) - && max(stride_w, dilation_w) >= conv->pad_left && conv->pad_left <= 1; + && std::max(stride_w, dilation_w) >= conv->pad_left && conv->pad_left <= 1; } else if (conv_dim == CONV_2D) { ifRunDepthWise &= Hk == 3 && Wk == 3 && ((stride_w == 1) || (stride_w == 2 && dilation_w == 1)) && - max(stride_w, dilation_w) >= conv->pad_left && max(stride_h, dilation_h) >= conv->pad_top + std::max(stride_w, dilation_w) >= conv->pad_left && std::max(stride_h, dilation_h) >= conv->pad_top && conv->pad_left <= 1 && conv->pad_top <= 1; } @@ -361,7 +361,7 @@ Ptr initFastConv( { // The weights are packed as // ngroups x (ceil((K/ngroups)/CONV_MR)*CONV_MR) x (Cg*Hk*Wk*Dk) x CONV_MR tensor - int Kg = K/ngroups, Cg = max(C/ngroups, 1); + int Kg = K/ngroups, Cg = std::max(C/ngroups, 1); int DkHkWkCg = Dk*Hk*Wk*Cg; int numStripsMR = (Kg + CONV_MR_FP32 - 1) / CONV_MR_FP32; diff --git a/modules/dnn/src/layers/detection_output_layer.cpp b/modules/dnn/src/layers/detection_output_layer.cpp index 443fc99c47..19f94b1e5a 100644 --- a/modules/dnn/src/layers/detection_output_layer.cpp +++ b/modules/dnn/src/layers/detection_output_layer.cpp @@ -718,8 +718,8 @@ public: float decode_bbox_width, decode_bbox_height; decode_bbox_center_x = bbox_xmin * prior_width + prior_center_x; decode_bbox_center_y = bbox_ymin * prior_height + prior_center_y; - decode_bbox_width = exp(bbox_xmax) * prior_width; - decode_bbox_height = exp(bbox_ymax) * prior_height; + decode_bbox_width = std::exp(bbox_xmax) * prior_width; + decode_bbox_height = std::exp(bbox_ymax) * prior_height; decode_bbox.xmin = decode_bbox_center_x - decode_bbox_width * .5; decode_bbox.ymin = decode_bbox_center_y - decode_bbox_height * .5; decode_bbox.xmax = decode_bbox_center_x + decode_bbox_width * .5; diff --git a/modules/dnn/src/layers/elementwise_layers.cpp b/modules/dnn/src/layers/elementwise_layers.cpp index ffd9c2afef..f5a603d62d 100644 --- a/modules/dnn/src/layers/elementwise_layers.cpp +++ b/modules/dnn/src/layers/elementwise_layers.cpp @@ -77,13 +77,11 @@ using std::abs; using std::exp; using std::expm1; using std::tanh; -using std::pow; using std::ceil; using std::floor; using std::log; using std::log1p; using std::sqrt; -using std::round; using std::acos; using std::acosh; using std::asin; @@ -2622,7 +2620,7 @@ struct HardSwishFunctor : public BaseDefaultFunctor inline float calculate(float x) const { - return x * std::max(0.f, std::min(1.f, x / 6.f + 0.5f)); + return x * std::clamp(x / 6.f + 0.5f, 0.f, 1.f); } void apply(const float* srcptr, float* dstptr, int stripeStart, int len, size_t planeSize, int cn0, int cn1) const { @@ -3030,7 +3028,7 @@ struct HardSigmoidFunctor : public BaseDefaultFunctor inline float calculate(float x) const { - return max(0.f, min(1.f, alpha * x + beta)); + return std::clamp(alpha * x + beta, 0.f, 1.f); } inline void setKernelParams(ocl::Kernel& kernel) const diff --git a/modules/dnn/src/layers/pooling_layer.cpp b/modules/dnn/src/layers/pooling_layer.cpp index ba7bd3e20e..c9bdeb9b97 100644 --- a/modules/dnn/src/layers/pooling_layer.cpp +++ b/modules/dnn/src/layers/pooling_layer.cpp @@ -60,8 +60,6 @@ #include #include #include -using std::max; -using std::min; #ifdef HAVE_OPENCL #include "opencl_kernels_dnn.hpp" @@ -869,18 +867,18 @@ public: { int pad_d_begin = (pads_begin.size() == 3) ? pads_begin[0] : 0; dstart = d0 * stride_d - pad_d_begin; - dend = min(dstart + kernel_d, (int)(inp_depth + pads_end[0])); + dend = std::min(dstart + kernel_d, (int)(inp_depth + pads_end[0])); ystart = y0 * stride_h - pad_t; - yend = min(ystart + kernel_h, inp_height + pad_b); + yend = std::min(ystart + kernel_h, inp_height + pad_b); srcData = src->ptr(n, c); } int ddelta = dend - dstart; - dstart = max(dstart, 0); - dend = min(dend, inp_depth); + dstart = std::max(dstart, 0); + dend = std::min(dend, inp_depth); int ydelta = yend - ystart; - ystart = max(ystart, 0); - yend = min(yend, inp_height); + ystart = std::max(ystart, 0); + yend = std::min(yend, inp_height); float *dstData = &dst->ptr(n, c, d0)[y0 * width]; float *dstMaskData = mask->data ? &mask->ptr(n, c, d0)[y0 * width] : 0; @@ -892,8 +890,8 @@ public: for( ; x0 < x1; x0++ ) { int xstart = x0 * stride_w - pad_l; - int xend = min(xstart + kernel_w, inp_width); - xstart = max(xstart, 0); + int xend = std::min(xstart + kernel_w, inp_width); + xstart = std::max(xstart, 0); if (xstart >= xend || ystart >= yend) { dstData[x0] = 0; @@ -1060,10 +1058,10 @@ public: for( ; x0 < x1; ++x0) { int xstart = x0 * stride_w - pad_l; - int xend = min(xstart + kernel_w, inp_width + pad_r); + int xend = std::min(xstart + kernel_w, inp_width + pad_r); int xdelta = xend - xstart; - xstart = max(xstart, 0); - xend = min(xend, inp_width); + xstart = std::max(xstart, 0); + xend = std::min(xend, inp_width); float inv_kernel_area = avePoolPaddedArea ? xdelta * ydelta * ddelta : ((dend - dstart) * (yend - ystart) * (xend - xstart)); inv_kernel_area = poolingType == AVE ? 1.0 / inv_kernel_area : 1.0; @@ -1126,8 +1124,8 @@ public: { int xstart = xstartROI + x0 * roiRatio; int xend = xstartROI + std::ceil((x0 + 1) * roiRatio); - xstart = max(xstart, 0); - xend = min(xend, inp_width); + xstart = std::max(xstart, 0); + xend = std::min(xend, inp_width); if (xstart >= xend || ystart >= yend) { dstData[x0] = 0; @@ -1158,8 +1156,8 @@ public: { int xstart = (int)std::floor(xstartROI + x0 * roiRatio); int xend = (int)std::ceil(xstartROI + (x0 + 1) * roiRatio); - xstart = max(xstart, 0); - xend = min(xend, inp_width); + xstart = std::max(xstart, 0); + xend = std::min(xend, inp_width); if (xstart >= xend || ystart >= yend) { dstData[x0] = 0; diff --git a/modules/dnn/src/layers/prior_box_layer.cpp b/modules/dnn/src/layers/prior_box_layer.cpp index 8eafc13428..24b1b2f3f0 100644 --- a/modules/dnn/src/layers/prior_box_layer.cpp +++ b/modules/dnn/src/layers/prior_box_layer.cpp @@ -260,7 +260,7 @@ public: if (_maxSize.size() > 0) { - float size = sqrt(minSize * _maxSize[i]); + float size = std::sqrt(minSize * _maxSize[i]); _boxWidths.push_back(size); _boxHeights.push_back(size); } @@ -268,7 +268,7 @@ public: // rest of priors for (size_t r = 0; r < _aspectRatios.size(); ++r) { - float arSqrt = sqrt(_aspectRatios[r]); + float arSqrt = std::sqrt(_aspectRatios[r]); _boxWidths.push_back(minSize * arSqrt); _boxHeights.push_back(minSize / arSqrt); } @@ -496,7 +496,7 @@ public: outputPtr = outputs[0].ptr(); for (size_t d = 0; d < _outChannelSize; ++d) { - outputPtr[d] = std::min(std::max(outputPtr[d], 0.), 1.); + outputPtr[d] = std::clamp(outputPtr[d], 0.f, 1.f); } } // set the variance. diff --git a/modules/dnn/src/layers/proposal_layer.cpp b/modules/dnn/src/layers/proposal_layer.cpp index 5b655e796e..f98182f9d1 100644 --- a/modules/dnn/src/layers/proposal_layer.cpp +++ b/modules/dnn/src/layers/proposal_layer.cpp @@ -50,7 +50,7 @@ public: for (int i = 0; i < ratios.size(); ++i) { float ratio = ratios.get(i); - float width = std::floor(baseSize / sqrt(ratio) + 0.5f); + float width = std::floor(baseSize / std::sqrt(ratio) + 0.5f); float height = std::floor(width * ratio + 0.5f); for (int j = 0; j < scales.size(); ++j) { diff --git a/modules/dnn/src/layers/region_layer.cpp b/modules/dnn/src/layers/region_layer.cpp index fccc11e222..3040504c11 100644 --- a/modules/dnn/src/layers/region_layer.cpp +++ b/modules/dnn/src/layers/region_layer.cpp @@ -130,7 +130,7 @@ public: return backendId == DNN_BACKEND_OPENCV; } - float logistic_activate(float x) { return 1.F / (1.F + exp(-x)); } + float logistic_activate(float x) { return 1.F / (1.F + std::exp(-x)); } void softmax_activate(const float* input, const int n, const float temp, float* output) { @@ -141,7 +141,7 @@ public: if (input[i] > largest) largest = input[i]; } for (i = 0; i < n; ++i) { - float e = exp((input[i] - largest) / temp); + float e = std::exp((input[i] - largest) / temp); sum += e; output[i] = e; } @@ -335,8 +335,8 @@ public: float y_tmp = (logistic_activate(srcData[box_index + 1]) - 0.5f) * scale_x_y + 0.5f; dstData[box_index + 0] = (x + x_tmp) / cols; dstData[box_index + 1] = (y + y_tmp) / rows; - dstData[box_index + 2] = exp(srcData[box_index + 2]) * biasData[2 * a] / wNorm; - dstData[box_index + 3] = exp(srcData[box_index + 3]) * biasData[2 * a + 1] / hNorm; + dstData[box_index + 2] = std::exp(srcData[box_index + 2]) * biasData[2 * a] / wNorm; + dstData[box_index + 3] = std::exp(srcData[box_index + 3]) * biasData[2 * a + 1] / hNorm; int class_index = index_sample_offset + index * cell_size + 5; for (int j = 0; j < classes; ++j) { diff --git a/modules/dnn/src/layers/reverse_sequence_layer.cpp b/modules/dnn/src/layers/reverse_sequence_layer.cpp index f08915de90..606affd089 100644 --- a/modules/dnn/src/layers/reverse_sequence_layer.cpp +++ b/modules/dnn/src/layers/reverse_sequence_layer.cpp @@ -53,7 +53,7 @@ public: CV_Assert(inputs.size()==2); CV_CheckType(inputs[1], inputs[1]==CV_32S||inputs[1]==CV_64S, "ReverseSequence: sequence_lens must be int64 or int32"); - outputs.assign(max(1, requiredOutputs), inputs[0]); + outputs.assign(std::max(1, requiredOutputs), inputs[0]); } void forward(InputArrayOfArrays inputs_arr, OutputArrayOfArrays outputs_arr, diff --git a/modules/dnn/src/layers/split_layer.cpp b/modules/dnn/src/layers/split_layer.cpp index b7d3f44af8..36ba4dd6b2 100644 --- a/modules/dnn/src/layers/split_layer.cpp +++ b/modules/dnn/src/layers/split_layer.cpp @@ -87,7 +87,7 @@ public: { CV_Assert(inputs.size() == 1); - Layer::getMemoryShapes(inputs, max(1, outputsCount >= 0 ? outputsCount : requiredOutputs), + Layer::getMemoryShapes(inputs, std::max(1, outputsCount >= 0 ? outputsCount : requiredOutputs), outputs, internals); return false; } diff --git a/modules/dnn/src/layers/trilu_layer.cpp b/modules/dnn/src/layers/trilu_layer.cpp index f28f1f8f99..eaf02258ae 100644 --- a/modules/dnn/src/layers/trilu_layer.cpp +++ b/modules/dnn/src/layers/trilu_layer.cpp @@ -47,7 +47,7 @@ class TriluLayerImpl CV_FINAL : public TriluLayer { for(int l=0; l < h; l+=1) { int cmin = upperTri ? 0 : (l + k + 1); cmin = std::max(cmin, 0); - const int cmax = upperTri ? min(l + k -1, w-1) : w-1; + const int cmax = upperTri ? std::min(l + k -1, w-1) : w-1; const int num_zeros = cmax - cmin + 1; if (cmin < w && num_zeros > 0) { diff --git a/modules/dnn/src/nms.cpp b/modules/dnn/src/nms.cpp index 0104f37dc4..f07ae571bf 100644 --- a/modules/dnn/src/nms.cpp +++ b/modules/dnn/src/nms.cpp @@ -179,7 +179,7 @@ void softNMSBoxes(const std::vector& bboxes, } break; case SoftNMSMethod::SOFTNMS_GAUSSIAN: - bscore_i *= exp(-(overlap * overlap) / sigma); + bscore_i *= std::exp(-(overlap * overlap) / sigma); break; default: CV_Error(Error::StsBadArg, "Not supported SoftNMS method."); diff --git a/modules/dnn/src/tflite/tflite_importer.cpp b/modules/dnn/src/tflite/tflite_importer.cpp index cd82079e3e..e8e8b2eebf 100644 --- a/modules/dnn/src/tflite/tflite_importer.cpp +++ b/modules/dnn/src/tflite/tflite_importer.cpp @@ -1822,7 +1822,7 @@ void TFLiteImporter::parseActivation(const Operator& op, const std::string& opco else if (opcode == "LOGISTIC") y = 1.0f / (1.0f + std::exp(-x)); else if (opcode == "HARD_SWISH") - y = x * max(0.f, min(1.f, x / 6.f + 0.5f)); + y = x * std::clamp(x / 6.f + 0.5f, 0.f, 1.f); else if (opcode == "LEAKY_RELU") y = x >= 0.f ? x : slope*x; else diff --git a/modules/dnn/src/vkcom/src/op_conv.cpp b/modules/dnn/src/vkcom/src/op_conv.cpp index ed7fa7a823..86a38d020a 100644 --- a/modules/dnn/src/vkcom/src/op_conv.cpp +++ b/modules/dnn/src/vkcom/src/op_conv.cpp @@ -24,7 +24,7 @@ OpConv::OpConv(const Mat& weightBlob, const std::vector& biasvec, int _ac type_ = kOpTypeConv; CV_Assert(!weightBlob.empty()); - Kg = K/ngroups, Cg = max(C/ngroups, 1); + Kg = K/ngroups, Cg = std::max(C/ngroups, 1); ksize = Hk * Wk; CgHkWk = Cg * ksize; fast_1x1 = ksize == 1 && stride_w == 1 && stride_h == 1 && pad_top == 0 && pad_left == 0; diff --git a/modules/features/src/affine_feature.cpp b/modules/features/src/affine_feature.cpp index 798d20b382..e29abd8ed0 100644 --- a/modules/features/src/affine_feature.cpp +++ b/modules/features/src/affine_feature.cpp @@ -268,7 +268,7 @@ private: warpedImage = rotImage; else { - float s = 0.8f * sqrt(tilt * tilt - 1); + float s = 0.8f * std::sqrt(tilt * tilt - 1); GaussianBlur(rotImage, rotImage, Size(0, 0), s, 0.01); resize(rotImage, warpedImage, Size(0, 0), 1.0/tilt, 1.0, INTER_NEAREST); pose(0, 0) /= tilt; diff --git a/modules/features/src/orb.cpp b/modules/features/src/orb.cpp index ce4a72ddfa..08e78c1de6 100644 --- a/modules/features/src/orb.cpp +++ b/modules/features/src/orb.cpp @@ -1027,8 +1027,8 @@ void ORB_Impl::detectAndCompute( InputArray _image, InputArray _mask, const int HARRIS_BLOCK_SIZE = 9; int halfPatchSize = patchSize / 2; // sqrt(2.0) is for handling patch rotation - int descPatchSize = cvCeil(halfPatchSize*sqrt(2.0)); - int border = std::max(edgeThreshold, std::max(descPatchSize, HARRIS_BLOCK_SIZE/2))+1; + int descPatchSize = cvCeil(halfPatchSize*std::sqrt(2.0)); + int border = std::max({edgeThreshold, descPatchSize, HARRIS_BLOCK_SIZE/2})+1; #ifdef HAVE_OPENCL bool useOCL = ocl::isOpenCLActivated() && OCL_FORCE_CHECK(_image.isUMat() || _descriptors.isUMat()); diff --git a/modules/features/src/sift.dispatch.cpp b/modules/features/src/sift.dispatch.cpp index 01b6c6595f..2b963bd8ec 100644 --- a/modules/features/src/sift.dispatch.cpp +++ b/modules/features/src/sift.dispatch.cpp @@ -834,7 +834,7 @@ static bool ocl_computeSIFTDescriptors( const UMat& packed = gauss_packs[o]; int img_cols = packed.cols; int img_rows = packed.rows / levelsPerOctave; - float diag = sqrt((float)img_cols * img_cols + (float)img_rows * img_rows); + float diag = std::sqrt((float)img_cols * img_cols + (float)img_rows * img_rows); UMat kpts_roi = kpts_buf.rowRange(groups[o].start, groups[o].start + nGroup); diff --git a/modules/geometry/src/ap3p.cpp b/modules/geometry/src/ap3p.cpp index 3b66d06bc5..036bde2266 100644 --- a/modules/geometry/src/ap3p.cpp +++ b/modules/geometry/src/ap3p.cpp @@ -203,7 +203,7 @@ int ap3p::computePoses(const double featureVectors[3][4], double ctheta1p = s[i]; if (abs(ctheta1p) > 1) continue; - double stheta1p = sqrt(1 - ctheta1p * ctheta1p); + double stheta1p = std::sqrt(1 - ctheta1p * ctheta1p); stheta1p = (k3b3 > 0) ? stheta1p : -stheta1p; double ctheta3 = g1 * ctheta1p + g2; double stheta3 = g3 * ctheta1p + g4; @@ -361,21 +361,21 @@ int ap3p::solve(double R[4][3][3], double t[4][3], mu0 = inv_fx * mu0 - cx_fx; mv0 = inv_fy * mv0 - cy_fy; - norm = sqrt(mu0 * mu0 + mv0 * mv0 + 1); + norm = std::sqrt(mu0 * mu0 + mv0 * mv0 + 1); mk0 = 1. / norm; mu0 *= mk0; mv0 *= mk0; mu1 = inv_fx * mu1 - cx_fx; mv1 = inv_fy * mv1 - cy_fy; - norm = sqrt(mu1 * mu1 + mv1 * mv1 + 1); + norm = std::sqrt(mu1 * mu1 + mv1 * mv1 + 1); mk1 = 1. / norm; mu1 *= mk1; mv1 *= mk1; mu2 = inv_fx * mu2 - cx_fx; mv2 = inv_fy * mv2 - cy_fy; - norm = sqrt(mu2 * mu2 + mv2 * mv2 + 1); + norm = std::sqrt(mu2 * mu2 + mv2 * mv2 + 1); mk2 = 1. / norm; mu2 *= mk2; mv2 *= mk2; diff --git a/modules/geometry/src/epnp.cpp b/modules/geometry/src/epnp.cpp index 09bff11362..9cab547e02 100644 --- a/modules/geometry/src/epnp.cpp +++ b/modules/geometry/src/epnp.cpp @@ -79,7 +79,7 @@ void epnp::choose_control_points(void) transpose(UCt, UCt); for(int i = 1; i < 4; i++) { - double k = sqrt(dc[i - 1] / number_of_correspondences); + double k = std::sqrt(dc[i - 1] / number_of_correspondences); for(int j = 0; j < 3; j++) cws[i][j] = cws[0][j] + k * uct[3 * (i - 1) + j]; } @@ -320,7 +320,7 @@ double epnp::reprojection_error(const double R[3][3], const double t[3]) double ve = vc + fv * Yc * inv_Zc; double u = us[2 * i], v = us[2 * i + 1]; - sum2 += sqrt( (u - ue) * (u - ue) + (v - ve) * (v - ve) ); + sum2 += std::sqrt( (u - ue) * (u - ue) + (v - ve) * (v - ve) ); } return sum2 / number_of_correspondences; @@ -346,12 +346,12 @@ void epnp::find_betas_approx_1(const Mat& L_6x10, const Mat& Rho, double* betas) CV_Assert(B4.ptr() == b4); if (b4[0] < 0) { - betas[0] = sqrt(-b4[0]); + betas[0] = std::sqrt(-b4[0]); betas[1] = -b4[1] / betas[0]; betas[2] = -b4[2] / betas[0]; betas[3] = -b4[3] / betas[0]; } else { - betas[0] = sqrt(b4[0]); + betas[0] = std::sqrt(b4[0]); betas[1] = b4[1] / betas[0]; betas[2] = b4[2] / betas[0]; betas[3] = b4[3] / betas[0]; @@ -377,11 +377,11 @@ void epnp::find_betas_approx_2(const Mat& L_6x10, const Mat& Rho, double* betas) CV_Assert(B3.ptr() == b3); if (b3[0] < 0) { - betas[0] = sqrt(-b3[0]); - betas[1] = (b3[2] < 0) ? sqrt(-b3[2]) : 0.0; + betas[0] = std::sqrt(-b3[0]); + betas[1] = (b3[2] < 0) ? std::sqrt(-b3[2]) : 0.0; } else { - betas[0] = sqrt(b3[0]); - betas[1] = (b3[2] > 0) ? sqrt(b3[2]) : 0.0; + betas[0] = std::sqrt(b3[0]); + betas[1] = (b3[2] > 0) ? std::sqrt(b3[2]) : 0.0; } if (b3[1] < 0) betas[0] = -betas[0]; @@ -410,11 +410,11 @@ void epnp::find_betas_approx_3(const Mat& L_6x10, const Mat& Rho, double * betas CV_Assert(B5.ptr() == b5); if (b5[0] < 0) { - betas[0] = sqrt(-b5[0]); - betas[1] = (b5[2] < 0) ? sqrt(-b5[2]) : 0.0; + betas[0] = std::sqrt(-b5[0]); + betas[1] = (b5[2] < 0) ? std::sqrt(-b5[2]) : 0.0; } else { - betas[0] = sqrt(b5[0]); - betas[1] = (b5[2] > 0) ? sqrt(b5[2]) : 0.0; + betas[0] = std::sqrt(b5[0]); + betas[1] = (b5[2] > 0) ? std::sqrt(b5[2]) : 0.0; } if (b5[1] < 0) betas[0] = -betas[0]; betas[2] = b5[3] / betas[0]; @@ -563,7 +563,7 @@ void epnp::qr_solve(Mat& A, Mat& b, Mat& X) sum2 += *ppAik2 * *ppAik2; ppAik2 += nc; } - double sigma = sqrt(sum2); + double sigma = std::sqrt(sum2); if (*ppAkk < 0) sigma = -sigma; *ppAkk += sigma; diff --git a/modules/geometry/src/fisheye.cpp b/modules/geometry/src/fisheye.cpp index e52f20de70..2b2fee5f2f 100644 --- a/modules/geometry/src/fisheye.cpp +++ b/modules/geometry/src/fisheye.cpp @@ -501,12 +501,12 @@ void cv::fisheye::undistortPoints( InputArray distorted, OutputArray undistorted // (r^2 = a^2 + b^2) // x'^2 + y'^2 = theta_d^2 => // theta_d = sqrt(x'^2 + y'^2) - double theta_d = sqrt(pw[0]*pw[0] + pw[1]*pw[1]); + double theta_d = std::sqrt(pw[0]*pw[0] + pw[1]*pw[1]); // the current camera model is only valid up to 180 FOV // for larger FOV the loop below does not converge // clip values so we still get plausible results for super fisheye images > 180 grad - theta_d = min(max(-CV_PI/2., theta_d), CV_PI/2.); + theta_d = std::clamp(theta_d, -CV_PI/2., CV_PI/2.); bool converged = false; double theta = theta_d; @@ -578,7 +578,7 @@ void cv::fisheye::estimateNewCameraMatrixForUndistortRectify(InputArray K, Input CV_Assert(D.empty() || ((D.total() == 4) && (D.depth() == CV_32F || D.depth() == CV_64F))); int w = image_size.width, h = image_size.height; - balance = std::min(std::max(balance, 0.0), 1.0); + balance = std::clamp(balance, 0.0, 1.0); Mat points(1, 4, CV_64FC2); Vec2d* pptr = points.ptr(); @@ -613,8 +613,8 @@ void cv::fisheye::estimateNewCameraMatrixForUndistortRectify(InputArray K, Input double f3 = h * 0.5 * aspect_ratio/(cn[1] - miny); double f4 = h * 0.5 * aspect_ratio/(maxy - cn[1]); - double fmin = std::min(f1, std::min(f2, std::min(f3, f4))); - double fmax = std::max(f1, std::max(f2, std::max(f3, f4))); + double fmin = std::min({f1, f2, f3, f4}); + double fmax = std::max({f1, f2, f3, f4}); double f = balance * fmin + (1.0 - balance) * fmax; f *= fov_scale > 0 ? 1.0/fov_scale : 1.0; diff --git a/modules/geometry/src/homography_decomp.cpp b/modules/geometry/src/homography_decomp.cpp index 5f52e27c06..2597697d54 100644 --- a/modules/geometry/src/homography_decomp.cpp +++ b/modules/geometry/src/homography_decomp.cpp @@ -205,7 +205,7 @@ void HomographyDecompZhang::decompose(std::vector& camMotions) double lambda1t3 = lambda1*lambda3; double t1 = 1.0/(2.0*lambda1t3); - double t2 = sqrt(1.0+4.0*lambda1t3/lambda1m3_2); + double t2 = std::sqrt(1.0+4.0*lambda1t3/lambda1m3_2); double t12 = t1*t2; double e1 = -t1 + t12; //t1*(-1.0f + t2 ); @@ -213,8 +213,8 @@ void HomographyDecompZhang::decompose(std::vector& camMotions) double e1_2 = e1*e1; double e3_2 = e3*e3; - double nv1p = sqrt(e1_2*lambda1m3_2 + 2*e1*(lambda1t3-1) + 1.0); - double nv3p = sqrt(e3_2*lambda1m3_2 + 2*e3*(lambda1t3-1) + 1.0); + double nv1p = std::sqrt(e1_2*lambda1m3_2 + 2*e1*(lambda1t3-1) + 1.0); + double nv3p = std::sqrt(e3_2*lambda1m3_2 + 2*e3*(lambda1t3-1) + 1.0); double v1p[3], v3p[3]; v1p[0]=Vt.at(0)*nv1p, v1p[1]=Vt.at(1)*nv1p, v1p[2]=Vt.at(2)*nv1p; @@ -349,9 +349,9 @@ void HomographyDecompInria::decompose(std::vector& camMotions) double M11 = oppositeOfMinor(S, 1, 1); double M22 = oppositeOfMinor(S, 2, 2); - double rtM00 = sqrt(M00); - double rtM11 = sqrt(M11); - double rtM22 = sqrt(M22); + double rtM00 = std::sqrt(M00); + double rtM11 = std::sqrt(M11); + double rtM22 = std::sqrt(M22); double M01 = oppositeOfMinor(S, 0, 1); double M12 = oppositeOfMinor(S, 1, 2); @@ -398,14 +398,14 @@ void HomographyDecompInria::decompose(std::vector& camMotions) } double traceS = S(0, 0) + S(1, 1) + S(2, 2); - double v = 2.0 * sqrt(1 + traceS - M00 - M11 - M22); + double v = 2.0 * std::sqrt(1 + traceS - M00 - M11 - M22); double ESii = signd(S(indx, indx)) ; double r_2 = 2 + traceS + v; double nt_2 = 2 + traceS - v; - double r = sqrt(r_2); - double n_t = sqrt(nt_2); + double r = std::sqrt(r_2); + double n_t = std::sqrt(nt_2); Vec3d na = npa / norm(npa); Vec3d nb = npb / norm(npb); diff --git a/modules/geometry/src/ippe.cpp b/modules/geometry/src/ippe.cpp index 50e503eafa..e88848cf04 100644 --- a/modules/geometry/src/ippe.cpp +++ b/modules/geometry/src/ippe.cpp @@ -192,7 +192,7 @@ void PoseSolver::solveSquare(InputArray _objectPoints, InputArray _imagePoints, objectPoints2D.ptr(0)[2] = Vec2d(objectPoints.ptr(0)[2](0), objectPoints.ptr(0)[2](1)); objectPoints2D.ptr(0)[3] = Vec2d(objectPoints.ptr(0)[3](0), objectPoints.ptr(0)[3](1)); - squareLength = sqrt( (objectPoints.ptr(0)[1](0) - objectPoints.ptr(0)[0](0))* + squareLength = std::sqrt( (objectPoints.ptr(0)[1](0) - objectPoints.ptr(0)[0](0))* (objectPoints.ptr(0)[1](0) - objectPoints.ptr(0)[0](0)) + (objectPoints.ptr(0)[1](1) - objectPoints.ptr(0)[0](1))* (objectPoints.ptr(0)[1](1) - objectPoints.ptr(0)[0](1)) ); @@ -204,7 +204,7 @@ void PoseSolver::solveSquare(InputArray _objectPoints, InputArray _imagePoints, objectPoints2D.ptr(0)[2] = Vec2d(objectPoints.ptr(0)[2](0), objectPoints.ptr(0)[2](1)); objectPoints2D.ptr(0)[3] = Vec2d(objectPoints.ptr(0)[3](0), objectPoints.ptr(0)[3](1)); - squareLength = sqrt( (objectPoints.ptr(0)[1](0) - objectPoints.ptr(0)[0](0))* + squareLength = std::sqrt( (objectPoints.ptr(0)[1](0) - objectPoints.ptr(0)[0](0))* (objectPoints.ptr(0)[1](0) - objectPoints.ptr(0)[0](0)) + (objectPoints.ptr(0)[1](1) - objectPoints.ptr(0)[0](1))* (objectPoints.ptr(0)[1](1) - objectPoints.ptr(0)[0](1)) ); @@ -303,7 +303,7 @@ void PoseSolver::rot2vec(InputArray _R, OutputArray _r) Mat rvec = _r.getMat(); double trace = R.at(0, 0) + R.at(1, 1) + R.at(2, 2); - double w_norm = std::acos(std::min(std::max((trace - 1.0) / 2.0, -1.0), 1.0)); + double w_norm = std::acos(std::clamp((trace - 1.0) / 2.0, -1.0, 1.0)); double eps = std::numeric_limits::epsilon(); double d = 1 / (2 * std::sin(w_norm)) * w_norm; if (w_norm < eps) //rotation is the identity @@ -458,11 +458,11 @@ void PoseSolver::computeRotations(double j00, double j01, double j10, double j11 double ata01 = a00 * a10 + a01 * a11; double ata11 = a10 * a10 + a11 * a11; - double gamma2 = 0.5 * (ata00 + ata11 + sqrt((ata00 - ata11) * (ata00 - ata11) + 4.0 * ata01 * ata01)); + double gamma2 = 0.5 * (ata00 + ata11 + std::sqrt((ata00 - ata11) * (ata00 - ata11) + 4.0 * ata01 * ata01)); if (gamma2 < 0) CV_Error(Error::StsNoConv, "gamma2 is negative."); - double gamma = sqrt(gamma2); + double gamma = std::sqrt(gamma2); if (std::fabs(gamma) < std::numeric_limits::epsilon()) CV_Error(Error::StsNoConv, "gamma is zero."); @@ -478,8 +478,8 @@ void PoseSolver::computeRotations(double j00, double j01, double j10, double j11 double rtilde10_2 = rtilde10 * rtilde10; double rtilde11_2 = rtilde11 * rtilde11; - double b0 = sqrt(-rtilde00_2 - rtilde10_2 + 1); - double b1 = sqrt(-rtilde01_2 - rtilde11_2 + 1); + double b0 = std::sqrt(-rtilde00_2 - rtilde10_2 + 1); + double b1 = std::sqrt(-rtilde01_2 - rtilde11_2 + 1); double sp = (-rtilde00 * rtilde01 - rtilde10 * rtilde11); if (sp < 0) @@ -715,7 +715,7 @@ void PoseSolver::evalReprojError(InputArray _objectPoints, InputArray _imagePoin err += dx * dx + dy * dy; } - err = sqrt(err / (2.0f * n)); + err = std::sqrt(err / (2.0f * n)); } void PoseSolver::sortPosesByReprojError(InputArray _objectPoints, InputArray _imagePoints, InputArray _Ma, InputArray _Mb, @@ -748,7 +748,7 @@ void PoseSolver::rotateVec2ZAxis(const Matx31d& a, Matx33d& Ra) double ay = a(1); double az = a(2); - double nrm = sqrt(ax*ax + ay*ay + az*az); + double nrm = std::sqrt(ax*ax + ay*ay + az*az); ax = ax/nrm; ay = ay/nrm; az = az/nrm; @@ -824,7 +824,7 @@ bool PoseSolver::computeObjextSpaceR3Pts(InputArray _objectPoints, Matx33d& R) double ny = (p1x - p3x)*(p1z - p2z) - (p1x - p2x)*(p1z - p3z); double nz = (p1x - p2x)*(p1y - p3y) - (p1x - p3x)*(p1y - p2y); - double nrm = sqrt(nx*nx+ ny*ny + nz*nz); + double nrm = std::sqrt(nx*nx+ ny*ny + nz*nz); if (nrm > IPPE_SMALL) { nx = nx/nrm; @@ -964,7 +964,7 @@ void normalizeDataIsotropic(InputArray _Data, OutputArray _DataN, OutputArray _T DataN.at(1, i) = yh; kappa = kappa + xh * xh + yh * yh; } - double beta = sqrt(2 * numPoints / kappa); + double beta = std::sqrt(2 * numPoints / kappa); DataN = DataN * beta; T.at(0, 0) = 1.0 / beta; diff --git a/modules/geometry/src/levmarq.cpp b/modules/geometry/src/levmarq.cpp index a92f273dab..989bc1bf85 100644 --- a/modules/geometry/src/levmarq.cpp +++ b/modules/geometry/src/levmarq.cpp @@ -241,7 +241,7 @@ LevMarq::Report detail::LevMarqBase::optimize() if (geoSolved) { - double truncerr = sqrt(xgeo.dot(xgeo) / x.dot(x)); + double truncerr = std::sqrt(xgeo.dot(xgeo) / x.dot(x)); bool geoIsGood = (truncerr < 1.0); if (geoIsGood) x += xgeo * settings.geoScale; @@ -295,7 +295,7 @@ LevMarq::Report detail::LevMarqBase::optimize() enoughLm = true; if (settings.useStepQuality) - lambdaLevMarq *= std::max(1.0 / settings.initialLmDownFactor, 1.0 - pow(2.0 * stepQuality - 1.0, 3)); + lambdaLevMarq *= std::max(1.0 / settings.initialLmDownFactor, 1.0 - std::pow(2.0 * stepQuality - 1.0, 3)); else lambdaLevMarq *= 1.0 / settings.initialLmDownFactor; lmUpFactor = settings.initialLmUpFactor; diff --git a/modules/geometry/src/p3p.cpp b/modules/geometry/src/p3p.cpp index fa8fe1f68d..81d1fba159 100644 --- a/modules/geometry/src/p3p.cpp +++ b/modules/geometry/src/p3p.cpp @@ -180,7 +180,7 @@ void p3p::calibrateAndNormalizePointsPnP(const Mat &opoints_, const Mat &ipoints for (int i = 0; i < 3; i++) { const double k_inv_u = ipoints.at(i, 0); const double k_inv_v = ipoints.at(i, 1); - double x_norm = 1.0 / sqrt(k_inv_u*k_inv_u + k_inv_v*k_inv_v + 1); + double x_norm = 1.0 / std::sqrt(k_inv_u*k_inv_u + k_inv_v*k_inv_v + 1); x_copy[i](0) = k_inv_u * x_norm; x_copy[i](1) = k_inv_v * x_norm; x_copy[i](2) = x_norm; diff --git a/modules/geometry/src/pinhole.cpp b/modules/geometry/src/pinhole.cpp index c0e92832fe..80ba3becba 100644 --- a/modules/geometry/src/pinhole.cpp +++ b/modules/geometry/src/pinhole.cpp @@ -285,7 +285,7 @@ static void undistortPointsInternal( const Mat& _src, Mat& _dst, const Mat& _cam double x_proj = xd*fx + cx; double y_proj = yd*fy + cy; - error = sqrt( std::pow(x_proj - u, 2) + std::pow(y_proj - v, 2) ); + error = std::sqrt( std::pow(x_proj - u, 2) + std::pow(y_proj - v, 2) ); } if (error > prevError) { alpha *= .5; diff --git a/modules/geometry/src/polynom_solver.cpp b/modules/geometry/src/polynom_solver.cpp index 48aa1f12b3..6a571f7b00 100644 --- a/modules/geometry/src/polynom_solver.cpp +++ b/modules/geometry/src/polynom_solver.cpp @@ -24,7 +24,7 @@ int solve_deg2(double a, double b, double c, double & x1, double & x2) return 1; } - double sqrt_delta = sqrt(delta); + double sqrt_delta = std::sqrt(delta); x1 = (-b + sqrt_delta) * inv_2a; x2 = (-b - sqrt_delta) * inv_2a; return 2; @@ -94,7 +94,7 @@ int solve_deg3(double a, double b, double c, double d, double R_abs = fabs(R); if (R_abs > DBL_EPSILON) { - AD = cv::cubeRoot(R_abs + sqrt(D)); + AD = cv::cubeRoot(R_abs + std::sqrt(D)); AD = (R >= 0) ? AD : -AD; BD = -Q / AD; } @@ -131,7 +131,7 @@ int solve_deg4(double a, double b, double c, double d, double e, if (R2 < 0) return 0; - R = sqrt(R2); + R = std::sqrt(R2); double inv_R = 1. / R; int nb_real_roots = 0; @@ -143,7 +143,7 @@ int solve_deg4(double a, double b, double c, double d, double e, if (temp < 0) D2 = E2 = -1; else { - double sqrt_temp = sqrt(temp); + double sqrt_temp = std::sqrt(temp); D2 = 0.75 * b2 - 2 * c + 2 * sqrt_temp; E2 = D2 - 4 * sqrt_temp; } @@ -157,7 +157,7 @@ int solve_deg4(double a, double b, double c, double d, double e, double b_4 = 0.25 * b, R_2 = 0.5 * R; if (D2 >= 0) { - double D = sqrt(D2); + double D = std::sqrt(D2); nb_real_roots = 2; double D_2 = 0.5 * D; x0 = R_2 + D_2 - b_4; @@ -166,7 +166,7 @@ int solve_deg4(double a, double b, double c, double d, double e, // Calculate E^2 if (E2 >= 0) { - double E = sqrt(E2); + double E = std::sqrt(E2); double E_2 = 0.5 * E; if (nb_real_roots == 0) { x0 = - R_2 + E_2 - b_4; diff --git a/modules/geometry/src/rho.cpp b/modules/geometry/src/rho.cpp index 941dab98a7..bdc643949b 100644 --- a/modules/geometry/src/rho.cpp +++ b/modules/geometry/src/rho.cpp @@ -1475,8 +1475,8 @@ static inline double sacDesignSPRTTest(double delta, double epsilon, double t_M, * Eq (2) */ - C = (1-delta) * log((1-delta)/(1-epsilon)) + - delta * log( delta / epsilon ); + C = (1-delta) * std::log((1-delta)/(1-epsilon)) + + delta * std::log( delta / epsilon ); /** * Randomized RANSAC with Sequential Probability Ratio Test, ICCV 2005 @@ -1501,7 +1501,7 @@ static inline double sacDesignSPRTTest(double delta, double epsilon, double t_M, do{ prevAn = An; - An = K + log(An); + An = K + std::log(An); }while((An-prevAn > 1.5e-8) && (++i < 10)); /** @@ -1598,11 +1598,11 @@ static inline void sacInitNonRand(double beta, unsigned N, unsigned* nonRandMinInl){ unsigned n = SMPL_SIZE+1 > start ? SMPL_SIZE+1 : start; - double beta_beta1_sq_chi = sqrt(beta*(1.0-beta)) * CHI_SQ; + double beta_beta1_sq_chi = std::sqrt(beta*(1.0-beta)) * CHI_SQ; for(; n < N; n++){ double mu = n * beta; - double sigma = sqrt((double)n)* beta_beta1_sq_chi; + double sigma = std::sqrt((double)n)* beta_beta1_sq_chi; unsigned i_min = (unsigned)ceil(SMPL_SIZE + mu + sigma); nonRandMinInl[n] = i_min; @@ -1770,7 +1770,7 @@ static inline unsigned sacCalcIterBound(double confidence, * numIterations (the return value) into */ - retVal = (unsigned)ceil(log(1.-confidence)/log(atLeastOneOutlierProbability)); + retVal = (unsigned)ceil(std::log(1.-confidence)/std::log(atLeastOneOutlierProbability)); } /** diff --git a/modules/geometry/src/shapedescr.cpp b/modules/geometry/src/shapedescr.cpp index 891776ac46..07911df943 100644 --- a/modules/geometry/src/shapedescr.cpp +++ b/modules/geometry/src/shapedescr.cpp @@ -526,12 +526,12 @@ cv::RotatedRect cv::fitEllipseAMS( InputArray _points ) // Select the eigen vector {a,b,c,d,e} which has the lowest eigenvalue int minpos = 0; double normi, normEVali, normMinpos, normEValMinpos; - normMinpos = sqrt(eVec.at(minpos,0)*eVec.at(minpos,0) + eVec.at(minpos,1)*eVec.at(minpos,1) + \ + normMinpos = std::sqrt(eVec.at(minpos,0)*eVec.at(minpos,0) + eVec.at(minpos,1)*eVec.at(minpos,1) + \ eVec.at(minpos,2)*eVec.at(minpos,2) + eVec.at(minpos,3)*eVec.at(minpos,3) + \ eVec.at(minpos,4)*eVec.at(minpos,4) ); normEValMinpos = eVal.at(minpos,0) * normMinpos; for (i=1; i<5; i++) { - normi = sqrt(eVec.at(i,0)*eVec.at(i,0) + eVec.at(i,1)*eVec.at(i,1) + \ + normi = std::sqrt(eVec.at(i,0)*eVec.at(i,0) + eVec.at(i,1)*eVec.at(i,1) + \ eVec.at(i,2)*eVec.at(i,2) + eVec.at(i,3)*eVec.at(i,3) + \ eVec.at(i,4)*eVec.at(i,4) ); normEVali = eVal.at(i,0) * normi; @@ -567,7 +567,7 @@ cv::RotatedRect cv::fitEllipseAMS( InputArray _points ) if (is_ellipse) { double u1 = pVec(2) *pVec(3) *pVec(3) - pVec(1) *pVec(3) *pVec(4) + pVec(0) *pVec(4) *pVec(4) + pVec(1) *pVec(1) *coeffs(5) ; double u2 = pVec(0) *pVec(2) *coeffs(5) ; - double l1 = sqrt(pVec(1) *pVec(1) + (pVec(0) - pVec(2) )*(pVec(0) - pVec(2) )); + double l1 = std::sqrt(pVec(1) *pVec(1) + (pVec(0) - pVec(2) )*(pVec(0) - pVec(2) )); double l2 = pVec(0) + pVec(2) ; double l3 = pVec(1) *pVec(1) - 4.0*pVec(0) *pVec(2) ; double p1 = 2.0*pVec(2) *pVec(3) - pVec(1) *pVec(4) ; @@ -575,8 +575,8 @@ cv::RotatedRect cv::fitEllipseAMS( InputArray _points ) x0 = p1/l3/scale + c.x; y0 = p2/l3/scale + c.y; - a = std::sqrt(2.)*sqrt((u1 - 4.0*u2)/((l1 - l2)*l3))/scale; - b = std::sqrt(2.)*sqrt(-1.0*((u1 - 4.0*u2)/((l1 + l2)*l3)))/scale; + a = std::sqrt(2.)*std::sqrt((u1 - 4.0*u2)/((l1 - l2)*l3))/scale; + b = std::sqrt(2.)*std::sqrt(-1.0*((u1 - 4.0*u2)/((l1 + l2)*l3)))/scale; if (pVec(1) == 0) { if (pVec(0) < pVec(2) ) { theta = 0; @@ -751,7 +751,7 @@ cv::RotatedRect cv::fitEllipseDirect( InputArray _points ) double u1 = pVec(2)*Q(0,0)*Q(0,0) - pVec(1)*Q(0,0)*Q(0,1) + pVec(0)*Q(0,1)*Q(0,1) + pVec(1)*pVec(1)*Q(0,2); double u2 = pVec(0)*pVec(2)*Q(0,2); - double l1 = sqrt(pVec(1)*pVec(1) + (pVec(0) - pVec(2))*(pVec(0) - pVec(2))); + double l1 = std::sqrt(pVec(1)*pVec(1) + (pVec(0) - pVec(2))*(pVec(0) - pVec(2))); double l2 = pVec(0) + pVec(2) ; double l3 = pVec(1)*pVec(1) - 4*pVec(0)*pVec(2) ; double p1 = 2*pVec(2)*Q(0,0) - pVec(1)*Q(0,1); @@ -759,8 +759,8 @@ cv::RotatedRect cv::fitEllipseDirect( InputArray _points ) x0 = (p1/l3/scale) + c.x; y0 = (p2/l3/scale) + c.y; - a = sqrt(2.)*sqrt((u1 - 4.0*u2)/((l1 - l2)*l3))/scale; - b = sqrt(2.)*sqrt(-1.0*((u1 - 4.0*u2)/((l1 + l2)*l3)))/scale; + a = std::sqrt(2.)*std::sqrt((u1 - 4.0*u2)/((l1 - l2)*l3))/scale; + b = std::sqrt(2.)*std::sqrt(-1.0*((u1 - 4.0*u2)/((l1 + l2)*l3)))/scale; if (pVec(1) == 0) { if (pVec(0) < pVec(2) ) { theta = 0; @@ -835,8 +835,8 @@ static void solveFast(float semi_major, float semi_minor, const cv::Point2f& pt, float r = std::hypotf(rx, ry); float q = std::hypotf(qx, qy); - tx = std::min(1.0f, std::max(0.0f, ((qx / q) * r + ex) / a)); - ty = std::min(1.0f, std::max(0.0f, ((qy / q) * r + ey) / b)); + tx = std::clamp(((qx / q) * r + ex) / a, 0.0f, 1.0f); + ty = std::clamp(((qy / q) * r + ey) / b, 0.0f, 1.0f); float t = std::hypotf(tx, ty); tx /= t; ty /= t; diff --git a/modules/geometry/src/solvepnp.cpp b/modules/geometry/src/solvepnp.cpp index 3f5d3fb808..a0e8aaf417 100644 --- a/modules/geometry/src/solvepnp.cpp +++ b/modules/geometry/src/solvepnp.cpp @@ -627,7 +627,7 @@ static void exponentialMapToSE3Inv(const Mat& twist, Mat& R1, Mat& t1) Mat R; Rodrigues(rvec, R); - double theta = sqrt(wx*wx + wy*wy + wz*wz); + double theta = std::sqrt(wx*wx + wy*wy + wz*wz); double sinc = std::fabs(theta) < 1e-8 ? 1 : std::sin(theta) / theta; double mcosc = (std::fabs(theta) < 1e-8) ? 0.5 : (1- std::cos(theta)) / (theta*theta); double msinc = (std::abs(theta) < 1e-8) ? (1/6.0) : (1-sinc) / (theta*theta); @@ -1049,7 +1049,7 @@ int solvePnPGeneric( InputArray _opoints, InputArray _ipoints, { int type = (reprojectionError.fixedType() || !reprojectionError.empty()) ? reprojectionError.type() - : (max(_ipoints.depth(), _opoints.depth()) == CV_64F ? CV_64F : CV_32F); + : (std::max(_ipoints.depth(), _opoints.depth()) == CV_64F ? CV_64F : CV_32F); reprojectionError.create(solutions, 1, type); CV_CheckType(reprojectionError.type(), type == CV_32FC1 || type == CV_64FC1, @@ -1078,7 +1078,7 @@ int solvePnPGeneric( InputArray _opoints, InputArray _ipoints, Mat projectedPoints; projectPoints(objectPoints, vec_rvecs[i], vec_tvecs[i], cameraMatrix, distCoeffs, projectedPoints); int nprojectedPoints = (int)projectedPoints.total(); - double rmse = norm(projectedPoints, imagePoints, NORM_L2) / sqrt(2*nprojectedPoints); + double rmse = norm(projectedPoints, imagePoints, NORM_L2) / std::sqrt(2*nprojectedPoints); Mat err = reprojectionError.getMat(); if (type == CV_32F) diff --git a/modules/geometry/src/sqpnp.cpp b/modules/geometry/src/sqpnp.cpp index 37a19dff69..c863830753 100644 --- a/modules/geometry/src/sqpnp.cpp +++ b/modules/geometry/src/sqpnp.cpp @@ -521,7 +521,7 @@ void PoseSolver::computeRowAndNullspace(const cv::Matx& r, H = cv::Matx::zeros(); // 1. q1 - double norm_r1 = sqrt(r(0) * r(0) + r(1) * r(1) + r(2) * r(2)); + double norm_r1 = std::sqrt(r(0) * r(0) + r(1) * r(1) + r(2) * r(2)); double inv_norm_r1 = norm_r1 > 1e-5 ? 1.0 / norm_r1 : 0.0; H(0, 0) = r(0) * inv_norm_r1; H(1, 0) = r(1) * inv_norm_r1; @@ -529,7 +529,7 @@ void PoseSolver::computeRowAndNullspace(const cv::Matx& r, K(0, 0) = 2 * norm_r1; // 2. q2 - double norm_r2 = sqrt(r(3) * r(3) + r(4) * r(4) + r(5) * r(5)); + double norm_r2 = std::sqrt(r(3) * r(3) + r(4) * r(4) + r(5) * r(5)); double inv_norm_r2 = 1.0 / norm_r2; H(3, 1) = r(3) * inv_norm_r2; H(4, 1) = r(4) * inv_norm_r2; @@ -538,7 +538,7 @@ void PoseSolver::computeRowAndNullspace(const cv::Matx& r, K(1, 1) = 2 * norm_r2; // 3. q3 = (r3'*q2)*q2 - (r3'*q1)*q1 ; q3 = q3/norm(q3) - double norm_r3 = sqrt(r(6) * r(6) + r(7) * r(7) + r(8) * r(8)); + double norm_r3 = std::sqrt(r(6) * r(6) + r(7) * r(7) + r(8) * r(8)); double inv_norm_r3 = 1.0 / norm_r3; H(6, 2) = r(6) * inv_norm_r3; H(7, 2) = r(7) * inv_norm_r3; @@ -556,7 +556,7 @@ void PoseSolver::computeRowAndNullspace(const cv::Matx& r, H(3, 3) = r(0) - dot_j4q2 * H(3, 1); H(4, 3) = r(1) - dot_j4q2 * H(4, 1); H(5, 3) = r(2) - dot_j4q2 * H(5, 1); - double inv_norm_j4 = 1.0 / sqrt(H(0, 3) * H(0, 3) + H(1, 3) * H(1, 3) + H(2, 3) * H(2, 3) + + double inv_norm_j4 = 1.0 / std::sqrt(H(0, 3) * H(0, 3) + H(1, 3) * H(1, 3) + H(2, 3) * H(2, 3) + H(3, 3) * H(3, 3) + H(4, 3) * H(4, 3) + H(5, 3) * H(5, 3)); H(0, 3) *= inv_norm_j4; diff --git a/modules/geometry/src/triangulate.cpp b/modules/geometry/src/triangulate.cpp index 26d4908463..fa66641d3d 100644 --- a/modules/geometry/src/triangulate.cpp +++ b/modules/geometry/src/triangulate.cpp @@ -214,14 +214,14 @@ void correctMatches( InputArray _F, InputArray _points1, InputArray _points2, // Compute the right epipole e1 from F * e1 = 0 SVDecomp(TFT, S, U, Vt); - double scale = sqrt(Vt(2, 0)*Vt(2, 0) + Vt(2, 1)*Vt(2, 1)); + double scale = std::sqrt(Vt(2, 0)*Vt(2, 0) + Vt(2, 1)*Vt(2, 1)); Vec3d e1(Vt(2, 0)/scale, Vt(2, 1)/scale, Vt(2, 2)/scale); if (e1(2) < 0) e1 = -e1; // Compute the left epipole e2 from e2' * F = 0 => F' * e2 = 0 - scale = sqrt(U(0, 2)*U(0, 2) + U(1, 2)*U(1, 2)); + scale = std::sqrt(U(0, 2)*U(0, 2) + U(1, 2)*U(1, 2)); Vec3d e2(U(0, 2)/scale, U(1, 2)/scale, U(2, 2)/scale); if (e2(2) < 0) diff --git a/modules/geometry/src/usac/degeneracy.cpp b/modules/geometry/src/usac/degeneracy.cpp index 590c8aaf9b..1816cdd993 100644 --- a/modules/geometry/src/usac/degeneracy.cpp +++ b/modules/geometry/src/usac/degeneracy.cpp @@ -201,7 +201,7 @@ private: Ptr random_gen_H; const EpipolarGeometryDegeneracyImpl ep_deg; // threshold to find inliers for homography model - const double homography_threshold, log_conf = log(0.05), H_SAMPLE_THR_SQR = 49/*7^2*/, MAX_H_THR = 225/*15^2*/; + const double homography_threshold, log_conf = std::log(0.05), H_SAMPLE_THR_SQR = 49/*7^2*/, MAX_H_THR = 225/*15^2*/; double f_threshold_sqr, best_focal = -1; // points (1-7) to verify in sample std::vector> h_sample {{0,1,2},{3,4,5},{0,1,6},{3,4,6},{2,5,6}}; @@ -435,7 +435,7 @@ public: const int num_f_inliers_of_h_outliers = getNonPlanarSupport(Mat(F), num_models_used_so_far >= MAX_MODELS_TO_TEST, non_planar_support); if (non_planar_support < num_f_inliers_of_h_outliers) { non_planar_support = num_f_inliers_of_h_outliers; - const double predicted_iters = log_conf / log(1 - std::pow(static_cast + const double predicted_iters = log_conf / std::log(1 - std::pow(static_cast (getNonPlanarSupport(Mat(F), non_planar_pts, num_non_planar_pts)) / num_non_planar_pts, 2)); if (use_preemptive && ! std::isinf(predicted_iters) && predicted_iters < max_iters) max_iters = static_cast(predicted_iters); diff --git a/modules/geometry/src/usac/essential_solver.cpp b/modules/geometry/src/usac/essential_solver.cpp index dfff4b970b..7ab340129d 100644 --- a/modules/geometry/src/usac/essential_solver.cpp +++ b/modules/geometry/src/usac/essential_solver.cpp @@ -178,8 +178,8 @@ public: Matx33d Bz(bz); // Bz is rank 2, matrix, so epipole is its null-vector - Vec3d xy1 = Utils::getRightEpipole(Mat(Bz * (1/sqrt(norm_bz)))); - const double one_over_xy1_norm = 1 / sqrt(xy1[0] * xy1[0] + xy1[1] * xy1[1] + xy1[2] * xy1[2]); + Vec3d xy1 = Utils::getRightEpipole(Mat(Bz * (1/std::sqrt(norm_bz)))); + const double one_over_xy1_norm = 1 / std::sqrt(xy1[0] * xy1[0] + xy1[1] * xy1[1] + xy1[2] * xy1[2]); xy1 *= one_over_xy1_norm; if (fabs(xy1(2)) < 1e-10) continue; diff --git a/modules/geometry/src/usac/estimator.cpp b/modules/geometry/src/usac/estimator.cpp index e6a44b4027..c4ca3bb460 100644 --- a/modules/geometry/src/usac/estimator.cpp +++ b/modules/geometry/src/usac/estimator.cpp @@ -606,7 +606,7 @@ public: const double * const p = (double *) model.data; double coeff_a = p[0], coeff_b = p[1], coeff_c = p[2], coeff_d = p[3]; // Format for easy distance calculation - double magnitude_abc = sqrt(coeff_a * coeff_a + coeff_b * coeff_b + coeff_c * coeff_c); + double magnitude_abc = std::sqrt(coeff_a * coeff_a + coeff_b * coeff_b + coeff_c * coeff_c); if (0 != magnitude_abc) { double inv_magnitude_abc = 1.0 / magnitude_abc; coeff_a = coeff_a * inv_magnitude_abc; @@ -703,7 +703,7 @@ public: float diff_y = center_y - pts_ptr_y[point_idx]; float diff_z = center_z - pts_ptr_z[point_idx]; // A better way to avoid sqrt() ? - float distance_from_center = sqrt(diff_x * diff_x + diff_y * diff_y + diff_z * diff_z); + float distance_from_center = std::sqrt(diff_x * diff_x + diff_y * diff_y + diff_z * diff_z); float diff_dist = distance_from_center - radius; double distance_square_from_surface = diff_dist * diff_dist; @@ -743,7 +743,7 @@ public: float diff_y = center_y - pts_ptr_y[i]; float diff_z = center_z - pts_ptr_z[i]; // A better way to avoid sqrt() ? - float distance_from_center = sqrt(diff_x * diff_x + diff_y * diff_y + diff_z * diff_z); + float distance_from_center = std::sqrt(diff_x * diff_x + diff_y * diff_y + diff_z * diff_z); float diff_dist = distance_from_center - radius; errors_cache[i] = diff_dist * diff_dist; } @@ -851,8 +851,8 @@ public: x2_m = points[smpl + 2] - mean_pts2_x; y2_m = points[smpl + 3] - mean_pts2_y; - avg_dist1 += sqrt (x1_m * x1_m + y1_m * y1_m); - avg_dist2 += sqrt (x2_m * x2_m + y2_m * y2_m); + avg_dist1 += std::sqrt (x1_m * x1_m + y1_m * y1_m); + avg_dist2 += std::sqrt (x2_m * x2_m + y2_m * y2_m); } // scale diff --git a/modules/geometry/src/usac/pnp_solver.cpp b/modules/geometry/src/usac/pnp_solver.cpp index f699e7cd4e..a85d04ccc4 100644 --- a/modules/geometry/src/usac/pnp_solver.cpp +++ b/modules/geometry/src/usac/pnp_solver.cpp @@ -361,16 +361,16 @@ public: const double n12 = root, n12_p2 = n12 * n12; const double n13 = (d12_p2*(d23_p2-d31_p2*n12_p2)+(d23_p2-d31_p2)*(d23_p2*(1+n12_p2-2*n12*c12)-d12_p2*n12_p2)) / (2*d12_p2*(d23_p2*c31 - d31_p2*c23*n12) + 2*(d31_p2-d23_p2)*d12_p2*c23*n12); - const double n1 = d12 / sqrt(1 + n12_p2 - 2*n12*c12); // 1+n12^2-2n12c12 is always > 0 + const double n1 = d12 / std::sqrt(1 + n12_p2 - 2*n12*c12); // 1+n12^2-2n12c12 is always > 0 const double n2 = n1 * n12; const double n3 = n1 * n13; if (n1 <= 0 || n2 <= 0 || n3 <= 0) continue; // compute and check errors - if (fabs((sqrt(n1*n1 + n2*n2 - 2*n1*n2*c12) - d12) / d12) > VAL_THR || - fabs((sqrt(n2*n2 + n3*n3 - 2*n2*n3*c23) - d23) / d23) > VAL_THR || - fabs((sqrt(n3*n3 + n1*n1 - 2*n3*n1*c31) - d31) / d31) > VAL_THR) + if (fabs((std::sqrt(n1*n1 + n2*n2 - 2*n1*n2*c12) - d12) / d12) > VAL_THR || + fabs((std::sqrt(n2*n2 + n3*n3 - 2*n2*n3*c23) - d23) / d23) > VAL_THR || + fabs((std::sqrt(n3*n3 + n1*n1 - 2*n3*n1*c31) - d31) / d31) > VAL_THR) continue; const Vec3d nX1 = n1 * cx1; diff --git a/modules/geometry/src/usac/quality.cpp b/modules/geometry/src/usac/quality.cpp index 9935eada56..4cd770fceb 100644 --- a/modules/geometry/src/usac/quality.cpp +++ b/modules/geometry/src/usac/quality.cpp @@ -193,7 +193,7 @@ public: stored_complete_gamma_values (gamma_generator->getCompleteGammaValues()), stored_lower_incomplete_gamma_values (gamma_generator->getIncompleteGammaValues()) { previous_best_loss = std::numeric_limits::max(); - const auto maximum_sigma = (float)sqrt(maximum_threshold_sqr) / sigma_quantile; + const auto maximum_sigma = (float)std::sqrt(maximum_threshold_sqr) / sigma_quantile; const auto maximum_sigma_2 = (float) (maximum_sigma * maximum_sigma); maximum_sigma_2_per_2 = maximum_sigma_2 / 2.f; const auto maximum_sigma_2_times_2 = maximum_sigma_2 * 2.f; @@ -560,20 +560,20 @@ private: complement_delta_to_complement_epsilon = (1 - delta) / (1 - epsilon); if (IS_ADAPTIVE) { - avg_num_checked_pts = std::min((log(current_A) / C) * one_over_complement_alpha, (double)points_size); + avg_num_checked_pts = std::min((std::log(current_A) / C) * one_over_complement_alpha, (double)points_size); do_sprt = time_ver_corr_sprt * avg_num_checked_pts < time_ver_corr * points_size; } return true; } std::pair estimateThresholdA (double epsilon, double delta) { - const double C = (1 - delta) * log ((1 - delta) / (1 - epsilon)) + delta * log (delta / epsilon); + const double C = (1 - delta) * std::log ((1 - delta) / (1 - epsilon)) + delta * std::log (delta / epsilon); // K = K1/K2 + 1 = (t_M / P_g) / (m_S / (C * P_g)) + 1 = (t_M * C)/m_S + 1 const double K = t_M * C / m_S + 1; double An, An_1 = K; // compute A using a recursive relation // A* = lim(n->inf)(An), the series typically converges within 4 iterations for (int i = 0; i < 10; i++) { - An = K + log(An_1); + An = K + std::log(An_1); if (fabs(An - An_1) < FLT_EPSILON) break; An_1 = An; diff --git a/modules/geometry/src/usac/ransac_solvers.cpp b/modules/geometry/src/usac/ransac_solvers.cpp index 671d9d3d1b..ebd53b3171 100644 --- a/modules/geometry/src/usac/ransac_solvers.cpp +++ b/modules/geometry/src/usac/ransac_solvers.cpp @@ -96,7 +96,7 @@ double getLambda (std::vector &supports, double cdf_thr, int points_size, int sample_size, bool is_independent, int &min_non_random_inliers) { std::sort(supports.begin(), supports.end()); double lambda = supports.size() % 2 ? (supports[supports.size()/2] + supports[supports.size()/2+1])*0.5 : supports[supports.size()/2]; - const double cdf = lambda + cdf_thr*sqrt(lambda * (1 - lambda / (is_independent ? points_size - sample_size : points_size))); + const double cdf = lambda + cdf_thr*std::sqrt(lambda * (1 - lambda / (is_independent ? points_size - sample_size : points_size))); int lower_than_cdf = 0; lambda = 0; for (const auto &inl : supports) if (inl < cdf) { @@ -106,7 +106,7 @@ double getLambda (std::vector &supports, double cdf_thr, int points_size, if (lambda < 1 || lower_than_cdf == 0) lambda = 1; // use 0.9999 quantile https://keisan.casio.com/exec/system/14060745333941 if (! is_independent) // do not calculate it for all inliers - min_non_random_inliers = (int)(lambda + 2.32*sqrt(lambda * (1 - lambda / points_size))) + 1; + min_non_random_inliers = (int)(lambda + 2.32*std::sqrt(lambda * (1 - lambda / points_size))) + 1; return lambda; } @@ -628,7 +628,7 @@ int UniversalRANSAC::getIndependentInliers (const Mat &model_, const std::vector num_pts_validatin_or_constr++; continue; } - const auto mag2 = 1 / sqrt(a2 * a2 + b2 * b2), mag1 = 1/sqrt(a1 * a1 + b1 * b1); + const auto mag2 = 1 / std::sqrt(a2 * a2 + b2 * b2), mag1 = 1/std::sqrt(a1 * a1 + b1 * b1); a2 *= mag2; b2 *= mag2; c2 *= mag2; a1 *= mag1; b1 *= mag1; c1 *= mag1; } diff --git a/modules/geometry/src/usac/sphere_solver.cpp b/modules/geometry/src/usac/sphere_solver.cpp index bbdd8c58e4..5a6b5b8d35 100644 --- a/modules/geometry/src/usac/sphere_solver.cpp +++ b/modules/geometry/src/usac/sphere_solver.cpp @@ -91,7 +91,7 @@ public: tmp1 = center_x - x1; tmp2 = center_y - y1; tmp3 = center_z - z1; - radius = sqrt(tmp1 * tmp1 + tmp2 * tmp2 + tmp3 * tmp3); + radius = std::sqrt(tmp1 * tmp1 + tmp2 * tmp2 + tmp3 * tmp3); } double sphere_coeff[4] = {center_x, center_y, center_z, radius}; diff --git a/modules/geometry/src/usac/termination.cpp b/modules/geometry/src/usac/termination.cpp index 58c6356b54..c53621a709 100644 --- a/modules/geometry/src/usac/termination.cpp +++ b/modules/geometry/src/usac/termination.cpp @@ -14,7 +14,7 @@ private: public: StandardTerminationCriteriaImpl (double confidence, int points_size_, int sample_size_, int max_iterations_) : - log_confidence(log(1 - confidence)), points_size (points_size_), + log_confidence(std::log(1 - confidence)), points_size (points_size_), sample_size (sample_size_), MAX_ITERATIONS(max_iterations_) {} /* @@ -30,7 +30,7 @@ public: */ int update (const Mat &model, int inlier_number) const override { CV_UNUSED(model); - const double predicted_iters = log_confidence / log(1 - std::pow + const double predicted_iters = log_confidence / std::log(1 - std::pow (static_cast(inlier_number) / points_size, sample_size)); // if inlier_prob == 1 then log(0) = -inf, predicted_iters == -0 @@ -42,7 +42,7 @@ public: } static int getMaxIterations (int inlier_number, int sample_size, int points_size, double conf) { - const double pred_iters = log(1 - conf) / log(1 - std::pow(static_cast(inlier_number)/points_size, sample_size)); + const double pred_iters = std::log(1 - conf) / std::log(1 - std::pow(static_cast(inlier_number)/points_size, sample_size)); if (std::isinf(pred_iters)) return INT_MAX; return (int) pred_iters + 1; @@ -63,7 +63,7 @@ private: public: SPRTTerminationImpl (const Ptr &sprt_, double confidence, int points_size_, int sample_size_, int max_iterations_) - : sprt (sprt_), log_eta_0(log(1-confidence)), + : sprt (sprt_), log_eta_0(std::log(1-confidence)), points_size (points_size_), sample_size (sample_size_),MAX_ITERATIONS(max_iterations_){} /* @@ -90,7 +90,7 @@ public: return getStandardUpperBound(inlier_size); const double epsilon = static_cast(inlier_size) / points_size; // inlier probability - const double P_g = pow (epsilon, sample_size); // probability of good sample + const double P_g = std::pow (epsilon, sample_size); // probability of good sample double log_eta_lmin1 = 0; @@ -98,7 +98,7 @@ public: // compute log n(l-1), l is number of tests for (const auto &test : sprt_histories) { if (test.tested_samples == 0) continue; - log_eta_lmin1 += log (1 - P_g * (1 - pow (test.A, + log_eta_lmin1 += std::log (1 - P_g * (1 - std::pow (test.A, -computeExponentH(test.epsilon, epsilon,test.delta)))) * test.tested_samples; total_number_of_tested_samples += test.tested_samples; } @@ -109,7 +109,7 @@ public: return getStandardUpperBound(inlier_size); // use decision threshold A for last test (l-th) const double predicted_iters_sprt = total_number_of_tested_samples + (log_eta_0 - log_eta_lmin1) / - log (1 - P_g * (1 - 1 / sprt_histories.back().A)); // last A + std::log (1 - P_g * (1 - 1 / sprt_histories.back().A)); // last A if (std::isnan(predicted_iters_sprt) || std::isinf(predicted_iters_sprt)) return getStandardUpperBound(inlier_size); @@ -122,7 +122,7 @@ public: } private: inline int getStandardUpperBound(int inlier_size) const { - const double predicted_iters = log_eta_0 / log(1 - std::pow + const double predicted_iters = log_eta_0 / std::log(1 - std::pow (static_cast(inlier_size) / points_size, sample_size)); return (! std::isinf(predicted_iters) && predicted_iters < MAX_ITERATIONS) ? static_cast(predicted_iters) : MAX_ITERATIONS; @@ -138,13 +138,13 @@ private: * Has numerical solution. */ static double computeExponentH (double epsilon, double epsilon_new, double delta) { - const double a = log (delta / epsilon); // log likelihood ratio - const double b = log ((1 - delta) / (1 - epsilon)); + const double a = std::log (delta / epsilon); // log likelihood ratio + const double b = std::log ((1 - delta) / (1 - epsilon)); - const double x0 = log (1 / (1 - epsilon_new)) / b; - const double v0 = epsilon_new * exp (x0 * a); - const double x1 = log ((1 - 2*v0) / (1 - epsilon_new)) / b; - const double v1 = epsilon_new * exp (x1 * a) + (1 - epsilon_new) * exp(x1 * b); + const double x0 = std::log (1 / (1 - epsilon_new)) / b; + const double v0 = epsilon_new * std::exp (x0 * a); + const double x1 = std::log ((1 - 2*v0) / (1 - epsilon_new)) / b; + const double v1 = epsilon_new * std::exp (x1 * a) + (1 - epsilon_new) * std::exp(x1 * b); const double h = x0 - (x0 - x1) / (1 + v0 - v1) * v0; if (std::isnan(h)) @@ -174,7 +174,7 @@ public: int max_iterations_, double relax_coef_) : sprt_termination (sprt, confidence, points_size_, sample_size_, max_iterations_), - relax_coef (relax_coef_), log_confidence(log(1-confidence)), + relax_coef (relax_coef_), log_confidence(std::log(1-confidence)), points_size (points_size_), sample_size (sample_size_), MAX_ITERS (max_iterations_) {} @@ -185,7 +185,7 @@ public: if (inlier_prob >= 1) return 0; - const double predicted_iters = log_confidence / log(1 - std::pow(inlier_prob, sample_size)); + const double predicted_iters = log_confidence / std::log(1 - std::pow(inlier_prob, sample_size)); if (! std::isinf(predicted_iters) && predicted_iters < predicted_iterations) return static_cast(predicted_iters); @@ -211,7 +211,7 @@ public: ProsacTerminationCriteriaImpl (const Ptr &sampler_,const Ptr &error_, int points_size_, int sample_size_, double confidence, int max_iterations, int min_termination_length_, double beta_, double non_randomness_phi_, - double inlier_threshold_, const std::vector &non_rand_inliers) : log_conf(log(1-confidence)), beta(beta_), + double inlier_threshold_, const std::vector &non_rand_inliers) : log_conf(std::log(1-confidence)), beta(beta_), non_randomness_phi(non_randomness_phi_), inlier_threshold(inlier_threshold_), MAX_ITERATIONS(max_iterations), points_size (points_size_), min_termination_length (min_termination_length_), sample_size(sample_size_), @@ -322,7 +322,7 @@ public: continue; // add 1 to termination length since num_inliers_under_termination_len is updated - const double new_max_samples = log_conf/log(1-std::pow(static_cast(num_inliers_under_termination_len) + const double new_max_samples = log_conf/std::log(1-std::pow(static_cast(num_inliers_under_termination_len) / (termination_len+1), sample_size)); if (! std::isinf(new_max_samples) && predicted_iterations > new_max_samples) { @@ -337,7 +337,7 @@ public: // compare also when termination length = points_size, // so inliers under termination length is total number of inliers: - const double predicted_iters = log_conf / log(1 - std::pow + const double predicted_iters = log_conf / std::log(1 - std::pow (static_cast(inliers_size) / points_size, sample_size)); if (! std::isinf(predicted_iters) && predicted_iters < predicted_iterations) diff --git a/modules/geometry/src/usac/utils.cpp b/modules/geometry/src/usac/utils.cpp index b5afd29104..b82e81a663 100644 --- a/modules/geometry/src/usac/utils.cpp +++ b/modules/geometry/src/usac/utils.cpp @@ -337,17 +337,17 @@ void Utils::decomposeProjection (const Mat &P, Matx33d &K, Matx33d &R, Vec3d &t, K = Matx33d::eye(); K(1,2) = M.row(1).dot(M.row(2)) / scale; K(0,2) = M.row(0).dot(M.row(2)) / scale; - K(1,1) = sqrt(M.row(1).dot(M.row(1)) / scale - K(1,2)*K(1,2)); - K(0,0) = sqrt(M.row(0).dot(M.row(0)) / scale - K(0,2)*K(0,2)); + K(1,1) = std::sqrt(M.row(1).dot(M.row(1)) / scale - K(1,2)*K(1,2)); + K(0,0) = std::sqrt(M.row(0).dot(M.row(0)) / scale - K(0,2)*K(0,2)); if (same_focal) K(0,0) = K(1,1) = (K(0,0) + K(1,1)) / 2; - R = K.inv() * M / sqrt(scale); + R = K.inv() * M / std::sqrt(scale); if (determinant(M) < 0) R *= -1; t = R * M.inv() * Vec3d(P.col(3)); } double Utils::getPoissonCDF (double lambda, int inliers) { - double exp_lambda = exp(-lambda), cdf = exp_lambda, lambda_i_div_fact_i = 1; + double exp_lambda = std::exp(-lambda), cdf = exp_lambda, lambda_i_div_fact_i = 1; for (int i = 1; i <= inliers; i++) { lambda_i_div_fact_i *= (lambda / i); cdf += exp_lambda * lambda_i_div_fact_i; diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index 97bdb359f9..c7875f3b1f 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -407,8 +407,8 @@ int FramebufferBackend::fbOpenAndGetInfo() fbBitsPerPixel = varInfo.bits_per_pixel; fbLineLength = fixInfo.line_length; - fbScreenSize = max(varInfo.xres, varInfo.xres_virtual) * - max(varInfo.yres, varInfo.yres_virtual) * + fbScreenSize = std::max(varInfo.xres, varInfo.xres_virtual) * + std::max(varInfo.yres, varInfo.yres_virtual) * fbBitsPerPixel / 8; fbPointer = (unsigned char*) diff --git a/modules/highgui/src/window_wayland.cpp b/modules/highgui/src/window_wayland.cpp index aa89576644..d7eefbd034 100644 --- a/modules/highgui/src/window_wayland.cpp +++ b/modules/highgui/src/window_wayland.cpp @@ -1660,7 +1660,7 @@ void cv_wl_viewer::on_mouse(int event, cv::Point const &p, int flag) { int y = static_cast((p.y - last_img_area_.y) * ((double) image_.size().height / last_img_area_.height)); - x = cv::min(x, real_img_width); + x = std::min(x, real_img_width); callback_(event, x, y, flag, param_); } } diff --git a/modules/imgproc/src/box_filter.simd.hpp b/modules/imgproc/src/box_filter.simd.hpp index 50e17ce8f4..0bbfcd47a2 100644 --- a/modules/imgproc/src/box_filter.simd.hpp +++ b/modules/imgproc/src/box_filter.simd.hpp @@ -1101,7 +1101,7 @@ inline int BlockSumBorder(const T* ref, const T* S, T* R, ST* SUM, T* D, ST** bu { R[j] = Si[k]; } - int rem = min(diff, dx2); + int rem = std::min(diff, dx2); for( k=0; k < rem*cn; k++, j++ ) { if( borderType != BORDER_CONSTANT ) @@ -1311,7 +1311,7 @@ void blockSum(const Mat& _src, Mat& _dst, Size ksize, Point anchor, const Size & int dx1 = std::max(anchor.x - roi.x, 0); int dx2 = std::max(kwidth - anchor.x - 1 + roi.x + roi.width - wholeSize.width, 0); int dy2 = std::max(kheight - anchor.y - 1 + roi.y + roi.height - wholeSize.height, 0); - int borderLeft = min(dx1, width)*cn; + int borderLeft = std::min(dx1, width)*cn; int bufWidth = (width1+borderLeft+VEC_ALIGN); int bufStep = bufWidth*besz; diff --git a/modules/imgproc/src/canny.cpp b/modules/imgproc/src/canny.cpp index 22f7a9c1d1..60d2227273 100644 --- a/modules/imgproc/src/canny.cpp +++ b/modules/imgproc/src/canny.cpp @@ -281,7 +281,7 @@ public: Mat dx, dy; AutoBuffer dxMax(0), dyMax(0); std::deque stack, borderPeaksLocal; - const int rowStart = max(0, boundaries.start - 1), rowEnd = min(src.rows, boundaries.end + 1); + const int rowStart = std::max(0, boundaries.start - 1), rowEnd = std::min(src.rows, boundaries.end + 1); int *_mag_p, *_mag_a, *_mag_n; short *_dx, *_dy, *_dx_a = NULL, *_dy_a = NULL, *_dx_n = NULL, *_dy_n = NULL; uchar *_pmap; diff --git a/modules/imgproc/src/color_lab.cpp b/modules/imgproc/src/color_lab.cpp index 57b11305f1..bf6fc0da3f 100644 --- a/modules/imgproc/src/color_lab.cpp +++ b/modules/imgproc/src/color_lab.cpp @@ -1084,9 +1084,9 @@ static int * initLUTforABXZ() inline void fill_one(int16_t *LAB, const int16_t *LAB_prev, int16_t *LUV, const int16_t *LUV_prev, int p, int q, int r, int _p, int _q, int _r) { int idxold = 0; - idxold += min(p+(_p), (int)(LAB_LUT_DIM-1))*3; - idxold += min(q+(_q), (int)(LAB_LUT_DIM-1))*LAB_LUT_DIM*3; - idxold += min(r+(_r), (int)(LAB_LUT_DIM-1))*LAB_LUT_DIM*LAB_LUT_DIM*3; + idxold += std::min(p+(_p), (int)(LAB_LUT_DIM-1))*3; + idxold += std::min(q+(_q), (int)(LAB_LUT_DIM-1))*LAB_LUT_DIM*3; + idxold += std::min(r+(_r), (int)(LAB_LUT_DIM-1))*LAB_LUT_DIM*LAB_LUT_DIM*3; int idxnew = p*3*8 + q*LAB_LUT_DIM*3*8 + r*LAB_LUT_DIM*LAB_LUT_DIM*3*8+4*(_p)+2*(_q)+(_r); LAB[idxnew] = LAB_prev[idxold]; LAB[idxnew+8] = LAB_prev[idxold+1]; @@ -1948,8 +1948,8 @@ struct RGB2Lab_f if(bIdx) { - swap(rvec0, bvec0); - swap(rvec1, bvec1); + std::swap(rvec0, bvec0); + std::swap(rvec1, bvec1); } v_float32 zerof = vx_setzero_f32(), onef = vx_setall_f32(1.0f); @@ -2448,9 +2448,9 @@ struct Lab2RGBinteger go = CV_DESCALE(C3 * x + C4 * y + C5 * z, shift); bo = CV_DESCALE(C6 * x + C7 * y + C8 * z, shift); - ro = max(0, min((int)INV_GAMMA_TAB_SIZE-1, ro)); - go = max(0, min((int)INV_GAMMA_TAB_SIZE-1, go)); - bo = max(0, min((int)INV_GAMMA_TAB_SIZE-1, bo)); + ro = std::clamp(ro, 0, (int)INV_GAMMA_TAB_SIZE-1); + go = std::clamp(go, 0, (int)INV_GAMMA_TAB_SIZE-1); + bo = std::clamp(bo, 0, (int)INV_GAMMA_TAB_SIZE-1); if(issRGB) { @@ -3292,7 +3292,7 @@ struct RGB2Luvinterpolate if(bIdx) { - swap(r, b); + std::swap(r, b); } /* @@ -3587,7 +3587,7 @@ struct Luv2RGBinteger int z = zm/256 + zm/65536; //limit X, Y, Z to [0, 2] to fit white point - x = max(0, min(2*BASE, x)); z = max(0, min(2*BASE, z)); + x = std::clamp(x, 0, 2*BASE); z = std::clamp(z, 0, 2*BASE); int C0 = coeffs[0], C1 = coeffs[1], C2 = coeffs[2]; int C3 = coeffs[3], C4 = coeffs[4], C5 = coeffs[5]; @@ -3597,9 +3597,9 @@ struct Luv2RGBinteger go = CV_DESCALE(C3 * x + C4 * y + C5 * z, shift); bo = CV_DESCALE(C6 * x + C7 * y + C8 * z, shift); - ro = max(0, min((int)INV_GAMMA_TAB_SIZE-1, ro)); - go = max(0, min((int)INV_GAMMA_TAB_SIZE-1, go)); - bo = max(0, min((int)INV_GAMMA_TAB_SIZE-1, bo)); + ro = std::clamp(ro, 0, (int)INV_GAMMA_TAB_SIZE-1); + go = std::clamp(go, 0, (int)INV_GAMMA_TAB_SIZE-1); + bo = std::clamp(bo, 0, (int)INV_GAMMA_TAB_SIZE-1); if(issRGB) { diff --git a/modules/imgproc/src/drawing_text.cpp b/modules/imgproc/src/drawing_text.cpp index 22698b4e04..0cde4c239e 100644 --- a/modules/imgproc/src/drawing_text.cpp +++ b/modules/imgproc/src/drawing_text.cpp @@ -712,16 +712,16 @@ compressCharacter(const uchar* bitmap_buf, { if(bitmap_buf[i*bitmap_step + j] != 0) { - left = min(left, j); - right = max(right, j); + left = std::min(left, j); + right = std::max(right, j); have_nz = true; } } if( have_nz ) { global_have_nz |= have_nz; - top = min(top, i); - bottom = max(bottom, i); + top = std::min(top, i); + bottom = std::max(bottom, i); } } // all 0's @@ -800,7 +800,7 @@ compressCharacter(const uchar* bitmap_buf, buf[k++] = 0; while(count > 0) { - int dcount = min(count, RLE_MAX); + int dcount = std::min(count, RLE_MAX); count -= dcount; buf[k++] = (uchar)dcount; if(count > 0) @@ -818,7 +818,7 @@ compressCharacter(const uchar* bitmap_buf, { while(count > 0) { - int dcount = min(count, RLE_MAX); + int dcount = std::min(count, RLE_MAX); count -= dcount; buf[k++] = (uchar)dcount; if(count > 0) @@ -1486,7 +1486,7 @@ Point FontRenderEngine::putText_( int dx = roundFixPt(pos.x_advance, FRAC_BITS); int dy = roundFixPt(pos.y_advance, FRAC_BITS); int new_pen_x = pen.x + dx*alignSign; - nextline_dy = max(nextline_dy, cached->linegap); + nextline_dy = std::max(nextline_dy, cached->linegap); // TODO: this wrapping algorithm is quite dumb, // preferably should split text at word boundary if( wrap && imgsize.width > 0 && new_pen_x*alignSign > x1*alignSign ) diff --git a/modules/imgproc/src/fisheye.cpp b/modules/imgproc/src/fisheye.cpp index ea3cb826a8..4550475d8e 100644 --- a/modules/imgproc/src/fisheye.cpp +++ b/modules/imgproc/src/fisheye.cpp @@ -81,7 +81,7 @@ void initUndistortRectifyMap( InputArray K, InputArray D, InputArray R, InputArr { double x = _x/_w, y = _y/_w; - double r = sqrt(x*x + y*y); + double r = std::sqrt(x*x + y*y); double theta = std::atan(r); double theta2 = theta*theta, theta4 = theta2*theta2, theta6 = theta4*theta2, theta8 = theta4*theta4; diff --git a/modules/imgproc/src/hough.cpp b/modules/imgproc/src/hough.cpp index e9c734c44e..678a5c0861 100644 --- a/modules/imgproc/src/hough.cpp +++ b/modules/imgproc/src/hough.cpp @@ -798,7 +798,7 @@ static bool ocl_makePointsList(InputArray _src, OutputArray _pointsList, InputOu ocl::Device dev = ocl::Device::getDefault(); const int pixPerWI = 16; - int workgroup_size = min((int) dev.maxWorkGroupSize(), (src.cols + pixPerWI - 1)/pixPerWI); + int workgroup_size = std::min((int) dev.maxWorkGroupSize(), (src.cols + pixPerWI - 1)/pixPerWI); ocl::Kernel pointListKernel("make_point_list", ocl::imgproc::hough_lines_oclsrc, format("-D MAKE_POINTS_LIST -D GROUP_SIZE=%d -D LOCAL_SIZE=%d", workgroup_size, src.cols)); if (pointListKernel.empty()) @@ -821,7 +821,7 @@ static bool ocl_fillAccum(InputArray _pointsList, OutputArray _accum, int total_ ocl::Device dev = ocl::Device::getDefault(); float irho = (float) (1 / rho); - int workgroup_size = min((int) dev.maxWorkGroupSize(), total_points); + int workgroup_size = std::min((int) dev.maxWorkGroupSize(), total_points); ocl::Kernel fillAccumKernel; size_t localThreads[2]; @@ -896,7 +896,7 @@ static bool ocl_HoughLines(InputArray _src, OutputArray _lines, double rho, doub if (getLinesKernel.empty()) return false; - int linesMax = threshold > 0 ? min(total_points*numangle/threshold, OCL_MAX_LINES) : OCL_MAX_LINES; + int linesMax = threshold > 0 ? std::min(total_points*numangle/threshold, OCL_MAX_LINES) : OCL_MAX_LINES; UMat lines(linesMax, 1, CV_32FC2); getLinesKernel.args(ocl::KernelArg::ReadOnly(accum), ocl::KernelArg::WriteOnlyNoSize(lines), @@ -906,7 +906,7 @@ static bool ocl_HoughLines(InputArray _src, OutputArray _lines, double rho, doub if (!getLinesKernel.run(2, globalThreads, NULL, false)) return false; - int total_lines = min(counters.getMat(ACCESS_READ).at(0, 1), linesMax); + int total_lines = std::min(counters.getMat(ACCESS_READ).at(0, 1), linesMax); if (total_lines > 0) _lines.assign(lines.rowRange(Range(0, total_lines))); else @@ -949,7 +949,7 @@ static bool ocl_HoughLinesP(InputArray _src, OutputArray _lines, double rho, dou if (getLinesKernel.empty()) return false; - int linesMax = threshold > 0 ? min(total_points*numangle/threshold, OCL_MAX_LINES) : OCL_MAX_LINES; + int linesMax = threshold > 0 ? std::min(total_points*numangle/threshold, OCL_MAX_LINES) : OCL_MAX_LINES; UMat lines(linesMax, 1, CV_32SC4); getLinesKernel.args(ocl::KernelArg::ReadOnly(accum), ocl::KernelArg::ReadOnly(src), @@ -960,7 +960,7 @@ static bool ocl_HoughLinesP(InputArray _src, OutputArray _lines, double rho, dou if (!getLinesKernel.run(2, globalThreads, NULL, false)) return false; - int total_lines = min(counters.getMat(ACCESS_READ).at(0, 1), linesMax); + int total_lines = std::min(counters.getMat(ACCESS_READ).at(0, 1), linesMax); if (total_lines > 0) _lines.assign(lines.rowRange(Range(0, total_lines))); else @@ -1358,8 +1358,8 @@ public: std::vector centersLocal; bool singleThread = (boundaries == Range(1, accum.rows - 1)); - startRow = max(1, startRow); - endRow = min(arows - 1, endRow); + startRow = std::max(1, startRow); + endRow = std::min(arows - 1, endRow); //Find possible circle centers for(int y = startRow; y < endRow; ++y ) @@ -1728,7 +1728,7 @@ static void HoughCirclesGradient(InputArray _image, OutputArray _circles, { CV_Assert(kernelSize == -1 || kernelSize == 3 || kernelSize == 5 || kernelSize == 7); - dp = max(dp, 1.f); + dp = std::max(dp, 1.f); float idp = 1.f/dp; Mat edges, dx, dy; diff --git a/modules/imgproc/src/lsd.cpp b/modules/imgproc/src/lsd.cpp index bbe9d11373..a8d7885a8d 100644 --- a/modules/imgproc/src/lsd.cpp +++ b/modules/imgproc/src/lsd.cpp @@ -458,7 +458,7 @@ void LineSegmentDetectorImpl::flsd(std::vector& lines, Mat gaussian_img; const double sigma = (SCALE < 1)?(SIGMA_SCALE / SCALE):(SIGMA_SCALE); const double sprec = 3; - const unsigned int h = (unsigned int)(ceil(sigma * sqrt(2 * sprec * log(10.0)))); + const unsigned int h = (unsigned int)(ceil(sigma * std::sqrt(2 * sprec * std::log(10.0)))); Size ksize(1 + 2 * h, 1 + 2 * h); // kernel size GaussianBlur(image, gaussian_img, ksize, sigma); // Scale image to needed size @@ -735,7 +735,7 @@ double LineSegmentDetectorImpl::get_theta(const std::vector& reg, c CV_Assert(!(double_equal(Ixx, 0) && double_equal(Iyy, 0) && double_equal(Ixy, 0))); // Compute smallest eigenvalue - double lambda = 0.5 * (Ixx + Iyy - sqrt((Ixx - Iyy) * (Ixx - Iyy) + 4.0 * Ixy * Ixy)); + double lambda = 0.5 * (Ixx + Iyy - std::sqrt((Ixx - Iyy) * (Ixx - Iyy) + 4.0 * Ixy * Ixy)); // Compute angle double theta = (fabs(Ixx)>fabs(Iyy))? @@ -778,7 +778,7 @@ bool LineSegmentDetectorImpl::refine(std::vector& reg, double reg_a CV_Assert(n > 0); double mean_angle = sum / double(n); // 2 * standard deviation - double tau = 2.0 * sqrt((s_sum - 2.0 * mean_angle * sum) / double(n) + mean_angle * mean_angle); + double tau = 2.0 * std::sqrt((s_sum - 2.0 * mean_angle * sum) / double(n) + mean_angle * mean_angle); // Try new region region_grow(Point(reg[0].x, reg[0].y), reg, reg_angle, tau); @@ -1017,8 +1017,8 @@ double LineSegmentDetectorImpl::nfa(const int& n, const int& k, const double& p) double log1term = log_gamma(double(n) + 1) - log_gamma(double(k) + 1) - log_gamma(double(n-k) + 1) - + double(k) * log(p) + double(n-k) * log(1.0 - p); - double term = exp(log1term); + + double(k) * std::log(p) + double(n-k) * std::log(1.0 - p); + double term = std::exp(log1term); if(double_equal(term, 0)) { diff --git a/modules/imgproc/src/resize.cpp b/modules/imgproc/src/resize.cpp index e27e332200..66f4ef22bc 100644 --- a/modules/imgproc/src/resize.cpp +++ b/modules/imgproc/src/resize.cpp @@ -608,12 +608,12 @@ public: else { *offset = maxsize - 1; - maxofst = min(maxofst, val); + maxofst = std::min(maxofst, val); } } else { - minofst = max(minofst, val + 1); + minofst = std::max(minofst, val + 1); } } void getMinMax(int &min, int &max) @@ -648,8 +648,8 @@ public: AutoBuffer linebuf(interp_y_len * dst_width * cn); int last_eval = - interp_y_len; int evalbuf_start = 0; - int rmin_y = max(min_y, range.start); - int rmax_y = min(max_y, range.end); + int rmin_y = std::max(min_y, range.start); + int rmax_y = std::min(max_y, range.end); if (range.start < min_y) { last_eval = 1 - interp_y_len; @@ -664,9 +664,9 @@ public: int &iy = yoffsets[dy]; int i; - for (i = max(iy, last_eval + interp_y_len); i < min(iy + interp_y_len, src_height); i++, evalbuf_start = (evalbuf_start + 1) % interp_y_len) + for (i = std::max(iy, last_eval + interp_y_len); i < std::min(iy + interp_y_len, src_height); i++, evalbuf_start = (evalbuf_start + 1) % interp_y_len) hResize((ET*)(src + i * src_step), cn, xoffsets, xcoeffs, linebuf.data() + evalbuf_start*(dst_width * cn), min_x, max_x, dst_width); - evalbuf_start = (evalbuf_start + max(iy, src_height - interp_y_len) - max(last_eval, src_height - interp_y_len)) % interp_y_len; + evalbuf_start = (evalbuf_start + std::max(iy, src_height - interp_y_len) - std::max(last_eval, src_height - interp_y_len)) % interp_y_len; last_eval = iy; fixedpoint curcoeffs[interp_y_len]; @@ -2971,7 +2971,7 @@ static int computeResizeAreaTabImpl( int ssize, int dsize, int cn, double scale, emit(sx, float(1.0 / cellWidth)); if( fsx2 - sx2 > 1e-3 ) - emit(sx2, (float)(std::min(std::min(fsx2 - sx2, 1.), cellWidth) / cellWidth)); + emit(sx2, (float)(std::min({fsx2 - sx2, 1., cellWidth}) / cellWidth)); } if constexpr (OCL) ofs_tab[dsize] = k; return k; diff --git a/modules/imgproc/src/smooth.simd.hpp b/modules/imgproc/src/smooth.simd.hpp index 6509ab532b..922a031db6 100644 --- a/modules/imgproc/src/smooth.simd.hpp +++ b/modules/imgproc/src/smooth.simd.hpp @@ -619,7 +619,7 @@ void inline smooth3N121Impl(const ET* src, int cn, ET *dst, int ito, int idst, int v = idst - 1; int len = (width - offset) * cn; int x = offset * cn; - int maxRow = min((ito - vOffset),height-vOffset); + int maxRow = std::min((ito - vOffset),height-vOffset); if (v >= maxRow) return; #if (CV_SIMD || CV_SIMD_SCALABLE) @@ -714,7 +714,7 @@ void inline smooth5N14641Impl(const ET* src, int cn, ET* dst, int ito, int idst, int v = idst - 2; int len = (width - offset) * cn; int x = offset * cn; - int maxRow = min((ito - vOffset),height-vOffset); + int maxRow = std::min((ito - vOffset),height-vOffset); if (v >= maxRow) return; #if (CV_SIMD || CV_SIMD_SCALABLE) @@ -1284,7 +1284,7 @@ void hlineSmooth(const ET* src, int cn, const FT* m, int n, FT* dst, int len, in int pre_shift = n / 2; int post_shift = n - pre_shift; int i = 0; - for (; i < min(pre_shift, len); i++, dst += cn) // Points that fall left from border + for (; i < std::min(pre_shift, len); i++, dst += cn) // Points that fall left from border { for (int k = 0; k < cn; k++) dst[k] = m[pre_shift-i] * src[k]; @@ -1296,7 +1296,7 @@ void hlineSmooth(const ET* src, int cn, const FT* m, int n, FT* dst, int len, in dst[k] = dst[k] + m[mid] * src[src_idx*cn + k]; } int j, mid; - for (j = 1, mid = pre_shift - i + 1; j < min(i + post_shift, len); j++, mid++) + for (j = 1, mid = pre_shift - i + 1; j < std::min(i + post_shift, len); j++, mid++) for (int k = 0; k < cn; k++) dst[k] = dst[k] + m[mid] * src[j*cn + k]; if (borderType != BORDER_CONSTANT) @@ -1338,7 +1338,7 @@ void hlineSmooth(const uint8_t* src, int cn, const ufixe int pre_shift = n / 2; int post_shift = n - pre_shift; int i = 0; - for (; i < min(pre_shift, len); i++, dst += cn) // Points that fall left from border + for (; i < std::min(pre_shift, len); i++, dst += cn) // Points that fall left from border { for (int k = 0; k < cn; k++) dst[k] = m[pre_shift - i] * src[k]; @@ -1350,7 +1350,7 @@ void hlineSmooth(const uint8_t* src, int cn, const ufixe dst[k] = dst[k] + m[mid] * src[src_idx*cn + k]; } int j, mid; - for (j = 1, mid = pre_shift - i + 1; j < min(i + post_shift, len); j++, mid++) + for (j = 1, mid = pre_shift - i + 1; j < std::min(i + post_shift, len); j++, mid++) for (int k = 0; k < cn; k++) dst[k] = dst[k] + m[mid] * src[j*cn + k]; if (borderType != BORDER_CONSTANT) @@ -1403,7 +1403,7 @@ void hlineSmoothONa_yzy_a(const ET* src, int cn, const FT* m, int n, FT* dst, in int pre_shift = n / 2; int post_shift = n - pre_shift; int i = 0; - for (; i < min(pre_shift, len); i++, dst += cn) // Points that fall left from border + for (; i < std::min(pre_shift, len); i++, dst += cn) // Points that fall left from border { for (int k = 0; k < cn; k++) dst[k] = m[pre_shift - i] * src[k]; @@ -1415,7 +1415,7 @@ void hlineSmoothONa_yzy_a(const ET* src, int cn, const FT* m, int n, FT* dst, in dst[k] = dst[k] + m[mid] * src[src_idx*cn + k]; } int j, mid; - for (j = 1, mid = pre_shift - i + 1; j < min(i + post_shift, len); j++, mid++) + for (j = 1, mid = pre_shift - i + 1; j < std::min(i + post_shift, len); j++, mid++) for (int k = 0; k < cn; k++) dst[k] = dst[k] + m[mid] * src[j*cn + k]; if (borderType != BORDER_CONSTANT) @@ -1457,7 +1457,7 @@ void hlineSmoothONa_yzy_a(const uint8_t* src, int cn, co int pre_shift = n / 2; int post_shift = n - pre_shift; int i = 0; - for (; i < min(pre_shift, len); i++, dst += cn) // Points that fall left from border + for (; i < std::min(pre_shift, len); i++, dst += cn) // Points that fall left from border { for (int k = 0; k < cn; k++) dst[k] = m[pre_shift - i] * src[k]; @@ -1469,7 +1469,7 @@ void hlineSmoothONa_yzy_a(const uint8_t* src, int cn, co dst[k] = dst[k] + m[mid] * src[src_idx*cn + k]; } int j, mid; - for (j = 1, mid = pre_shift - i + 1; j < min(i + post_shift, len); j++, mid++) + for (j = 1, mid = pre_shift - i + 1; j < std::min(i + post_shift, len); j++, mid++) for (int k = 0; k < cn; k++) dst[k] = dst[k] + m[mid] * src[j*cn + k]; if (borderType != BORDER_CONSTANT) @@ -1522,7 +1522,7 @@ void hlineSmoothONa_yzy_a(const uint16_t* src, int cn, int pre_shift = n / 2; int post_shift = n - pre_shift; int i = 0; - for (; i < min(pre_shift, len); i++, dst += cn) // Points that fall left from border + for (; i < std::min(pre_shift, len); i++, dst += cn) // Points that fall left from border { for (int k = 0; k < cn; k++) dst[k] = m[pre_shift - i] * src[k]; @@ -1534,7 +1534,7 @@ void hlineSmoothONa_yzy_a(const uint16_t* src, int cn, dst[k] = dst[k] + m[mid] * src[src_idx*cn + k]; } int j, mid; - for (j = 1, mid = pre_shift - i + 1; j < min(i + post_shift, len); j++, mid++) + for (j = 1, mid = pre_shift - i + 1; j < std::min(i + post_shift, len); j++, mid++) for (int k = 0; k < cn; k++) dst[k] = dst[k] + m[mid] * src[j*cn + k]; if (borderType != BORDER_CONSTANT) @@ -1669,7 +1669,7 @@ void vlineSmooth3N(const ufixedpoint16* const * src, con std::memcpy(&val01, m, sizeof(val01)); v_int16 v_mul01 = v_reinterpret_as_s16(vx_setall_u32(val01)); v_int16 v_mul2 = v_reinterpret_as_s16(vx_setall_u16(*((uint16_t*)(m + 2)))); - for (; i <= min(len - 4*VECSZ, len-kcn); i += 4*VECSZ) + for (; i <= std::min(len - 4*VECSZ, len-kcn); i += 4*VECSZ) { v_int16 v_src00, v_src10, v_src01, v_src11, v_src02, v_src12, v_src03, v_src13; v_int16 v_tmp0, v_tmp1; @@ -1762,7 +1762,7 @@ void vlineSmooth3N121(const ufixedpoint16* const * src, { #if (CV_SIMD || CV_SIMD_SCALABLE) const int VECSZ = VTraits::vlanes(); - for (; i <= min(len - 2*VECSZ, len-kcn); i += 2*VECSZ) + for (; i <= std::min(len - 2*VECSZ, len-kcn); i += 2*VECSZ) { v_uint32 v_src00, v_src01, v_src02, v_src03, v_src10, v_src11, v_src12, v_src13, v_src20, v_src21, v_src22, v_src23; v_expand(vx_load((uint16_t*)(src[0]) + i), v_src00, v_src01); @@ -1792,7 +1792,7 @@ void vlineSmooth3N121(const ufixedpoint32* const * src, { #if (CV_SIMD || CV_SIMD_SCALABLE) const int VECSZ = VTraits::vlanes(); - for (; i <= min(len - 2*VECSZ, len-kcn); i += 2*VECSZ) + for (; i <= std::min(len - 2*VECSZ, len-kcn); i += 2*VECSZ) { v_uint64 v_src00, v_src01, v_src02, v_src03, v_src10, v_src11, v_src12, v_src13, v_src20, v_src21, v_src22, v_src23; v_expand(vx_load((uint32_t*)(src[0]) + i), v_src00, v_src01); @@ -1847,7 +1847,7 @@ void vlineSmooth5N(const ufixedpoint16* const * src, con v_int16 v_mul01 = v_reinterpret_as_s16(vx_setall_u32(*((uint32_t*)m))); v_int16 v_mul23 = v_reinterpret_as_s16(vx_setall_u32(*((uint32_t*)(m + 2)))); v_int16 v_mul4 = v_reinterpret_as_s16(vx_setall_u16(*((uint16_t*)(m + 4)))); - for (; i <= min(len - 4*VECSZ, len-kcn); i += 4*VECSZ) + for (; i <= std::min(len - 4*VECSZ, len-kcn); i += 4*VECSZ) { v_int16 v_src00, v_src10, v_src01, v_src11, v_src02, v_src12, v_src03, v_src13; v_int16 v_tmp0, v_tmp1; @@ -1967,7 +1967,7 @@ void vlineSmooth5N14641(const ufixedpoint16* const * src #if (CV_SIMD || CV_SIMD_SCALABLE) v_uint32 v_6 = vx_setall_u32(6); const int VECSZ = VTraits::vlanes(); - for (; i <= min(len - 2*VECSZ, len-kcn); i += 2*VECSZ) + for (; i <= std::min(len - 2*VECSZ, len-kcn); i += 2*VECSZ) { v_uint32 v_src00, v_src10, v_src20, v_src30, v_src40; v_uint32 v_src01, v_src11, v_src21, v_src31, v_src41; @@ -2011,7 +2011,7 @@ void vlineSmooth5N14641(const ufixedpoint32* const * sr { #if (CV_SIMD || CV_SIMD_SCALABLE) const int VECSZ = VTraits::vlanes(); - for (; i <= min(len - 2*VECSZ, len-kcn); i += 2*VECSZ) + for (; i <= std::min(len - 2*VECSZ, len-kcn); i += 2*VECSZ) { v_uint64 v_src00, v_src10, v_src20, v_src30, v_src40; v_uint64 v_src01, v_src11, v_src21, v_src31, v_src41; @@ -2108,7 +2108,7 @@ void vlineSmooth(const ufixedpoint16* const * src, const ufixedpoint32 val[] = { msum * ufixedpoint16((uint8_t)128) }; v_128_4 = vx_setall_s32(*((int32_t*)val)); } - for (; i <= min(len - 4*VECSZ, len-kcn); i += 4*VECSZ) + for (; i <= std::min(len - 4*VECSZ, len-kcn); i += 4*VECSZ) { v_int16 v_src00, v_src10, v_src01, v_src11, v_src02, v_src12, v_src03, v_src13; v_int16 v_tmp0, v_tmp1; @@ -2537,11 +2537,11 @@ public: int post_shift = kylen - pre_shift - 1; // First line evaluation int idst = range.start; - int ifrom = max(0, idst - pre_shift); + int ifrom = std::max(0, idst - pre_shift); int ito = idst + post_shift + 1; int i = ifrom; int bufline = 0; - for (; i < min(ito, height); i++, bufline++) + for (; i < std::min(ito, height); i++, bufline++) { ptrs[bufline+kylen] = ptrs[bufline] = buf + bufline * width*cn; hlineSmoothFunc(src + i * src_stride, cn, kx, kxlen, ptrs[bufline], width, borderType, true); @@ -2576,8 +2576,8 @@ public: // border mode dependent part evaluation // i points to last src row to evaluate in convolution - bufline %= kylen; ito = min(height, range.end + post_shift); - for (; i < min(kylen, ito); i++, idst++) + bufline %= kylen; ito = std::min(height, range.end + post_shift); + for (; i < std::min(kylen, ito); i++, idst++) { ptrs[bufline + kylen] = ptrs[bufline] = buf + bufline * width*cn; hlineSmoothFunc(src + i * src_stride, cn, kx, kxlen, ptrs[bufline], width, borderType, true); @@ -2606,8 +2606,8 @@ public: // First line evaluation int idst = range.start; int ifrom = idst - pre_shift; - int ito = min(idst + post_shift + 1, height); - int i = max(0, ifrom); + int ito = std::min(idst + post_shift + 1, height); + int i = std::max(0, ifrom); int bufline = 0; for (; i < ito; i++, bufline++) { @@ -2616,19 +2616,19 @@ public: } if (bufline == 1) - vlineSmooth1N(ptrs, ky - min(ifrom, 0), bufline, dst + idst*dst_stride, width*cn, cn, true); + vlineSmooth1N(ptrs, ky - std::min(ifrom, 0), bufline, dst + idst*dst_stride, width*cn, cn, true); else if (bufline == 3) - vlineSmooth3N(ptrs, ky - min(ifrom, 0), bufline, dst + idst*dst_stride, width*cn, cn, true); + vlineSmooth3N(ptrs, ky - std::min(ifrom, 0), bufline, dst + idst*dst_stride, width*cn, cn, true); else if (bufline == 5) - vlineSmooth5N(ptrs, ky - min(ifrom, 0), bufline, dst + idst*dst_stride, width*cn, cn, true); + vlineSmooth5N(ptrs, ky - std::min(ifrom, 0), bufline, dst + idst*dst_stride, width*cn, cn, true); else - vlineSmooth(ptrs, ky - min(ifrom, 0), bufline, dst + idst*dst_stride, width*cn, cn, true); + vlineSmooth(ptrs, ky - std::min(ifrom, 0), bufline, dst + idst*dst_stride, width*cn, cn, true); idst++; // border mode dependent part evaluation // i points to last src row to evaluate in convolution - bufline %= kylen; ito = min(height, range.end + post_shift); - for (; i < min(kylen, ito); i++, idst++) + bufline %= kylen; ito = std::min(height, range.end + post_shift); + for (; i < std::min(kylen, ito); i++, idst++) { ptrs[bufline + kylen] = ptrs[bufline] = buf + bufline * width*cn; hlineSmoothFunc(src + i * src_stride, cn, kx, kxlen, ptrs[bufline], width, borderType, true); @@ -2642,7 +2642,7 @@ public: bufline %= kylen; } // Points inside the border - if (i - max(0, ifrom) >= kylen) + if (i - std::max(0, ifrom) >= kylen) { computeInnerRegion(idst, i, ito, bufline, ptrs); @@ -2660,7 +2660,7 @@ public: else { // i points to first src row to evaluate in convolution - for (i = idst - pre_shift; i < min(range.end - pre_shift, 0); i++, idst++) + for (i = idst - pre_shift; i < std::min(range.end - pre_shift, 0); i++, idst++) if (height == 3) vlineSmooth3N(ptrs, ky - i, height, dst + idst*dst_stride, width*cn, cn, true); else if (height == 5) @@ -2669,11 +2669,11 @@ public: vlineSmooth(ptrs, ky - i, height, dst + idst*dst_stride, width*cn, cn, true); for (; i < range.end - pre_shift; i++, idst++) if (height - i == 3) - vlineSmooth3N(ptrs + i - max(0, ifrom), ky, height - i, dst + idst*dst_stride, width*cn, cn, true); + vlineSmooth3N(ptrs + i - std::max(0, ifrom), ky, height - i, dst + idst*dst_stride, width*cn, cn, true); else if (height - i == 5) - vlineSmooth5N(ptrs + i - max(0, ifrom), ky, height - i, dst + idst*dst_stride, width*cn, cn, true); + vlineSmooth5N(ptrs + i - std::max(0, ifrom), ky, height - i, dst + idst*dst_stride, width*cn, cn, true); else - vlineSmooth(ptrs + i - max(0, ifrom), ky, height - i, dst + idst*dst_stride, width*cn, cn, true); + vlineSmooth(ptrs + i - std::max(0, ifrom), ky, height - i, dst + idst*dst_stride, width*cn, cn, true); } } } diff --git a/modules/objdetect/src/aruco/apriltag/apriltag_quad_thresh.cpp b/modules/objdetect/src/aruco/apriltag/apriltag_quad_thresh.cpp index 41e6852609..914cfe73ad 100644 --- a/modules/objdetect/src/aruco/apriltag/apriltag_quad_thresh.cpp +++ b/modules/objdetect/src/aruco/apriltag/apriltag_quad_thresh.cpp @@ -330,7 +330,7 @@ int quad_segment_maxima(const DetectorParameters &td, int sz, struct line_fit_pt // XXX Tunable (though not super useful to change) double cutoff = 0.05; - int fsz = cvFloor(sqrt(-log(cutoff)*2*sigma*sigma)) + 1; + int fsz = cvFloor(std::sqrt(-std::log(cutoff)*2*sigma*sigma)) + 1; fsz = 2*fsz + 1; // For default values of cutoff = 0.05, sigma = 3, @@ -339,7 +339,7 @@ int quad_segment_maxima(const DetectorParameters &td, int sz, struct line_fit_pt for (int i = 0; i < fsz; i++) { int j = i - fsz / 2; - f[i] = (float)exp(-j*j/(2*sigma*sigma)); + f[i] = (float)std::exp(-j*j/(2*sigma*sigma)); } for (int iy = 0; iy < sz; iy++) { @@ -793,7 +793,7 @@ int fit_quad(const DetectorParameters &_params, const Mat im, zarray_t *cluster, im.data[(iy-1) * im.cols + ix]; // XXX Tunable. How to shape the gradient magnitude? - W = sqrt(grad_x*grad_x + grad_y*grad_y) + 1; + W = std::sqrt(grad_x*grad_x + grad_y*grad_y) + 1; } double fx = x, fy = y; @@ -936,11 +936,11 @@ int fit_quad(const DetectorParameters &_params, const Mat im, zarray_t *cluster, sq1 = sq1 * sq1; double sq2 = quad->p[idxb][1] - quad->p[idxa][1]; sq2 = sq2 * sq2; - length[i] = sqrt(sq1 + sq2); + length[i] = std::sqrt(sq1 + sq2); } p = (length[0] + length[1] + length[2]) / 2; - area += sqrt(p*(p-length[0])*(p-length[1])*(p-length[2])); + area += std::sqrt(p*(p-length[0])*(p-length[1])*(p-length[2])); // get area of triangle formed by points 2, 3, 0, 2 for (int i = 0; i < 3; i++) { @@ -954,11 +954,11 @@ int fit_quad(const DetectorParameters &_params, const Mat im, zarray_t *cluster, sq1 = sq1 * sq1; double sq2 = quad->p[idxb][1] - quad->p[idxa][1]; sq2 = sq2 * sq2; - length[i] = sqrt(sq1 + sq2); + length[i] = std::sqrt(sq1 + sq2); } p = (length[0] + length[1] + length[2]) / 2; - area += sqrt(p*(p-length[0])*(p-length[1])*(p-length[2])); + area += std::sqrt(p*(p-length[0])*(p-length[1])*(p-length[2])); // we don't actually know the family yet (quad detection is generic.) // This threshold is based on a 6x6 tag (which is actually 8x8) diff --git a/modules/objdetect/src/aruco/aruco_board.cpp b/modules/objdetect/src/aruco/aruco_board.cpp index 0c613fdd18..935cfcbe11 100644 --- a/modules/objdetect/src/aruco/aruco_board.cpp +++ b/modules/objdetect/src/aruco/aruco_board.cpp @@ -89,10 +89,10 @@ void Board::Impl::generateImage(Size outSize, OutputArray img, int marginSize, i for(unsigned int i = 0; i < objPoints.size(); i++) { for(int j = 0; j < 4; j++) { - minX = min(minX, objPoints[i][j].x); - maxX = max(maxX, objPoints[i][j].x); - minY = min(minY, objPoints[i][j].y); - maxY = max(maxY, objPoints[i][j].y); + minX = std::min(minX, objPoints[i][j].x); + maxX = std::max(maxX, objPoints[i][j].x); + minY = std::min(minY, objPoints[i][j].y); + maxY = std::max(maxY, objPoints[i][j].y); } } @@ -395,7 +395,7 @@ void CharucoBoardImpl::calcNearestMarkerCorners() { double sqDistance; Point3f distVector = charucoCorner - center; sqDistance = distVector.x * distVector.x + distVector.y * distVector.y; - if(j == 0 || fabs(sqDistance - minDist) < cv::pow(0.01 * squareLength, 2)) { + if(j == 0 || fabs(sqDistance - minDist) < std::pow(0.01 * squareLength, 2)) { // if same minimum distance (or first iteration), add to nearestMarkerIdx vector nearestMarkerIdx[i].push_back(j); minDist = sqDistance; @@ -603,7 +603,7 @@ bool CharucoBoard::checkCharucoCornersCollinear(InputArray charucoIds) const { Vec testLine = point0.cross(point1); Vec testPoint(0, 0, 1); - double divisor = sqrt(testLine[0]*testLine[0] + testLine[1]*testLine[1]); + double divisor = std::sqrt(testLine[0]*testLine[0] + testLine[1]*testLine[1]); CV_Assert(divisor != 0.0); // normalize the line with normal diff --git a/modules/objdetect/src/aruco/aruco_detector.cpp b/modules/objdetect/src/aruco/aruco_detector.cpp index 3fa882f704..f735556df3 100644 --- a/modules/objdetect/src/aruco/aruco_detector.cpp +++ b/modules/objdetect/src/aruco/aruco_detector.cpp @@ -138,9 +138,9 @@ static void _findMarkerContours(const Mat &in, vector > &candida // calculate maximum and minimum sizes in pixels unsigned int minPerimeterPixels = - (unsigned int)(minPerimeterRate * max(in.cols, in.rows)); + (unsigned int)(minPerimeterRate * std::max(in.cols, in.rows)); unsigned int maxPerimeterPixels = - (unsigned int)(maxPerimeterRate * max(in.cols, in.rows)); + (unsigned int)(maxPerimeterRate * std::max(in.cols, in.rows)); // for aruco3 functionality if (minSize != 0) { @@ -161,13 +161,13 @@ static void _findMarkerContours(const Mat &in, vector > &candida if(approxCurve.size() != 4 || !isContourConvex(approxCurve)) continue; // check min distance between corners - double minDistSq = max(in.cols, in.rows) * max(in.cols, in.rows); + double minDistSq = std::max(in.cols, in.rows) * std::max(in.cols, in.rows); for(int j = 0; j < 4; j++) { double d = (double)(approxCurve[j].x - approxCurve[(j + 1) % 4].x) * (double)(approxCurve[j].x - approxCurve[(j + 1) % 4].x) + (double)(approxCurve[j].y - approxCurve[(j + 1) % 4].y) * (double)(approxCurve[j].y - approxCurve[(j + 1) % 4].y); - minDistSq = min(minDistSq, d); + minDistSq = std::min(minDistSq, d); } double minCornerDistancePixels = double(contours[i].size()) * minCornerDistanceRate; if(minDistSq < minCornerDistancePixels * minCornerDistancePixels) continue; @@ -197,7 +197,7 @@ static void _reorderCandidatesCorners(vector > &candidates) { double crossProduct = (dx1 * dy2) - (dy1 * dx2); if(crossProduct < 0.0) { // not clockwise direction - swap(candidates[i][1], candidates[i][3]); + std::swap(candidates[i][1], candidates[i][3]); } } } @@ -205,7 +205,7 @@ static void _reorderCandidatesCorners(vector > &candidates) { static float getAverageModuleSize(const vector& markerCorners, int markerSize, int markerBorderBits) { float averageArucoModuleSize = 0.f; for (size_t i = 0ull; i < 4ull; i++) { - averageArucoModuleSize += sqrt(normL2Sqr(Point2f(markerCorners[i] - markerCorners[(i+1ull) % 4ull]))); + averageArucoModuleSize += std::sqrt(normL2Sqr(Point2f(markerCorners[i] - markerCorners[(i+1ull) % 4ull]))); } int numModules = markerSize + markerBorderBits * 2; averageArucoModuleSize /= ((float)markerCorners.size()*numModules); @@ -235,7 +235,7 @@ struct MarkerCandidateTree : MarkerCandidate{ contour = std::move(contour_); perimeter = 0.f; for (size_t i = 0ull; i < 4ull; i++) { - perimeter += sqrt(normL2Sqr(Point2f(corners[i] - corners[(i+1ull) % 4ull]))); + perimeter += std::sqrt(normL2Sqr(Point2f(corners[i] - corners[(i+1ull) % 4ull]))); } } @@ -258,9 +258,9 @@ float static inline getAverageDistance(const std::vector& marker1, cons distSq += normL2Sqr(marker1[modC] - marker2[c]); } distSq /= 4.f; - minDistSq = min(minDistSq, distSq); + minDistSq = std::min(minDistSq, distSq); } - return sqrt(minDistSq); + return std::sqrt(minDistSq); } /** @@ -463,7 +463,7 @@ static float _getMarkerConfidence(const Mat& groundTruthbits, const Mat &cellPix const float normalizedMarkerUnc = (tempInnerUnc + tempBorderUnc) / area; const float normalizedMarkerConfidence = 1.f - normalizedMarkerUnc; - return std::max(0.f, std::min(1.f, normalizedMarkerConfidence)); + return std::clamp(normalizedMarkerConfidence, 0.f, 1.f); } /** @@ -1039,7 +1039,7 @@ struct ArucoDetector::ArucoDetectorImpl { for (int j = i - 1; j >= 0; j--) { if (checkMarker1InMarker2(selectedCandidates[i].corners, selectedCandidates[j].corners)) { selectedCandidates[i].parent = j; - selectedCandidates[j].depth = max(selectedCandidates[j].depth, selectedCandidates[i].depth + 1); + selectedCandidates[j].depth = std::max(selectedCandidates[j].depth, selectedCandidates[i].depth + 1); break; } } @@ -1064,7 +1064,7 @@ struct ArucoDetector::ArucoDetectorImpl { int maxDepth = 0; for (size_t i = 0ull; i < selectedContours.size(); i++) - maxDepth = max(selectedContours[i].depth, maxDepth); + maxDepth = std::max(selectedContours[i].depth, maxDepth); vector> depths(maxDepth+1); for (size_t i = 0ull; i < selectedContours.size(); i++) { depths[selectedContours[i].depth].push_back(i); @@ -1158,7 +1158,7 @@ struct ArucoDetector::ArucoDetectorImpl { } else { int cornerRefinementWinSize = std::max(1, cvRound(detectorParams.relativeCornerRefinmentWinSize* getAverageModuleSize(candidates[i], dictionary.markerSize, detectorParams.markerBorderBits))); - cornerRefinementWinSize = min(cornerRefinementWinSize, detectorParams.cornerRefinementWinSize); + cornerRefinementWinSize = std::min(cornerRefinementWinSize, detectorParams.cornerRefinementWinSize); cornerSubPix(grey, Mat(candidates[i]), Size(cornerRefinementWinSize, cornerRefinementWinSize), Size(-1, -1), TermCriteria(TermCriteria::MAX_ITER | TermCriteria::EPS, detectorParams.cornerRefinementMaxIterations, @@ -1370,7 +1370,7 @@ void ArucoDetector::refineDetectedMarkers(InputArray _image, const Board& _board Point2f rejCorner = _rejectedCorners.getMat(j).ptr()[(c + k) % 4]; Point2f distVector = undetectedMarkersCorners[i][k] - rejCorner; double cornerDist = distVector.x * distVector.x + distVector.y * distVector.y; - currentMaxDistance = max(currentMaxDistance, cornerDist); + currentMaxDistance = std::max(currentMaxDistance, cornerDist); } // if distance is better than current best distance if(currentMaxDistance < closestCandidateDistance) { @@ -1433,7 +1433,7 @@ void ArucoDetector::refineDetectedMarkers(InputArray _image, const Board& _board std::vector marker(closestRotatedMarker.begin(), closestRotatedMarker.end()); int cornerRefinementWinSize = std::max(1, cvRound(detectorParams.relativeCornerRefinmentWinSize* getAverageModuleSize(marker, dictionary.markerSize, detectorParams.markerBorderBits))); - cornerRefinementWinSize = min(cornerRefinementWinSize, detectorParams.cornerRefinementWinSize); + cornerRefinementWinSize = std::min(cornerRefinementWinSize, detectorParams.cornerRefinementWinSize); cornerSubPix(grey, closestRotatedMarker, Size(cornerRefinementWinSize, cornerRefinementWinSize), Size(-1, -1), TermCriteria(TermCriteria::MAX_ITER | TermCriteria::EPS, @@ -1559,8 +1559,8 @@ void drawDetectedMarkers(InputOutputArray _image, InputArrayOfArrays _corners, // calculate colors Scalar textColor, cornerColor; textColor = cornerColor = borderColor; - swap(textColor.val[0], textColor.val[1]); // text color just sawp G and R - swap(cornerColor.val[1], cornerColor.val[2]); // corner color just sawp G and B + std::swap(textColor.val[0], textColor.val[1]); // text color just sawp G and R + std::swap(cornerColor.val[1], cornerColor.val[2]); // corner color just sawp G and B int nMarkers = (int)_corners.total(); for(int i = 0; i < nMarkers; i++) { diff --git a/modules/objdetect/src/aruco/aruco_dictionary.cpp b/modules/objdetect/src/aruco/aruco_dictionary.cpp index 14d80a6472..547472d75b 100644 --- a/modules/objdetect/src/aruco/aruco_dictionary.cpp +++ b/modules/objdetect/src/aruco/aruco_dictionary.cpp @@ -494,15 +494,15 @@ Dictionary extendDictionary(int nMarkers, int markerSize, const Dictionary &base // if baseDictionary is provided, calculate its intermarker distance if(baseDictionary.bytesList.rows > 0) { CV_Assert(baseDictionary.markerSize == markerSize); - out.bytesList = baseDictionary.bytesList.rowRange(0, min(nMarkers, baseDictionary.bytesList.rows)).clone(); + out.bytesList = baseDictionary.bytesList.rowRange(0, std::min(nMarkers, baseDictionary.bytesList.rows)).clone(); int minDistance = markerSize * markerSize + 1; for(int i = 0; i < out.bytesList.rows; i++) { Mat markerBytes = out.bytesList.rowRange(i, i + 1); Mat markerBits = Dictionary::getBitsFromByteList(markerBytes, markerSize); - minDistance = min(minDistance, _getSelfDistance(markerBits)); + minDistance = std::min(minDistance, _getSelfDistance(markerBits)); for(int j = i + 1; j < out.bytesList.rows; j++) { - minDistance = min(minDistance, out.getDistanceToId(markerBits, j)); + minDistance = std::min(minDistance, out.getDistanceToId(markerBits, j)); } } tau = minDistance; @@ -527,7 +527,7 @@ Dictionary extendDictionary(int nMarkers, int markerSize, const Dictionary &base if(selfDistance >= bestTau) { for(int i = 0; i < out.bytesList.rows; i++) { int currentDistance = out.getDistanceToId(currentMarker, i); - minDistance = min(currentDistance, minDistance); + minDistance = std::min(currentDistance, minDistance); if(minDistance <= bestTau) { break; } diff --git a/modules/objdetect/src/aruco/charuco_detector.cpp b/modules/objdetect/src/aruco/charuco_detector.cpp index d0ba8afe12..5740f9ffff 100644 --- a/modules/objdetect/src/aruco/charuco_detector.cpp +++ b/modules/objdetect/src/aruco/charuco_detector.cpp @@ -49,7 +49,7 @@ struct CharucoDetector::CharucoDetectorImpl { continue; Point2f centerMarker((mCorners[j].ptr(0)[0] + mCorners[j].ptr(0)[1] + mCorners[j].ptr(0)[2] + mCorners[j].ptr(0)[3]) / 4.f); - float dist = sqrt(normL2Sqr(centerMarker - charucoCorner)); + float dist = std::sqrt(normL2Sqr(centerMarker - charucoCorner)); // nearestMarkerIdx contains for each charuco corner, nearest marker index in ids array const int nearestMarkerId1 = boardIds[nearestMarkerIdx[chId][0]]; const int nearestMarkerId2 = boardIds[nearestMarkerIdx[chId][1]]; @@ -57,20 +57,20 @@ struct CharucoDetector::CharucoDetectorImpl { int nearestCornerId = nearestMarkerId1 == idMaker ? nearestMarkerCorners[chId][0] : nearestMarkerCorners[chId][1]; Point2f nearestCorner = mCorners[j].ptr(0)[nearestCornerId]; // distToNearest: distance from the charuco corner to charuco corner-forming markers - float distToNearest = sqrt(normL2Sqr(nearestCorner - charucoCorner)); - distance[chId].x = max(distance[chId].x, distToNearest); + float distToNearest = std::sqrt(normL2Sqr(nearestCorner - charucoCorner)); + distance[chId].x = std::max(distance[chId].x, distToNearest); // check that nearestCorner is nearest point { Point2f mid1 = (mCorners[j].ptr(0)[(nearestCornerId + 1) % 4]+nearestCorner)*0.5f; Point2f mid2 = (mCorners[j].ptr(0)[(nearestCornerId + 3) % 4]+nearestCorner)*0.5f; - float tmpDist = min(sqrt(normL2Sqr(mid1 - charucoCorner)), sqrt(normL2Sqr(mid2 - charucoCorner))); + float tmpDist = std::min(std::sqrt(normL2Sqr(mid1 - charucoCorner)), std::sqrt(normL2Sqr(mid2 - charucoCorner))); if (tmpDist < distToNearest) return false; } } // check distance from the charuco corner to other markers else - distance[chId].y = min(distance[chId].y, dist); + distance[chId].y = std::min(distance[chId].y, dist); } // if distance from the charuco corner to charuco corner-forming markers more then distance from the charuco corner to other markers, // then a false board is found. @@ -114,7 +114,7 @@ struct CharucoDetector::CharucoDetectorImpl { Point2f charucoCorner = charucoCorners.getMat().at((int)i); double dist = norm(markerCorner - charucoCorner); if(minDist == -1) minDist = dist; // if first distance, just assign it - minDist = min(dist, minDist); + minDist = std::min(dist, minDist); counter++; } // if this is the first closest marker, don't do anything @@ -445,7 +445,7 @@ void CharucoDetector::detectDiamonds(InputArray image, OutputArrayOfArrays _diam perimeterSq += edge.x*edge.x + edge.y*edge.y; } // maximum reprojection error relative to perimeter - float minRepDistance = sqrt(perimeterSq) * minRepDistanceRate; + float minRepDistance = std::sqrt(perimeterSq) * minRepDistanceRate; int currentId = _markerIds.getMat().at(i); @@ -588,8 +588,8 @@ void drawDetectedDiamonds(InputOutputArray _image, InputArrayOfArrays _corners, // calculate colors Scalar textColor, cornerColor; textColor = cornerColor = borderColor; - swap(textColor.val[0], textColor.val[1]); // text color just sawp G and R - swap(cornerColor.val[1], cornerColor.val[2]); // corner color just sawp G and B + std::swap(textColor.val[0], textColor.val[1]); // text color just sawp G and R + std::swap(cornerColor.val[1], cornerColor.val[2]); // corner color just sawp G and B int nMarkers = (int)_corners.total(); for(int i = 0; i < nMarkers; i++) { diff --git a/modules/objdetect/src/barcode_decoder/common/super_scale.cpp b/modules/objdetect/src/barcode_decoder/common/super_scale.cpp index 33e1db02ea..15ca5824b7 100644 --- a/modules/objdetect/src/barcode_decoder/common/super_scale.cpp +++ b/modules/objdetect/src/barcode_decoder/common/super_scale.cpp @@ -28,7 +28,7 @@ int SuperScale::init(const std::string &model_path) void SuperScale::processImageScale(const Mat &src, Mat &dst, float scale, const bool &use_sr, int sr_max_size) { - scale = min(scale, MAX_SCALE); + scale = std::min(scale, MAX_SCALE); if (scale > .0 && scale < 1.0) { // down sample resize(src, dst, Size(), scale, scale, INTER_AREA); @@ -41,7 +41,7 @@ void SuperScale::processImageScale(const Mat &src, Mat &dst, float scale, const { int width = src.cols; int height = src.rows; - if (use_sr && (int) sqrt(width * height * 1.0) < sr_max_size && net_loaded_) + if (use_sr && (int) std::sqrt(width * height * 1.0) < sr_max_size && net_loaded_) { superResolutionScale(src, dst); if (scale > 2.0) diff --git a/modules/objdetect/src/barcode_decoder/upcean_decoder.cpp b/modules/objdetect/src/barcode_decoder/upcean_decoder.cpp index 2288f5b81f..55e9cc3ffc 100644 --- a/modules/objdetect/src/barcode_decoder/upcean_decoder.cpp +++ b/modules/objdetect/src/barcode_decoder/upcean_decoder.cpp @@ -102,7 +102,7 @@ bool UPCEANDecoder::findStartGuardPatterns(const std::vector &row, std::p } int start = static_cast(start_range.first); next_start = static_cast(start_range.second); - int quiet_start = max(start - (next_start - start), 0); + int quiet_start = std::max(start - (next_start - start), 0); is_find = (quiet_start != start) && (std::find(std::begin(row) + quiet_start, std::begin(row) + start, BLACK) == std::begin(row) + start); } diff --git a/modules/objdetect/src/barcode_detector/bardetect.cpp b/modules/objdetect/src/barcode_detector/bardetect.cpp index e0fcf7bcd9..5b77e583ca 100644 --- a/modules/objdetect/src/barcode_detector/bardetect.cpp +++ b/modules/objdetect/src/barcode_detector/bardetect.cpp @@ -306,7 +306,7 @@ void Detect::calCoherence(int window_size) continue; } top_row = y * window_size; - bottom_row = min(height, (y + 1) * window_size); + bottom_row = std::min(height, (y + 1) * window_size); for (int pos = 0; pos < new_size.width; pos++) { @@ -318,7 +318,7 @@ void Detect::calCoherence(int window_size) continue; } left_col = pos * window_size; - right_col = min(width, (pos + 1) * window_size); + right_col = std::min(width, (pos + 1) * window_size); //we had an integral image to count non-zero elements CALCULATE_SUM(edges_ptr, rect_area) @@ -334,7 +334,7 @@ void Detect::calCoherence(int window_size) CALCULATE_SUM(xy_ptr, xy) // get the values of the rectangle corners from the integral image - 0 if outside bounds - d = sqrt((x_sq - y_sq) * (x_sq - y_sq) + 4 * xy * xy) / (x_sq + y_sq); + d = std::sqrt((x_sq - y_sq) * (x_sq - y_sq) + 4 * xy * xy) / (x_sq + y_sq); if (d > THRESHOLD_COHERENCE) { coherence_row[pos] = 255; diff --git a/modules/objdetect/src/calibinit.cpp b/modules/objdetect/src/calibinit.cpp index 0a852254d5..cab6980f8e 100644 --- a/modules/objdetect/src/calibinit.cpp +++ b/modules/objdetect/src/calibinit.cpp @@ -136,7 +136,7 @@ struct ChessBoardCorner { if (neighbors[i]) { - sum += sqrt(normL2Sqr(neighbors[i]->pt - pt)); + sum += std::sqrt(normL2Sqr(neighbors[i]->pt - pt)); n++; } } @@ -1948,13 +1948,13 @@ void ChessBoardDetector::generateQuads(const Mat& image_, int flags, int dilatio double p = arcLength(approx_contour, true); double area = contourArea(approx_contour, false); - double d1 = sqrt(normL2Sqr(pt[0] - pt[2])); - double d2 = sqrt(normL2Sqr(pt[1] - pt[3])); + double d1 = std::sqrt(normL2Sqr(pt[0] - pt[2])); + double d2 = std::sqrt(normL2Sqr(pt[1] - pt[3])); // philipg. Only accept those quadrangles which are more square // than rectangular and which are big enough - double d3 = sqrt(normL2Sqr(pt[0] - pt[1])); - double d4 = sqrt(normL2Sqr(pt[1] - pt[2])); + double d3 = std::sqrt(normL2Sqr(pt[0] - pt[1])); + double d4 = std::sqrt(normL2Sqr(pt[1] - pt[2])); if (!(d3*4 > d4 && d4*4 > d3 && d3*d4 < area*1.5 && area > min_area && d1 >= 0.15 * p && d2 >= 0.15 * p)) continue; @@ -2000,7 +2000,7 @@ void ChessBoardDetector::generateQuads(const Mat& image_, int flags, int dilatio } const int edge_len_compensation = 2 * dilations; - q.edge_sqr_len += 2 * sqrt(q.edge_sqr_len) * edge_len_compensation + edge_len_compensation * edge_len_compensation; + q.edge_sqr_len += 2 * std::sqrt(q.edge_sqr_len) * edge_len_compensation + edge_len_compensation * edge_len_compensation; } all_quads_count = quad_count; diff --git a/modules/objdetect/src/chessboard.cpp b/modules/objdetect/src/chessboard.cpp index 103fcb4aa1..f5912dda41 100644 --- a/modules/objdetect/src/chessboard.cpp +++ b/modules/objdetect/src/chessboard.cpp @@ -713,7 +713,7 @@ void FastX::detectImpl(const cv::Mat& _gray_image, //for each scale const int num_scales = parameters.max_scale-parameters.min_scale+1; - const int diag = int(sqrt(gray_image.rows*gray_image.rows+gray_image.cols*gray_image.cols)); + const int diag = int(std::sqrt(gray_image.rows*gray_image.rows+gray_image.cols*gray_image.cols)); const cv::Size size(diag,diag); const int num = int(0.5001*CV_PI/parameters.resolution); @@ -3447,7 +3447,7 @@ void Chessboard::findKeyPoints(const cv::Mat& image, std::vector& keyp const std::vector &angles_i3 = *iter2; if(angles_i3.size() != 2)// || pt.response < noise) continue; - int result = testPointSymmetry(image,pt.pt,pt.size*0.7F,std::max(10.0F,sqrt(pt.response)+0.5F*pt.size)); + int result = testPointSymmetry(image,pt.pt,pt.size*0.7F,std::max(10.0F,std::sqrt(pt.response)+0.5F*pt.size)); if(result > MAX_SYMMETRY_ERRORS) continue; else if(result > 3) @@ -3684,7 +3684,7 @@ Chessboard::Board Chessboard::detectImpl(const Mat& gray,std::vector &f float white_angle = fabs(angles_i.front()); // angle is negative if black --> clockwise float black_angle = fabs(angles_i.back()); // angle is negative if black --> clockwise if(angles_i.front() < 0) // ensure white angle is first - swap(white_angle,black_angle); + std::swap(white_angle,black_angle); std::vector boards; generateBoards(flann_index, data,*points_iter,white_angle,black_angle,min_response,gray,boards); diff --git a/modules/objdetect/src/circlesgrid.cpp b/modules/objdetect/src/circlesgrid.cpp index c08ec77363..6d567638fa 100644 --- a/modules/objdetect/src/circlesgrid.cpp +++ b/modules/objdetect/src/circlesgrid.cpp @@ -356,7 +356,7 @@ void CirclesGridClusterFinder::getSortedCorners(const std::vector & double dist01 = norm(sortedCorners[0] - sortedCorners[1]); double dist12 = norm(sortedCorners[1] - sortedCorners[2]); // Use half the average distance between circles on the shorter side as threshold for determining whether a point lies on an edge. - double thresh = min(dist01, dist12) / min(patternSize.width, patternSize.height) / 2; + double thresh = std::min(dist01, dist12) / std::min(patternSize.width, patternSize.height) / 2; size_t circleCount01 = 0; size_t circleCount12 = 0; diff --git a/modules/objdetect/src/face_detect.cpp b/modules/objdetect/src/face_detect.cpp index c6b24301b8..2f09d40f28 100644 --- a/modules/objdetect/src/face_detect.cpp +++ b/modules/objdetect/src/face_detect.cpp @@ -214,8 +214,8 @@ private: // Get bounding box float cx = ((c + bbox_v[idx * 4 + 0]) * strides[i]); float cy = ((r + bbox_v[idx * 4 + 1]) * strides[i]); - float w = exp(bbox_v[idx * 4 + 2]) * strides[i]; - float h = exp(bbox_v[idx * 4 + 3]) * strides[i]; + float w = std::exp(bbox_v[idx * 4 + 2]) * strides[i]; + float h = std::exp(bbox_v[idx * 4 + 3]) * strides[i]; float x1 = cx - w / 2.f; float y1 = cy - h / 2.f; diff --git a/modules/objdetect/src/mcc/checker_detector.cpp b/modules/objdetect/src/mcc/checker_detector.cpp index f703ce5a2e..5f72c323ca 100644 --- a/modules/objdetect/src/mcc/checker_detector.cpp +++ b/modules/objdetect/src/mcc/checker_detector.cpp @@ -238,7 +238,7 @@ bool CCheckerDetectorImpl:: } //remove too close detections removeTooCloseDetections(); - m_checkers.resize(min(nc, (int)m_checkers.size())); + m_checkers.resize(std::min(nc, (int)m_checkers.size())); return !m_checkers.empty(); } @@ -296,10 +296,10 @@ bool CCheckerDetectorImpl:: float confidence = detectionScores.at(0, i); if (confidence > m_params.confidenceThreshold) { - float xTopLeft = max(0.0f, detectionBoxes.at(i, 1) * cols - m_params.borderWidth); - float yTopLeft = max(0.0f, detectionBoxes.at(i, 0) * rows - m_params.borderWidth); - float xBottomRight = min((float)cols - 1, detectionBoxes.at(i, 3) * cols + m_params.borderWidth); - float yBottomRight = min((float)rows - 1, detectionBoxes.at(i, 2) * rows + m_params.borderWidth); + float xTopLeft = std::max(0.0f, detectionBoxes.at(i, 1) * cols - m_params.borderWidth); + float yTopLeft = std::max(0.0f, detectionBoxes.at(i, 0) * rows - m_params.borderWidth); + float xBottomRight = std::min((float)cols - 1, detectionBoxes.at(i, 3) * cols + m_params.borderWidth); + float yBottomRight = std::min((float)rows - 1, detectionBoxes.at(i, 2) * rows + m_params.borderWidth); Point2f topLeft = {xTopLeft, yTopLeft}; Point2f bottomRight = {xBottomRight, yBottomRight}; @@ -469,7 +469,7 @@ bool CCheckerDetectorImpl:: //remove too close detections removeTooCloseDetections(); - m_checkers.resize(min(nc, (int)m_checkers.size())); + m_checkers.resize(std::min(nc, (int)m_checkers.size())); return !m_checkers.empty(); #else @@ -1195,9 +1195,9 @@ Mat CCheckerDetectorImpl::getRefColors() { // Convert to 8-bit RGB values (0-255) but store as int Vec3f rgb = rgb_color.at(0, 0) * 255; out.at(i, 0) = Vec3i( - std::min(255, std::max(0, static_cast(rgb[0]))), // Blue - std::min(255, std::max(0, static_cast(rgb[1]))), // Green - std::min(255, std::max(0, static_cast(rgb[2]))) // Red + std::clamp(static_cast(rgb[0]), 0, 255), // Blue + std::clamp(static_cast(rgb[1]), 0, 255), // Green + std::clamp(static_cast(rgb[2]), 0, 255) // Red ); } return out; @@ -1240,7 +1240,7 @@ void CCheckerDetectorImpl:: std::vector idx; sort(J, idx); float invAsp = 1 / asp; - size_t n = min(nc, (unsigned)N); + size_t n = std::min(nc, (unsigned)N); checkers.clear(); for (size_t i = 0; i < n; i++) diff --git a/modules/objdetect/src/mcc/checker_model.cpp b/modules/objdetect/src/mcc/checker_model.cpp index 7f8fae253a..fc2776fb2f 100644 --- a/modules/objdetect/src/mcc/checker_model.cpp +++ b/modules/objdetect/src/mcc/checker_model.cpp @@ -238,7 +238,7 @@ float CChartModel:: // euclidean Vec3f v = v1 - v2; dist_i = v.dot(v); - dist += sqrt(dist_i); + dist += std::sqrt(dist_i); // cosine //float costh = v1.dot(v2) / (norm(v1)*norm(v2)); diff --git a/modules/objdetect/src/mcc/common.cpp b/modules/objdetect/src/mcc/common.cpp index 5b9eddf592..b27b61a6b2 100644 --- a/modules/objdetect/src/mcc/common.cpp +++ b/modules/objdetect/src/mcc/common.cpp @@ -61,7 +61,7 @@ float perimeter(const std::vector &ps) dx = ps[i].x - ps[i2].x; dy = ps[i].y - ps[i2].y; - sum += sqrt(dx * dx + dy * dy); + sum += std::sqrt(dx * dx + dy * dy); } return sum; diff --git a/modules/objdetect/src/mcc/graph_cluster.cpp b/modules/objdetect/src/mcc/graph_cluster.cpp index 3c1cea3df1..7b799ce82b 100644 --- a/modules/objdetect/src/mcc/graph_cluster.cpp +++ b/modules/objdetect/src/mcc/graph_cluster.cpp @@ -65,8 +65,8 @@ void CB0cluster:: //heuristic to combine two sub charts, This is pretty ugly at the moment, //Looking for somthing better - w = min(abs(W[i] - W[j]) / (W[i] + W[j]), - abs(max(W[i], W[j]) - 24 / 11.0f * min(W[i], W[j])) / (max(W[i], W[j]) + 24 / 11.0f * min(W[i], W[j]))); + w = std::min(abs(W[i] - W[j]) / (W[i] + W[j]), + abs(std::max(W[i], W[j]) - 24 / 11.0f * std::min(W[i], W[j])) / (std::max(W[i], W[j]) + 24 / 11.0f * std::min(W[i], W[j]))); w = (w < 0.1); y = w * dist; diff --git a/modules/objdetect/src/qrcode.cpp b/modules/objdetect/src/qrcode.cpp index b61c21e625..06cf32b52c 100644 --- a/modules/objdetect/src/qrcode.cpp +++ b/modules/objdetect/src/qrcode.cpp @@ -495,7 +495,7 @@ bool QRDetect::localization() triangle_perim = (triangle_sides[0] + triangle_sides[1] + triangle_sides[2]) / 2; - square_area = sqrt((triangle_perim * (triangle_perim - triangle_sides[0]) + square_area = std::sqrt((triangle_perim * (triangle_perim - triangle_sides[0]) * (triangle_perim - triangle_sides[1]) * (triangle_perim - triangle_sides[2]))) * 2; img_square_area = bin_barcode.cols * bin_barcode.rows; @@ -575,8 +575,8 @@ bool QRDetect::computeTransformationPoints() { Mat mask = Mat::zeros(bin_barcode.rows + 2, bin_barcode.cols + 2, CV_8UC1); uint8_t next_pixel, future_pixel = 255; - int count_test_lines = 0, index_c = max(0, min(cvRound(localization_points[i].x), bin_barcode.cols - 1)); - const int index_r = max(0, min(cvRound(localization_points[i].y), bin_barcode.rows - 1)); + int count_test_lines = 0, index_c = std::max(0, std::min(cvRound(localization_points[i].x), bin_barcode.cols - 1)); + const int index_r = std::max(0, std::min(cvRound(localization_points[i].y), bin_barcode.rows - 1)); for (; index_c < bin_barcode.cols - 1; index_c++) { next_pixel = bin_barcode.ptr(index_r)[index_c + 1]; @@ -1150,7 +1150,7 @@ float static getMinSideLen(const vector &points) { CV_Assert(points.size() == 4ull); double res = norm(points[1]-points[0]); for (size_t i = 1ull; i < points.size(); i++) { - res = min(res, norm(points[i]-points[(i+1ull) % points.size()])); + res = std::min(res, norm(points[i]-points[(i+1ull) % points.size()])); } return static_cast(res); } @@ -1167,7 +1167,7 @@ void QRDecode::init(const Mat &src, const vector &points) original_points = bbox; version = 0; version_size = 0; - test_perspective_size = max(getMinSideLen(points)+1.f, 251.f); + test_perspective_size = std::max(getMinSideLen(points)+1.f, 251.f); result_info = ""; } @@ -1182,7 +1182,7 @@ float QRDecode::distancePointToLine(Point2f a, Point2f b , Point2f c) A = c.y - b.y; B = c.x - b.x; C = c.x * b.y - b.x * c.y; - float dist = sqrt(A*A + B*B); + float dist = std::sqrt(A*A + B*B); if (dist == 0) return 0; result = abs((A * a.x - B * a.y + C)) / dist; @@ -2183,7 +2183,7 @@ bool QRDecode::straightenQRCodeInParts() { return false; } - float perspective_curved_size = max(getMinSideLen(original_points)+1.f, 251.f);; + float perspective_curved_size = std::max(getMinSideLen(original_points)+1.f, 251.f);; const Size temporary_size(cvRound(perspective_curved_size), cvRound(perspective_curved_size)); float dist = perspective_curved_size / (number_pnts_to_cut - 1); @@ -2349,10 +2349,10 @@ static inline bool checkFinderPatternByAspect(const vector &finderPattern return false; float sidesLen[4]; for (size_t i = 0; i < finderPattern.size(); i++) { - sidesLen[i] = (sqrt(normL2Sqr(Point2f(finderPattern[i] - finderPattern[(i+1ull)%finderPattern.size()])))); + sidesLen[i] = (std::sqrt(normL2Sqr(Point2f(finderPattern[i] - finderPattern[(i+1ull)%finderPattern.size()])))); } - const float maxSide = max(max(sidesLen[0], sidesLen[1]), max(sidesLen[2], sidesLen[3])); - const float minSide = min(min(sidesLen[0], sidesLen[1]), min(sidesLen[2], sidesLen[3])); + const float maxSide = std::max({sidesLen[0], sidesLen[1], sidesLen[2], sidesLen[3]}); + const float minSide = std::min({sidesLen[0], sidesLen[1], sidesLen[2], sidesLen[3]}); const float patternMaxRelativeLen = .3f; if (1.f - minSide / maxSide > patternMaxRelativeLen) @@ -2388,11 +2388,11 @@ static inline std::pair matchPatternPoints(const vector &finder } } } - distanceToOrig = sqrt(distanceToOrig); + distanceToOrig = std::sqrt(distanceToOrig); // check that the distance from the QR pattern to the corners of the QR code is small - const float originalQrSide = sqrt(normL2Sqr(cornerPointsQR[0] - cornerPointsQR[1]))*0.5f + - sqrt(normL2Sqr(cornerPointsQR[0] - cornerPointsQR[3]))*0.5f; + const float originalQrSide = std::sqrt(normL2Sqr(cornerPointsQR[0] - cornerPointsQR[1]))*0.5f + + std::sqrt(normL2Sqr(cornerPointsQR[0] - cornerPointsQR[3]))*0.5f; const float maxRelativeDistance = .1f; if (distanceToOrig/originalQrSide > maxRelativeDistance) @@ -2707,8 +2707,8 @@ void QRDecode::detectAlignment() { float l = resTemplate.at(maxLoc.y, maxLoc.x - 1), r = resTemplate.at(maxLoc.y, maxLoc.x + 1); float u = resTemplate.at(maxLoc.y - 1, maxLoc.x), d = resTemplate.at(maxLoc.y + 1, maxLoc.x); float denx = l - 2*c + r, deny = u - 2*c + d; - if (denx < 0) refined.x += std::max(-0.5f, std::min(0.5f, (l - r)/(2*denx))); - if (deny < 0) refined.y += std::max(-0.5f, std::min(0.5f, (u - d)/(2*deny))); + if (denx < 0) refined.x += std::clamp((l - r)/(2*denx), -0.5f, 0.5f); + if (deny < 0) refined.y += std::clamp((u - d)/(2*deny), -0.5f, 0.5f); } const float templateOffset = static_cast(resizedAlignmentMarker.size().width) / 2.f; Point2f alignmentCoord(Point2f(refined.x + left_top_x + templateOffset, refined.y + left_top_y + templateOffset)); @@ -2779,8 +2779,8 @@ bool QRDecode::samplingForVersion() for (int r = 0, i = 0; i < version_size; r += deltas_rows[i], i++) { for (int c = 0, j = 0; j < version_size; c += deltas_cols[j], j++) { Mat tile = postIntermediate( - Range(r, min(r + delta_rows, postIntermediate.rows)), - Range(c, min(c + delta_cols, postIntermediate.cols))); + Range(r, std::min(r + delta_rows, postIntermediate.rows)), + Range(c, std::min(c + delta_cols, postIntermediate.cols))); const double frequencyElem = (countNonZero(tile) * 1.0) / tile.total(); straight.ptr(i)[j] = (frequencyElem < totalFrequencyElem) ? 0 : 255; } @@ -4224,8 +4224,8 @@ struct FinderPatternInfo { for (int i = 0; i < 4; i++) { center += points[i]; const Point2f side = points[i]-points[(i+1) % 4]; - const float lenSide = sqrt(normL2Sqr(side)); - minSin = min(minSin, abs(side.y) / lenSide); + const float lenSide = std::sqrt(normL2Sqr(side)); + minSin = std::min(minSin, abs(side.y) / lenSide); moduleSize += lenSide; } moduleSize /= (4.f * 7.f); // 4 sides, 7 modules in one side @@ -4295,7 +4295,7 @@ struct FinderPatternInfo { Point2f toThis = other.getDirectionTo(typePattern); const float cosAngle = getCosAngle(toOther, toThis); if (cosAngle < 0.f && (CV_PI - acos(cosAngle)) / 2.f < maxRotation) { - const float angleCenter = max(acos(getCosAngle(toOther, other.center - center)), acos(getCosAngle(toThis, center - other.center))); + const float angleCenter = std::max(acos(getCosAngle(toOther, other.center - center)), acos(getCosAngle(toThis, center - other.center))); if (angleCenter < maxRotation) return true; } @@ -4303,7 +4303,7 @@ struct FinderPatternInfo { } static float getCosAngle(const Point2f& vec1, const Point2f& vec2) { - float cosAngle = vec1.dot(vec2) / (sqrt(normL2Sqr(vec1)) * sqrt(normL2Sqr(vec2))); + float cosAngle = vec1.dot(vec2) / (std::sqrt(normL2Sqr(vec1)) * std::sqrt(normL2Sqr(vec2))); cosAngle = std::max(-1.f, cosAngle); cosAngle = std::min(1.f, cosAngle); return cosAngle; @@ -4371,9 +4371,9 @@ struct FinderPatternInfo { for(int i = 1; i < lineIterator.count; i++, ++lineIterator) { const uint8_t value = img.at(lineIterator.pos()); if (prevValue != value) { - const float dist = sqrt(normL2Sqr((Point2f)(vec.back()-lineIterator.pos()))); + const float dist = std::sqrt(normL2Sqr((Point2f)(vec.back()-lineIterator.pos()))); // check long and short lines in timing pattern - const float relativeDiff = max(moduleSize, dist)/min(moduleSize, dist); + const float relativeDiff = std::max(moduleSize, dist)/std::min(moduleSize, dist); if (relativeDiff > maxTimingPatternMismatch) { if (dist < moduleSize || relativeDiff < maxTimingPatternMismatch*8.f) penaltyPoints++; @@ -4441,8 +4441,8 @@ struct QRCode { if (abs(pattern1.minQrAngle - pattern2.minQrAngle) > qrDetectorParameters.maxRotation || abs(pattern1.minQrAngle - pattern3.minQrAngle) > qrDetectorParameters.maxRotation) // check maxRotation return QRCode(pattern1, pattern2, pattern3, centerQR, distance); - if (max(pattern1.moduleSize, pattern2.moduleSize) / min(pattern1.moduleSize, pattern2.moduleSize) > qrDetectorParameters.maxModuleSizeMismatch || - max(pattern1.moduleSize, pattern3.moduleSize) / min(pattern1.moduleSize, pattern3.moduleSize) > qrDetectorParameters.maxModuleSizeMismatch) + if (std::max(pattern1.moduleSize, pattern2.moduleSize) / std::min(pattern1.moduleSize, pattern2.moduleSize) > qrDetectorParameters.maxModuleSizeMismatch || + std::max(pattern1.moduleSize, pattern3.moduleSize) / std::min(pattern1.moduleSize, pattern3.moduleSize) > qrDetectorParameters.maxModuleSizeMismatch) return QRCode(pattern1, pattern2, pattern3, centerQR, distance); // QR code: // center right @@ -4457,9 +4457,9 @@ struct QRCode { // bottom // sides length check - const float side1 = sqrt(normL2Sqr(pattern1.center - pattern2.center)); - const float side2 = sqrt(normL2Sqr(pattern1.center - pattern3.center)); - const float side3 = sqrt(normL2Sqr(pattern2.center - pattern3.center)); + const float side1 = std::sqrt(normL2Sqr(pattern1.center - pattern2.center)); + const float side2 = std::sqrt(normL2Sqr(pattern1.center - pattern3.center)); + const float side3 = std::sqrt(normL2Sqr(pattern2.center - pattern3.center)); std::array sides = {side1, side2, side3}; std::sort(sides.begin(), sides.end()); // check sides diff @@ -4501,7 +4501,7 @@ struct QRCode { pattern2.getQRCorner().second, pattern2.points[pattern2.innerCornerId]); Point2f c2 = intersectionLines(pattern1.getQRCorner().second, pattern1.points[pattern1.innerCornerId], pattern3.getQRCorner().second, pattern3.points[pattern3.innerCornerId]); - const float centerDistance = sqrt(normL2Sqr(c1 - c2)); + const float centerDistance = std::sqrt(normL2Sqr(c1 - c2)); distance = (sides[0] + sides[1] + centerDistance)*(sides[1] / sides[0]); } } @@ -4529,8 +4529,8 @@ struct QRCode { return std::numeric_limits::max(); // TODO: add v1, v2 check, add "y" checks - float numModules = (sqrt(normL2Sqr((centerPattern.getQRCorner().second - rightPattern.getQRCorner().second)))*0.5f + - sqrt(normL2Sqr((centerPattern.getQRCorner().second - bottomPattern.getQRCorner().second))*0.5f)) / moduleSize; + float numModules = (std::sqrt(normL2Sqr((centerPattern.getQRCorner().second - rightPattern.getQRCorner().second)))*0.5f + + std::sqrt(normL2Sqr((centerPattern.getQRCorner().second - bottomPattern.getQRCorner().second))*0.5f)) / moduleSize; const int sizeDelta = abs(cvRound(numModules) - (14 + v1.z < v2.z ? v1.x : v2.x)); const int colorDelta = abs(v1.x - v1.y - v1.y) + abs(v2.x - v2.y - v2.y); @@ -4569,7 +4569,7 @@ vector analyzeFinderPatterns(const vector > &corners, co for (size_t i = 0ull; i < corners.size(); i++) { FinderPatternInfo pattern = FinderPatternInfo(corners[i]); patterns[i] = pattern; - maxModuleSize = max(maxModuleSize, pattern.moduleSize); + maxModuleSize = std::max(maxModuleSize, pattern.moduleSize); } const int threshold = cvRound(qrDetectorParameters.minModuleSizeInPyramid * 12.5f) + (cvRound(qrDetectorParameters.minModuleSizeInPyramid * 12.5f) % 2 ? 0 : 1); @@ -4677,7 +4677,7 @@ struct PimplQRAruco : public ImplContour { float minDist = std::numeric_limits::max(); for (size_t i = 0ull; i < corners.size(); i += 4ull) { Point2f qrCenter((corners[i] + corners[i+1ull] + corners[i+2ull] + corners[i+3ull]) / 4.f); - float dist = sqrt(normL2Sqr(qrCenter - imageCenter)); + float dist = std::sqrt(normL2Sqr(qrCenter - imageCenter)); if (dist < minDist) { minQrId = i; minDist = dist; diff --git a/modules/objdetect/src/qrcode_encoder.cpp b/modules/objdetect/src/qrcode_encoder.cpp index 78110b1e21..7bb3fc5b0d 100644 --- a/modules/objdetect/src/qrcode_encoder.cpp +++ b/modules/objdetect/src/qrcode_encoder.cpp @@ -805,7 +805,7 @@ void QRCodeEncoderImpl::rearrangeBlocks(const vector > &data_blo { rearranged_data.clear(); int blocks = cur_ecc_params->num_blocks_in_G2 + cur_ecc_params->num_blocks_in_G1; - int col_border = max(cur_ecc_params->data_codewords_in_G2, cur_ecc_params->data_codewords_in_G1); + int col_border = std::max(cur_ecc_params->data_codewords_in_G2, cur_ecc_params->data_codewords_in_G1); int total_codeword_num = version_info->total_codewords; int is_not_equal = cur_ecc_params->data_codewords_in_G2 - cur_ecc_params->data_codewords_in_G1; int add_steps = cur_ecc_params->data_codewords_in_G2 > cur_ecc_params->data_codewords_in_G1 ? @@ -948,7 +948,7 @@ void QRCodeEncoderImpl::findAutoMaskType() int modules_percent = dark_modules * 100 / total_modules; int lower_bound = 45; int upper_bound = 55; - int diff = min(abs(modules_percent - lower_bound), abs(modules_percent - upper_bound)); + int diff = std::min(abs(modules_percent - lower_bound), abs(modules_percent - upper_bound)); penalty_four = (diff / 5) * 10; penalty_total = penalty_one + penalty_two + penalty_three + penalty_four; if (penalty_total < lowest_penalty) diff --git a/modules/objdetect/test/test_charucodetection.cpp b/modules/objdetect/test/test_charucodetection.cpp index 5e12b86eac..48cc347b19 100644 --- a/modules/objdetect/test/test_charucodetection.cpp +++ b/modules/objdetect/test/test_charucodetection.cpp @@ -787,7 +787,7 @@ TEST_P(CharucoBoard, testWrongSizeDetection) Mat boardImage; board.generateImage(boardSize*40, boardImage); - swap(boardSize.width, boardSize.height); + std::swap(boardSize.width, boardSize.height); aruco::CharucoDetector detector(aruco::CharucoBoard(boardSize, 1.f, 0.5f, aruco::getPredefinedDictionary(aruco::DICT_4X4_50))); // try detect board with wrong size for(int i: {0, 1}) { diff --git a/modules/objdetect/test/test_chesscorners.cpp b/modules/objdetect/test/test_chesscorners.cpp index 5800ce9dc0..a1baa60c6a 100644 --- a/modules/objdetect/test/test_chesscorners.cpp +++ b/modules/objdetect/test/test_chesscorners.cpp @@ -840,7 +840,7 @@ TEST(Calib3d_RotatedCirclesPatternDetector, issue_24964) EXPECT_LE(error, precise_success_error_level); // "rotate" the circle grid by 90 degrees - swap(parrernSize.height, parrernSize.width); + std::swap(parrernSize.height, parrernSize.width); found = findCirclesGrid(image, parrernSize, centers, CALIB_CB_SYMMETRIC_GRID); error = calcError(centers, goldCenters.t()); diff --git a/modules/objdetect/test/test_face.cpp b/modules/objdetect/test/test_face.cpp index c8bd55c1b3..ddf5ab05d3 100644 --- a/modules/objdetect/test/test_face.cpp +++ b/modules/objdetect/test/test_face.cpp @@ -126,7 +126,7 @@ TEST(Objdetect_face_detection, regression) float gtY = item.second.at(j, 4 + 2 * lmIdx + 1); float resX = faces.at(i, 4 + 2 * lmIdx); float resY = faces.at(i, 4 + 2 * lmIdx + 1); - float l2dis = cv::sqrt((gtX - resX) * (gtX - resX) + (gtY - resY) * (gtY - resY)); + float l2dis = std::sqrt((gtX - resX) * (gtX - resX) + (gtY - resY) * (gtY - resY)); if (l2dis <= l2disThreshold) { diff --git a/modules/photo/src/align.cpp b/modules/photo/src/align.cpp index 6a3972045e..11678e2116 100644 --- a/modules/photo/src/align.cpp +++ b/modules/photo/src/align.cpp @@ -125,8 +125,8 @@ public: CV_Assert(img0.channels() == 1 && img0.type() == img1.type()); CV_Assert(img0.size() == img1.size()); - int maxlevel = static_cast(log((double)max(img0.rows, img0.cols)) / log(2.0)) - 1; - maxlevel = min(maxlevel, max_bits - 1); + int maxlevel = static_cast(std::log2((double)std::max(img0.rows, img0.cols))) - 1; + maxlevel = std::min(maxlevel, max_bits - 1); std::vector pyr0; std::vector pyr1; @@ -175,8 +175,8 @@ public: Mat res = Mat::zeros(src.size(), src.type()); int width = src.cols - abs(shift.x); int height = src.rows - abs(shift.y); - Rect dst_rect(max(shift.x, 0), max(shift.y, 0), width, height); - Rect src_rect(max(-shift.x, 0), max(-shift.y, 0), width, height); + Rect dst_rect(std::max(shift.x, 0), std::max(shift.y, 0), width, height); + Rect src_rect(std::max(-shift.x, 0), std::max(-shift.y, 0), width, height); src(src_rect).copyTo(res(dst_rect)); res.copyTo(dst); } diff --git a/modules/photo/src/calibrate.cpp b/modules/photo/src/calibrate.cpp index 41d8f0f5ec..0954d5d56a 100644 --- a/modules/photo/src/calibrate.cpp +++ b/modules/photo/src/calibrate.cpp @@ -91,7 +91,7 @@ public: points.push_back(Point(rand() % cols, rand() % rows)); } } else { - int x_points = static_cast(sqrt(static_cast(samples) * cols / rows)); + int x_points = static_cast(std::sqrt(static_cast(samples) * cols / rows)); CV_Assert(0 < x_points && x_points <= cols); int y_points = samples / x_points; CV_Assert(0 < y_points && y_points <= rows); @@ -129,7 +129,7 @@ public: float wij = w.at(val); A.at(k, val) = wij; A.at(k, LDR_SIZE + (int)i) = -wij; - B.at(k, 0) = wij * log(times.at((int)j)); + B.at(k, 0) = wij * std::log(times.at((int)j)); k++; } } diff --git a/modules/photo/src/ccm/ccm.cpp b/modules/photo/src/ccm/ccm.cpp index 7d3e693a25..e0a7425998 100644 --- a/modules/photo/src/ccm/ccm.cpp +++ b/modules/photo/src/ccm/ccm.cpp @@ -246,7 +246,7 @@ void ColorCorrectionModel::Impl::initialLeastSquare(bool fit) Mat residual = A.reshape(1, A.rows) * ccm.reshape(0, shape / 3) - B.reshape(1, B.rows); Scalar s = residual.dot(residual); double sum = s[0]; - loss = sqrt(sum / maskedLen); + loss = std::sqrt(sum / maskedLen); } } @@ -283,7 +283,7 @@ void ColorCorrectionModel::Impl::fitting(void) solver->setTermCriteria(termcrit); double res = solver->minimize(reshapeCcm); ccm = reshapeCcm.reshape(0, shape / 3); - loss = sqrt(res / maskedLen); + loss = std::sqrt(res / maskedLen); } ColorCorrectionModel::ColorCorrectionModel() diff --git a/modules/photo/src/ccm/colorspace.cpp b/modules/photo/src/ccm/colorspace.cpp index 2a5cc5bf64..effd076945 100644 --- a/modules/photo/src/ccm/colorspace.cpp +++ b/modules/photo/src/ccm/colorspace.cpp @@ -155,7 +155,7 @@ void sRGBBase_::calLinear() { alpha = a + 1; K0 = a / (gamma - 1); - phi = (pow(alpha, gamma) * pow(gamma - 1, gamma - 1)) / (pow(a, gamma - 1) * pow(gamma, gamma)); + phi = (std::pow(alpha, gamma) * std::pow(gamma - 1, gamma - 1)) / (std::pow(a, gamma - 1) * std::pow(gamma, gamma)); beta = K0 / phi; } @@ -165,7 +165,7 @@ double sRGBBase_::toLFuncEW(double x) const { if (x > K0) { - return pow(((x + alpha - 1) / alpha), gamma); + return std::pow(((x + alpha - 1) / alpha), gamma); } else if (x >= -K0) { @@ -173,7 +173,7 @@ double sRGBBase_::toLFuncEW(double x) const } else { - return -(pow(((-x + alpha - 1) / alpha), gamma)); + return -(std::pow(((-x + alpha - 1) / alpha), gamma)); } } @@ -193,7 +193,7 @@ double sRGBBase_::fromLFuncEW(double x) const { if (x > beta) { - return alpha * pow(x, 1 / gamma) - (alpha - 1); + return alpha * std::pow(x, 1 / gamma) - (alpha - 1); } else if (x >= -beta) { @@ -201,7 +201,7 @@ double sRGBBase_::fromLFuncEW(double x) const } else { - return -(alpha * pow(-x, 1 / gamma) - (alpha - 1)); + return -(alpha * std::pow(-x, 1 / gamma) - (alpha - 1)); } } @@ -421,7 +421,7 @@ Mat Lab::fromsrc(Mat& src) Vec3d Lab::tolab(const Vec3d& lab) { auto f_inv = [](double t) -> double { - return t > DELTA ? pow(t, 3.0) : (t - C) / M; + return t > DELTA ? std::pow(t, 3.0) : (t - C) / M; }; double L = (lab[0] + 16.) / 116., a = lab[1] / 500., b = lab[2] / 200.; auto& il = getIlluminants(illumobserver); diff --git a/modules/photo/src/ccm/distance.cpp b/modules/photo/src/ccm/distance.cpp index fde973b00f..8bd01c2b32 100644 --- a/modules/photo/src/ccm/distance.cpp +++ b/modules/photo/src/ccm/distance.cpp @@ -17,18 +17,18 @@ double deltaCIE94(const Vec3d& lab1, const Vec3d& lab2, double kH, double kC, double kL, double k1, double k2) { double dl = lab1[0] - lab2[0]; - double c1 = sqrt(pow(lab1[1], 2) + pow(lab1[2], 2)); - double c2 = sqrt(pow(lab2[1], 2) + pow(lab2[2], 2)); + double c1 = std::sqrt(std::pow(lab1[1], 2) + std::pow(lab1[2], 2)); + double c2 = std::sqrt(std::pow(lab2[1], 2) + std::pow(lab2[2], 2)); double dc = c1 - c2; double da = lab1[1] - lab2[1]; double db = lab1[2] - lab2[2]; - double dh = pow(da, 2) + pow(db, 2) - pow(dc, 2); + double dh = std::pow(da, 2) + std::pow(db, 2) - std::pow(dc, 2); double sc = 1.0 + k1 * c1; double sh = 1.0 + k2 * c1; double sl = 1.0; - double res = pow(dl / (kL * sl), 2) + pow(dc / (kC * sc), 2) + dh / pow(kH * sh, 2); + double res = std::pow(dl / (kL * sl), 2) + std::pow(dc / (kC * sc), 2) + dh / std::pow(kH * sh, 2); - return res > 0 ? sqrt(res) : 0; + return res > 0 ? std::sqrt(res) : 0; } double deltaCIE94GraphicArts(const Vec3d& lab1, const Vec3d& lab2) @@ -48,14 +48,14 @@ double deltaCIEDE2000_(const Vec3d& lab1, const Vec3d& lab2, double kL, { double deltaLApo = lab2[0] - lab1[0]; double lBarApo = (lab1[0] + lab2[0]) / 2.0; - double C1 = sqrt(pow(lab1[1], 2) + pow(lab1[2], 2)); - double C2 = sqrt(pow(lab2[1], 2) + pow(lab2[2], 2)); + double C1 = std::sqrt(std::pow(lab1[1], 2) + std::pow(lab1[2], 2)); + double C2 = std::sqrt(std::pow(lab2[1], 2) + std::pow(lab2[2], 2)); double cBar = (C1 + C2) / 2.0; - double G = sqrt(pow(cBar, 7) / (pow(cBar, 7) + pow(25, 7))); + double G = std::sqrt(std::pow(cBar, 7) / (std::pow(cBar, 7) + std::pow(25, 7))); double a1Apo = lab1[1] + lab1[1] / 2.0 * (1.0 - G); double a2Apo = lab2[1] + lab2[1] / 2.0 * (1.0 - G); - double c1Apo = sqrt(pow(a1Apo, 2) + pow(lab1[2], 2)); - double c2Apo = sqrt(pow(a2Apo, 2) + pow(lab2[2], 2)); + double c1Apo = std::sqrt(std::pow(a1Apo, 2) + std::pow(lab1[2], 2)); + double c2Apo = std::sqrt(std::pow(a2Apo, 2) + std::pow(lab2[2], 2)); double cBarApo = (c1Apo + c2Apo) / 2.0; double deltaCApo = c2Apo - c1Apo; @@ -115,15 +115,15 @@ double deltaCIEDE2000_(const Vec3d& lab1, const Vec3d& lab2, double kL, hBarApo = (h1Apo + h2Apo - 2. * CV_PI) / 2.0; } - double deltaH_Apo = 2.0 * sqrt(c1Apo * c2Apo) * sin(deltaHApo / 2.0); + double deltaH_Apo = 2.0 * std::sqrt(c1Apo * c2Apo) * sin(deltaHApo / 2.0); double T = 1.0 - 0.17 * cos(hBarApo - toRad(30.)) + 0.24 * cos(2.0 * hBarApo) + 0.32 * cos(3.0 * hBarApo + toRad(6.0)) - 0.2 * cos(4.0 * hBarApo - toRad(63.0)); double sC = 1.0 + 0.045 * cBarApo; double sH = 1.0 + 0.015 * cBarApo * T; - double sL = 1.0 + ((0.015 * pow(lBarApo - 50.0, 2.0)) / sqrt(20.0 + pow(lBarApo - 50.0, 2.0))); - double rC = 2.0 * sqrt(pow(cBarApo, 7.0) / (pow(cBarApo, 7.0) + pow(25, 7))); - double rT = -sin(toRad(60.0) * exp(-pow((hBarApo - toRad(275.0)) / toRad(25.0), 2.0))) * rC; - double res = (pow(deltaLApo / (kL * sL), 2.0) + pow(deltaCApo / (kC * sC), 2.0) + pow(deltaH_Apo / (kH * sH), 2.0) + rT * (deltaCApo / (kC * sC)) * (deltaH_Apo / (kH * sH))); - return res > 0 ? sqrt(res) : 0; + double sL = 1.0 + ((0.015 * std::pow(lBarApo - 50.0, 2.0)) / std::sqrt(20.0 + std::pow(lBarApo - 50.0, 2.0))); + double rC = 2.0 * std::sqrt(std::pow(cBarApo, 7.0) / (std::pow(cBarApo, 7.0) + std::pow(25, 7))); + double rT = -sin(toRad(60.0) * std::exp(-std::pow((hBarApo - toRad(275.0)) / toRad(25.0), 2.0))) * rC; + double res = (std::pow(deltaLApo / (kL * sL), 2.0) + std::pow(deltaCApo / (kC * sC), 2.0) + std::pow(deltaH_Apo / (kH * sH), 2.0) + rT * (deltaCApo / (kC * sC)) * (deltaH_Apo / (kH * sH))); + return res > 0 ? std::sqrt(res) : 0; } double deltaCIEDE2000(const Vec3d& lab1, const Vec3d& lab2) @@ -136,10 +136,10 @@ double deltaCMC(const Vec3d& lab1, const Vec3d& lab2, double kL, double kC) double dL = lab2[0] - lab1[0]; double da = lab2[1] - lab1[1]; double db = lab2[2] - lab1[2]; - double C1 = sqrt(pow(lab1[1], 2.0) + pow(lab1[2], 2.0)); - double C2 = sqrt(pow(lab2[1], 2.0) + pow(lab2[2], 2.0)); + double C1 = std::sqrt(std::pow(lab1[1], 2.0) + std::pow(lab1[2], 2.0)); + double C2 = std::sqrt(std::pow(lab2[1], 2.0) + std::pow(lab2[2], 2.0)); double dC = C2 - C1; - double dH = sqrt(pow(da, 2) + pow(db, 2) - pow(dC, 2)); + double dH = std::sqrt(std::pow(da, 2) + std::pow(db, 2) - std::pow(dC, 2)); double H1; if (C1 == 0.) @@ -153,7 +153,7 @@ double deltaCMC(const Vec3d& lab1, const Vec3d& lab2, double kL, double kC) H1 += 2. * CV_PI; } - double F = pow(C1, 2) / sqrt(pow(C1, 4) + 1900); + double F = std::pow(C1, 2) / std::sqrt(std::pow(C1, 4) + 1900); double T = (H1 > toRad(164) && H1 <= toRad(345)) ? 0.56 + abs(0.2 * cos(H1 + toRad(168))) : 0.36 + abs(0.4 * cos(H1 + toRad(35))); @@ -161,7 +161,7 @@ double deltaCMC(const Vec3d& lab1, const Vec3d& lab2, double kL, double kC) double sC = (0.0638 * C1) / (1.0 + 0.0131 * C1) + 0.638; double sH = sC * (F * T + 1.0 - F); - return sqrt(pow(dL / (kL * sL), 2.0) + pow(dC / (kC * sC), 2.0) + pow(dH / sH, 2.0)); + return std::sqrt(std::pow(dL / (kL * sL), 2.0) + std::pow(dC / (kC * sC), 2.0) + std::pow(dH / sH, 2.0)); } double deltaCMC1To1(const Vec3d& lab1, const Vec3d& lab2) diff --git a/modules/photo/src/ccm/linearize.cpp b/modules/photo/src/ccm/linearize.cpp index d50b5ec6ae..56f8a9bc25 100644 --- a/modules/photo/src/ccm/linearize.cpp +++ b/modules/photo/src/ccm/linearize.cpp @@ -61,7 +61,7 @@ double Polyfit::fromEW(double x) double res = 0; for (int d = 0; d <= deg; ++d) { - res += pow(x, d) * p.at(d, 0); + res += std::pow(x, d) * p.at(d, 0); } return res; }; diff --git a/modules/photo/src/contrast_preserve.cpp b/modules/photo/src/contrast_preserve.cpp index 332159345f..18f92ba94a 100644 --- a/modules/photo/src/contrast_preserve.cpp +++ b/modules/photo/src/contrast_preserve.cpp @@ -119,8 +119,8 @@ void cv::decolor(InputArray _src, OutputArray _dst, OutputArray _color_boost) for(size_t i=0; i= 1); Mat weight(length, 1, CV_32FC3); float q = (length - 1) / 4.0f; - float e4 = exp(4.f); + float e4 = std::exp(4.f); float scale = e4/(e4 - 1.f); float shift = 1 / (1.f - e4); for(int i = 0; i < length; i++) { float value = i / q - 2.0f; - value = scale*exp(-value * value) + shift; + value = scale*std::exp(-value * value) + shift; weight.at(i) = Vec3f::all(value); } return weight; diff --git a/modules/photo/src/merge.cpp b/modules/photo/src/merge.cpp index 2f7868b4bd..239e1b1e66 100644 --- a/modules/photo/src/merge.cpp +++ b/modules/photo/src/merge.cpp @@ -254,7 +254,7 @@ public: } }); - int maxlevel = static_cast(logf(static_cast(min(size.width, size.height))) / logf(2.0f)); + int maxlevel = static_cast(std::log2(static_cast(std::min(size.width, size.height)))); std::vector res_pyr(maxlevel + 1); std::vector res_pyr_mutexes(maxlevel + 1); diff --git a/modules/photo/src/seamless_cloning_impl.cpp b/modules/photo/src/seamless_cloning_impl.cpp index c2e5c13478..181de8994a 100644 --- a/modules/photo/src/seamless_cloning_impl.cpp +++ b/modules/photo/src/seamless_cloning_impl.cpp @@ -418,12 +418,12 @@ void Cloning::illuminationChange(Mat &I, Mat &mask, Mat &wmask, Mat &cloned, flo Mat multX, multY, multx_temp, multy_temp; - multiply(patchGradientX,pow(alpha,beta),multX); + multiply(patchGradientX,std::pow(alpha,beta),multX); pow(mag,-1*beta, multx_temp); multiply(multX,multx_temp, patchGradientX); patchNaNs(patchGradientX); - multiply(patchGradientY,pow(alpha,beta),multY); + multiply(patchGradientY,std::pow(alpha,beta),multY); pow(mag,-1*beta, multy_temp); multiply(multY,multy_temp,patchGradientY); patchNaNs(patchGradientY); diff --git a/modules/photo/src/tonemap.cpp b/modules/photo/src/tonemap.cpp index 0445638bc2..2f8dcf7d96 100644 --- a/modules/photo/src/tonemap.cpp +++ b/modules/photo/src/tonemap.cpp @@ -233,7 +233,7 @@ public: float key = (log_max - log_mean) / (log_max - log_min); float map_key = 0.3f + 0.7f * std::pow(key, 1.4f); - const float intensity_scale = exp(-intensity); + const float intensity_scale = std::exp(-intensity); Scalar chan_mean = mean(img); float gray_mean = static_cast(mean(gray_img)[0]); @@ -431,7 +431,7 @@ protected: void getContrast(Mat src, std::vector& x_contrast, std::vector& y_contrast) { - int levels = static_cast(logf(static_cast(min(src.rows, src.cols))) / logf(2.0f)); + int levels = static_cast(std::log2(static_cast(std::min(src.rows, src.cols)))); x_contrast.resize(levels); y_contrast.resize(levels); diff --git a/modules/ptcloud/include/opencv2/ptcloud/detail/submap.hpp b/modules/ptcloud/include/opencv2/ptcloud/detail/submap.hpp index e11256242b..73d75b28ef 100644 --- a/modules/ptcloud/include/opencv2/ptcloud/detail/submap.hpp +++ b/modules/ptcloud/include/opencv2/ptcloud/detail/submap.hpp @@ -298,7 +298,7 @@ int SubmapManager::estimateConstraint(int fromSubmapId, int toSubmapId, float rAbs = abs(residual); if (rAbs < thresh) return 1.0; - float numerator = sqrt(2 * thresh * rAbs - thresh * thresh); + float numerator = std::sqrt(2 * thresh * rAbs - thresh * thresh); return numerator / rAbs; }; @@ -379,7 +379,7 @@ int SubmapManager::estimateConstraint(int fromSubmapId, int toSubmapId, inlierConstraint += DualQuatf::createFromMat(fromSubmapData.constraints[i].matrix); } } - inlierConstraint = inlierConstraint * 1.0f/float(max(localInliers, 1)); + inlierConstraint = inlierConstraint * 1.0f/float(std::max(localInliers, 1)); inlierPose = inlierConstraint.toAffine3(); inliers = localInliers; diff --git a/modules/ptcloud/src/color_hash_tsdf_functions.cpp b/modules/ptcloud/src/color_hash_tsdf_functions.cpp index 0118ece856..4ee440899e 100644 --- a/modules/ptcloud/src/color_hash_tsdf_functions.cpp +++ b/modules/ptcloud/src/color_hash_tsdf_functions.cpp @@ -175,7 +175,7 @@ Point3f getNormalColorHashVoxel( normal[2] = interpolate(tx, ty, tz, czv); #endif - float nv = sqrt(normal[0] * normal[0] + normal[1] * normal[1] + normal[2] * normal[2]); + float nv = std::sqrt(normal[0] * normal[0] + normal[1] * normal[1] + normal[2] * normal[2]); return nv < 0.0001f ? nan3 : normal / nv; } diff --git a/modules/ptcloud/src/color_tsdf_functions.cpp b/modules/ptcloud/src/color_tsdf_functions.cpp index 858a4fb246..8a48db5695 100644 --- a/modules/ptcloud/src/color_tsdf_functions.cpp +++ b/modules/ptcloud/src/color_tsdf_functions.cpp @@ -105,8 +105,8 @@ void integrateColorTsdfVolumeUnit(const VolumeSettings& settings, const Matx44f& startZ = endZ = 0; } } - startZ = max(0, startZ); - endZ = min(int(volResolution.z), endZ); + startZ = std::max(0, startZ); + endZ = std::min(int(volResolution.z), endZ); for (int z = startZ; z < endZ; z++) { // optimization of the following: @@ -203,7 +203,7 @@ void integrateColorTsdfVolumeUnit(const VolumeSettings& settings, const Matx44f& colorFix(r, g, b); // update TSDF value = floatToTsdf((tsdfToFloat(value) * weight + tsdfToFloat(tsdf)) / (weight + 1)); - weight = WeightType(min(int(weight + 1), int(maxWeight))); + weight = WeightType(std::min(int(weight + 1), int(maxWeight))); } } } @@ -254,8 +254,8 @@ void integrateColorTsdfVolumeUnit(const VolumeSettings& settings, const Matx44f& startZ = endZ = 0; } } - startZ = max(0, startZ); - endZ = min(int(volResolution.z), endZ); + startZ = std::max(0, startZ); + endZ = std::min(int(volResolution.z), endZ); for (int z = startZ; z < endZ; z++) { @@ -309,7 +309,7 @@ void integrateColorTsdfVolumeUnit(const VolumeSettings& settings, const Matx44f& // update TSDF value = floatToTsdf((tsdfToFloat(value) * weight + tsdfToFloat(tsdf)) / (weight + 1)); - weight = (WeightType)min(weight + 1, maxWeight); + weight = (WeightType)std::min(weight + 1, maxWeight); } } } @@ -531,7 +531,7 @@ inline Point3f getNormalColorVoxel(const Mat& volume, nv = v0 + tx * (v1 - v0); } - float nv = sqrt(an[0] * an[0] + + float nv = std::sqrt(an[0] * an[0] + an[1] * an[1] + an[2] * an[2]); return nv < 0.0001f ? nan3 : an / nv; @@ -809,8 +809,8 @@ void raycastColorTsdfVolumeUnit(const VolumeSettings &settings, const Matx44f &c float _minAx[4], _maxAx[4]; v_store(_minAx, minAx); v_store(_maxAx, maxAx); - float tmin = max({ _minAx[0], _minAx[1], _minAx[2], clip }); - float tmax = min({ _maxAx[0], _maxAx[1], _maxAx[2] }); + float tmin = std::max({ _minAx[0], _minAx[1], _minAx[2], clip }); + float tmax = std::min({ _maxAx[0], _maxAx[1], _maxAx[2] }); // precautions against getting coordinates out of bounds tmin = tmin + tstep; @@ -917,15 +917,15 @@ void raycastColorTsdfVolumeUnit(const VolumeSettings &settings, const Matx44f &c Point3f ttop = rayinv.mul(boxMax - orig); // re-order intersections to find smallest and largest on each axis - Point3f minAx(min(ttop.x, tbottom.x), min(ttop.y, tbottom.y), min(ttop.z, tbottom.z)); - Point3f maxAx(max(ttop.x, tbottom.x), max(ttop.y, tbottom.y), max(ttop.z, tbottom.z)); + Point3f minAx(std::min(ttop.x, tbottom.x), std::min(ttop.y, tbottom.y), std::min(ttop.z, tbottom.z)); + Point3f maxAx(std::max(ttop.x, tbottom.x), std::max(ttop.y, tbottom.y), std::max(ttop.z, tbottom.z)); // near clipping plane const float clip = 0.f; //float tmin = max(max(max(minAx.x, minAx.y), max(minAx.x, minAx.z)), clip); //float tmax = min(min(maxAx.x, maxAx.y), min(maxAx.x, maxAx.z)); - float tmin = max({ minAx.x, minAx.y, minAx.z, clip }); - float tmax = min({ maxAx.x, maxAx.y, maxAx.z }); + float tmin = std::max({ minAx.x, minAx.y, minAx.z, clip }); + float tmax = std::min({ maxAx.x, maxAx.y, maxAx.z }); // precautions against getting coordinates out of bounds tmin = tmin + tstep; diff --git a/modules/ptcloud/src/hash_tsdf_functions.cpp b/modules/ptcloud/src/hash_tsdf_functions.cpp index 8376e45b46..cd257c7fb9 100644 --- a/modules/ptcloud/src/hash_tsdf_functions.cpp +++ b/modules/ptcloud/src/hash_tsdf_functions.cpp @@ -530,7 +530,7 @@ void ocl_integrateHashTsdfVolumeUnit( { bufferSizeDegree = (int)(log2(sizeAfter) + 1); // clz() would be better int oldBuffSize = buff_lvl; - buff_lvl = (int)pow(2, bufferSizeDegree); + buff_lvl = (int)std::pow(2, bufferSizeDegree); volUnitsDataCopy.resize(buff_lvl); @@ -837,7 +837,7 @@ Point3f getNormalVoxel( normal[2] = interpolate(tx, ty, tz, czv); #endif - float nv = sqrt(normal[0] * normal[0] + + float nv = std::sqrt(normal[0] * normal[0] + normal[1] * normal[1] + normal[2] * normal[2]); return nv < 0.0001f ? nan3 : normal / nv; @@ -980,7 +980,7 @@ Point3f ocl_getNormalVoxel( normal[2] = interpolate(tx, ty, tz, czv); #endif - float nv = sqrt(normal[0] * normal[0] + + float nv = std::sqrt(normal[0] * normal[0] + normal[1] * normal[1] + normal[2] * normal[2]); return nv < 0.0001f ? nan3 : normal / nv; diff --git a/modules/ptcloud/src/kinfu_frame.cpp b/modules/ptcloud/src/kinfu_frame.cpp index 036247b8ce..1579e3c5fa 100644 --- a/modules/ptcloud/src/kinfu_frame.cpp +++ b/modules/ptcloud/src/kinfu_frame.cpp @@ -91,8 +91,8 @@ struct RenderInvoker : ParallelLoopBody Point3f v = normalize(-Vec3f(p)); Point3f r = normalize(Vec3f(2.f*n*n.dot(l) - l)); - uchar ix = (uchar)((Ax*Ka*Dx + Lx*Kd*Dx*max(0.f, n.dot(l)) + - Lx*Ks*Sx*specPow(max(0.f, r.dot(v))))*255.f); + uchar ix = (uchar)((Ax*Ka*Dx + Lx*Kd*Dx*std::max(0.f, n.dot(l)) + + Lx*Ks*Sx*specPow(std::max(0.f, r.dot(v))))*255.f); color = Vec4b(ix, ix, ix, 0); } @@ -215,8 +215,8 @@ struct PyrDownBilateralInvoker : ParallelLoopBody { depthType center = srcCenterRow[2*x]; - int sx = max(0, 2*x - D/2), ex = min(2*x - D/2 + D, depth.cols-1); - int sy = max(0, 2*y - D/2), ey = min(2*y - D/2 + D, depth.rows-1); + int sx = std::max(0, 2*x - D/2), ex = std::min(2*x - D/2 + D, depth.cols-1); + int sy = std::max(0, 2*y - D/2), ey = std::min(2*y - D/2 + D, depth.rows-1); depthType sum = 0; int count = 0; diff --git a/modules/ptcloud/src/octree.cpp b/modules/ptcloud/src/octree.cpp index 8ad57f7d3f..374fe98560 100644 --- a/modules/ptcloud/src/octree.cpp +++ b/modules/ptcloud/src/octree.cpp @@ -210,12 +210,12 @@ static Vec6f getBoundingBox(const Mat& points) for (int i = 0; i < (int)points.total(); i++) { Point3f pt = points.at(i); - bb[0] = min(bb[0], pt.x); - bb[1] = min(bb[1], pt.y); - bb[2] = min(bb[2], pt.z); - bb[3] = max(bb[3], pt.x); - bb[4] = max(bb[4], pt.y); - bb[5] = max(bb[5], pt.z); + bb[0] = std::min(bb[0], pt.x); + bb[1] = std::min(bb[1], pt.y); + bb[2] = std::min(bb[2], pt.z); + bb[3] = std::max(bb[3], pt.x); + bb[4] = std::max(bb[4], pt.y); + bb[5] = std::max(bb[5], pt.z); } return bb; @@ -261,7 +261,7 @@ void Octree::Impl::fill(bool useResolution, InputArray _points, InputArray _colo Point3f minBound(bbox[0], bbox[1], bbox[2]); Point3f maxBound(bbox[3], bbox[4], bbox[5]); - double maxSize = max(max(maxBound.x - minBound.x, maxBound.y - minBound.y), maxBound.z - minBound.z); + double maxSize = std::max({maxBound.x - minBound.x, maxBound.y - minBound.y, maxBound.z - minBound.z}); // Extend maxSize to the closest power of 2 that exceeds it for bit operations maxSize = double(1 << int(ceil(log2(maxSize)))); @@ -488,7 +488,7 @@ bool OctreeNode::overlap(const Point3f& query, float squareRadius) const float dist = SquaredDistance(center, query); float temp = float(this->size) * float(this->size) * 3.0f; - return ( dist + dist * std::numeric_limits::epsilon() ) <= float(temp * 0.25f + squareRadius + sqrt(temp * squareRadius)) ; + return ( dist + dist * std::numeric_limits::epsilon() ) <= float(temp * 0.25f + squareRadius + std::sqrt(temp * squareRadius)) ; } diff --git a/modules/ptcloud/src/odometry_functions.cpp b/modules/ptcloud/src/odometry_functions.cpp index 4e91f7a99c..bd40057586 100644 --- a/modules/ptcloud/src/odometry_functions.cpp +++ b/modules/ptcloud/src/odometry_functions.cpp @@ -1412,7 +1412,7 @@ bool ocl_calcICPLsmMatricesFast(Matx33f cameraMatrix, const UMat& oldPts, const // local memory should keep upperTriangles for all threads in group for reduce const size_t ltsz = UTSIZE * sizeof(float); const size_t lcols = 32; - size_t lrows = min(memSize / ltsz, wgsLimit) / lcols; + size_t lrows = std::min(memSize / ltsz, wgsLimit) / lcols; // round lrows down to 2^n lrows = roundDownPow2(lrows); size_t localSize[2] = { lcols, lrows }; diff --git a/modules/ptcloud/src/pose_graph.cpp b/modules/ptcloud/src/pose_graph.cpp index 0d4d1e88a8..e743958eb4 100644 --- a/modules/ptcloud/src/pose_graph.cpp +++ b/modules/ptcloud/src/pose_graph.cpp @@ -401,7 +401,7 @@ static inline cv::Matx66d llt6(Matx66d m) sum += L(i, k) * L(j, k); if (i == j) - L(i, i) = sqrt(m(i, i) - sum); + L(i, i) = std::sqrt(m(i, i) - sum); else L(i, j) = (1.0 / L(j, j) * (m(i, j) - sum)); } diff --git a/modules/ptcloud/src/tsdf_functions.cpp b/modules/ptcloud/src/tsdf_functions.cpp index b321d06966..bf13353171 100644 --- a/modules/ptcloud/src/tsdf_functions.cpp +++ b/modules/ptcloud/src/tsdf_functions.cpp @@ -137,8 +137,8 @@ void integrateTsdfVolumeUnit(const VolumeSettings& settings, const Matx44f& volu startZ = endZ = 0; } } - startZ = max(0, startZ); - endZ = min(int(volResolution.z), endZ); + startZ = std::max(0, startZ); + endZ = std::min(int(volResolution.z), endZ); for (int z = startZ; z < endZ; z++) { // optimization of the following: @@ -277,8 +277,8 @@ void integrateTsdfVolumeUnit(const VolumeSettings& settings, const Matx44f& volu startZ = endZ = 0; } } - startZ = max(0, startZ); - endZ = min(int(volResolution.z), endZ); + startZ = std::max(0, startZ); + endZ = std::min(int(volResolution.z), endZ); for (int z = startZ; z < endZ; z++) { @@ -318,7 +318,7 @@ void integrateTsdfVolumeUnit(const VolumeSettings& settings, const Matx44f& volu // update TSDF value = floatToTsdf((tsdfToFloat(value) * weight + tsdfToFloat(tsdf)) / (weight + 1)); - weight = (WeightType)min(weight + 1, maxWeight); + weight = (WeightType)std::min(weight + 1, maxWeight); } } } @@ -608,7 +608,7 @@ inline Point3f getNormalVoxel( const Mat& volume, nv = v0 + tx * (v1 - v0); } - float nv = sqrt(an[0] * an[0] + + float nv = std::sqrt(an[0] * an[0] + an[1] * an[1] + an[2] * an[2]); return nv < 0.0001f ? nan3 : an / nv; @@ -729,8 +729,8 @@ void raycastTsdfVolumeUnit(const VolumeSettings& settings, const Matx44f& camera float _minAx[4], _maxAx[4]; v_store(_minAx, minAx); v_store(_maxAx, maxAx); - float tmin = max({ _minAx[0], _minAx[1], _minAx[2], clip }); - float tmax = min({ _maxAx[0], _maxAx[1], _maxAx[2] }); + float tmin = std::max({ _minAx[0], _minAx[1], _minAx[2], clip }); + float tmax = std::min({ _maxAx[0], _maxAx[1], _maxAx[2] }); // precautions against getting coordinates out of bounds tmin = tmin + tstep; @@ -833,15 +833,15 @@ void raycastTsdfVolumeUnit(const VolumeSettings& settings, const Matx44f& camera Point3f ttop = rayinv.mul(boxMax - orig); // re-order intersections to find smallest and largest on each axis - Point3f minAx(min(ttop.x, tbottom.x), min(ttop.y, tbottom.y), min(ttop.z, tbottom.z)); - Point3f maxAx(max(ttop.x, tbottom.x), max(ttop.y, tbottom.y), max(ttop.z, tbottom.z)); + Point3f minAx(std::min(ttop.x, tbottom.x), std::min(ttop.y, tbottom.y), std::min(ttop.z, tbottom.z)); + Point3f maxAx(std::max(ttop.x, tbottom.x), std::max(ttop.y, tbottom.y), std::max(ttop.z, tbottom.z)); // near clipping plane const float clip = 0.f; //float tmin = max(max(max(minAx.x, minAx.y), max(minAx.x, minAx.z)), clip); //float tmax = min(min(maxAx.x, maxAx.y), min(maxAx.x, maxAx.z)); - float tmin = max({ minAx.x, minAx.y, minAx.z, clip }); - float tmax = min({ maxAx.x, maxAx.y, maxAx.z }); + float tmin = std::max({ minAx.x, minAx.y, minAx.z, clip }); + float tmax = std::min({ maxAx.x, maxAx.y, maxAx.z }); // precautions against getting coordinates out of bounds tmin = tmin + tstep; @@ -1359,7 +1359,7 @@ void ocl_fetchPointsNormalsFromTsdfVolumeUnit(const VolumeSettings& settings, In size_t elemSize = (sizeof(float) * 4) * (needNormals ? 2 : 1); const size_t lcols = 8; const size_t lrows = 8; - size_t lplanes = min(memSize / elemSize, wgsLimit) / lcols / lrows; + size_t lplanes = std::min(memSize / elemSize, wgsLimit) / lcols / lrows; lplanes = roundDownPow2(lplanes); size_t localSize[3] = { lcols, lrows, lplanes }; Vec3i ngroups((int)divUp(globalSize[0], (unsigned int)localSize[0]), diff --git a/modules/ptcloud/src/viz3d/viz3d.cpp b/modules/ptcloud/src/viz3d/viz3d.cpp index 8b9fc34aeb..ca707f5fda 100644 --- a/modules/ptcloud/src/viz3d/viz3d.cpp +++ b/modules/ptcloud/src/viz3d/viz3d.cpp @@ -721,7 +721,7 @@ void View::rotate(float dx, float dy) float phi = ::asin(this->position(1)); theta -= dx * 0.05f; phi += dy * 0.05f; - phi = max(-1.5f, min(1.5f, phi)); + phi = std::clamp(phi, -1.5f, 1.5f); this->position(0) = ::cos(theta) * ::cos(phi) * this->distance; this->position(1) = ::sin(phi) * this->distance; @@ -746,7 +746,7 @@ void View::move(float dx, float dy) void View::scaleDistance(float amount) { this->distance *= amount; - this->distance = max(0.1f, this->distance); + this->distance = std::max(0.1f, this->distance); this->position = normalize(this->position - this->origin) * this->distance + this->origin; this->lookAt(this->origin, this->up); @@ -1055,7 +1055,7 @@ void Window::onMouse(int event, int x, int y, int flags) } else if (event == EVENT_MOUSEWHEEL) { - this->view.scaleDistance(min(1.2f, max(0.8f, 1.0f - getMouseWheelDelta(flags) / 12.0f))); + this->view.scaleDistance(std::clamp(1.0f - getMouseWheelDelta(flags) / 12.0f, 0.8f, 1.2f)); updateWindow(this->name); } } diff --git a/modules/ptcloud/src/volume_impl.cpp b/modules/ptcloud/src/volume_impl.cpp index 3c7856f39a..1309f71127 100644 --- a/modules/ptcloud/src/volume_impl.cpp +++ b/modules/ptcloud/src/volume_impl.cpp @@ -464,12 +464,12 @@ void HashTsdfVolume::getBoundingBox(OutputArray boundingBox, int precision) cons { // pt in local coords Point3f pg = p; - bb[0] = min(bb[0], pg.x); - bb[1] = min(bb[1], pg.y); - bb[2] = min(bb[2], pg.z); - bb[3] = max(bb[3], pg.x); - bb[4] = max(bb[4], pg.y); - bb[5] = max(bb[5], pg.z); + bb[0] = std::min(bb[0], pg.x); + bb[1] = std::min(bb[1], pg.y); + bb[2] = std::min(bb[2], pg.z); + bb[3] = std::max(bb[3], pg.x); + bb[4] = std::max(bb[4], pg.y); + bb[5] = std::max(bb[5], pg.z); } bb.copyTo(boundingBox); @@ -757,12 +757,12 @@ void ColorHashTsdfVolume::getBoundingBox(OutputArray boundingBox, int precision) for (auto p : pts) { Point3f pg = p; - bb[0] = min(bb[0], pg.x); - bb[1] = min(bb[1], pg.y); - bb[2] = min(bb[2], pg.z); - bb[3] = max(bb[3], pg.x); - bb[4] = max(bb[4], pg.y); - bb[5] = max(bb[5], pg.z); + bb[0] = std::min(bb[0], pg.x); + bb[1] = std::min(bb[1], pg.y); + bb[2] = std::min(bb[2], pg.z); + bb[3] = std::max(bb[3], pg.x); + bb[4] = std::max(bb[4], pg.y); + bb[5] = std::max(bb[5], pg.z); } bb.copyTo(boundingBox); diff --git a/modules/ts/src/ts_perf.cpp b/modules/ts/src/ts_perf.cpp index 638978246f..c027efcbe3 100644 --- a/modules/ts/src/ts_perf.cpp +++ b/modules/ts/src/ts_perf.cpp @@ -840,7 +840,7 @@ static void printNodeRec(cv::instr::InstrNode *pNode, cv::instr::InstrNode *pRoo { if(pNode->m_childs[i-1]->m_payload.m_funName == pNode->m_childs[j]->m_payload.m_funName ) { - cv::swap(pNode->m_childs[i], pNode->m_childs[j]); + std::swap(pNode->m_childs[i], pNode->m_childs[j]); i++; } } @@ -1037,7 +1037,7 @@ void TestBase::Init(const std::vector & availableImpls, printf("No such strategy: %s\n", perf_strategy.c_str()); exit(1); } - param_max_outliers = std::min(100., std::max(0., args.get("perf_max_outliers"))); + param_max_outliers = std::clamp(args.get("perf_max_outliers"), 0., 100.); param_min_samples = std::max(1u, args.get("perf_min_samples")); param_max_deviation = std::max(0., args.get("perf_max_deviation")); param_seed = args.get("perf_seed"); diff --git a/modules/video/src/bgfg_KNN.cpp b/modules/video/src/bgfg_KNN.cpp index 950ce2d99c..389d88d252 100644 --- a/modules/video/src/bgfg_KNN.cpp +++ b/modules/video/src/bgfg_KNN.cpp @@ -665,9 +665,9 @@ bool BackgroundSubtractorKNNImpl::ocl_apply(InputArray _image, OutputArray _fgma // calculate update parameters (using alpha) int Kshort,Kmid,Klong; //approximate exponential learning curve - Kshort=(int)(log(0.7)/log(1-learningRate))+1;//Kshort - Kmid=(int)(log(0.4)/log(1-learningRate))-Kshort+1;//Kmid - Klong=(int)(log(0.1)/log(1-learningRate))-Kshort-Kmid+1;//Klong + Kshort=(int)(std::log(0.7)/std::log(1-learningRate))+1;//Kshort + Kmid=(int)(std::log(0.4)/std::log(1-learningRate))-Kshort+1;//Kmid + Klong=(int)(std::log(0.1)/std::log(1-learningRate))-Kshort-Kmid+1;//Klong //refresh rates int nShortUpdate = (Kshort/nN)+1; @@ -794,9 +794,9 @@ void BackgroundSubtractorKNNImpl::apply(InputArray _image, InputArray _knownFore // calculate update parameters (using alpha) int Kshort,Kmid,Klong; //approximate exponential learning curve - Kshort=(int)(log(0.7)/log(1-learningRate))+1;//Kshort - Kmid=(int)(log(0.4)/log(1-learningRate))-Kshort+1;//Kmid - Klong=(int)(log(0.1)/log(1-learningRate))-Kshort-Kmid+1;//Klong + Kshort=(int)(std::log(0.7)/std::log(1-learningRate))+1;//Kshort + Kmid=(int)(std::log(0.4)/std::log(1-learningRate))-Kshort+1;//Kmid + Klong=(int)(std::log(0.1)/std::log(1-learningRate))-Kshort-Kmid+1;//Klong //refresh rates int nShortUpdate = (Kshort/nN)+1; diff --git a/modules/video/src/dis_flow.cpp b/modules/video/src/dis_flow.cpp index e754e816dc..439aa4705a 100644 --- a/modules/video/src/dis_flow.cpp +++ b/modules/video/src/dis_flow.cpp @@ -1084,8 +1084,8 @@ void DISOpticalFlowImpl::PatchInverseSearch_ParBody::operator()(const Range &ran float dUx, dUy, i_I1, j_I1, w00, w01, w10, w11, dx, dy; #define INIT_BILINEAR_WEIGHTS(Ux, Uy) \ - i_I1 = min(max(i + Uy + bsz, i_lower_limit), i_upper_limit); \ - j_I1 = min(max(j + Ux + bsz, j_lower_limit), j_upper_limit); \ + i_I1 = std::min(std::max(i + Uy + bsz, i_lower_limit), i_upper_limit); \ + j_I1 = std::min(std::max(j + Ux + bsz, j_lower_limit), j_upper_limit); \ { \ float di = i_I1 - floor(i_I1); \ float dj = j_I1 - floor(j_I1); \ @@ -1110,8 +1110,8 @@ void DISOpticalFlowImpl::PatchInverseSearch_ParBody::operator()(const Range &ran if (iter % 2 == 0) { dir = 1; - start_is = min(range.start * stripe_sz, hs); - end_is = min(range.end * stripe_sz, hs); + start_is = std::min(range.start * stripe_sz, hs); + end_is = std::min(range.end * stripe_sz, hs); start_js = 0; end_js = dis->ws; start_i = start_is * dis->patch_stride; @@ -1120,8 +1120,8 @@ void DISOpticalFlowImpl::PatchInverseSearch_ParBody::operator()(const Range &ran else { dir = -1; - start_is = min(range.end * stripe_sz, hs) - 1; - end_is = min(range.start * stripe_sz, hs) - 1; + start_is = std::min(range.end * stripe_sz, hs) - 1; + end_is = std::min(range.start * stripe_sz, hs) - 1; start_js = dis->ws - 1; end_js = -1; start_i = start_is * dis->patch_stride; @@ -1264,8 +1264,8 @@ void DISOpticalFlowImpl::Densification_ParBody::operator()(const Range &range) c { CV_INSTRUMENT_REGION(); - int start_i = min(range.start * stripe_sz, h); - int end_i = min(range.end * stripe_sz, h); + int start_i = std::min(range.start * stripe_sz, h); + int end_i = std::min(range.end * stripe_sz, h); /* Input sparse flow */ float *Sx_ptr = Sx->ptr(); @@ -1358,7 +1358,7 @@ void DISOpticalFlowImpl::Densification_ParBody::operator()(const Range &range) c { float sx = Sx_ptr[is * dis->ws + js]; float sy = Sy_ptr[is * dis->ws + js]; - i_m = min(max(i + sy, 0.0f), dis->h - 1.0f - EPS); + i_m = std::min(std::max(i + sy, 0.0f), dis->h - 1.0f - EPS); i_l = (int)i_m; i_u = i_l + 1; v_float32 v_wi_u = vx_setall_f32(i_m - i_l); @@ -1428,8 +1428,8 @@ void DISOpticalFlowImpl::Densification_ParBody::operator()(const Range &range) c for (int is = start_is; is <= end_is; is++) for (int js = start_js; js <= end_js; js++) { - j_m = min(max(j + Sx_ptr[is * dis->ws + js], 0.0f), dis->w - 1.0f - EPS); - i_m = min(max(i + Sy_ptr[is * dis->ws + js], 0.0f), dis->h - 1.0f - EPS); + j_m = std::min(std::max(j + Sx_ptr[is * dis->ws + js], 0.0f), dis->w - 1.0f - EPS); + i_m = std::min(std::max(i + Sy_ptr[is * dis->ws + js], 0.0f), dis->h - 1.0f - EPS); j_l = (int)j_m; j_u = j_l + 1; i_l = (int)i_m; @@ -1438,7 +1438,7 @@ void DISOpticalFlowImpl::Densification_ParBody::operator()(const Range &range) c (j_u - j_m) * (i_m - i_l) * I1_ptr[i_u * dis->w + j_l] + (j_m - j_l) * (i_u - i_m) * I1_ptr[i_l * dis->w + j_u] + (j_u - j_m) * (i_u - i_m) * I1_ptr[i_l * dis->w + j_l] - I0_ptr[i * dis->w + j]; - coef = 1 / max(1.0f, abs(diff)); + coef = 1 / std::max(1.0f, abs(diff)); sum_Ux += coef * Sx_ptr[is * dis->ws + js]; sum_Uy += coef * Sy_ptr[is * dis->ws + js]; sum_coef += coef; @@ -1735,11 +1735,11 @@ bool DISOpticalFlowImpl::ocl_calc(InputArray I0, InputArray I1, InputOutputArray if (flow.sameSize(I0) && flow.depth() == CV_32F && flow.channels() == 2) use_input_flow = true; - int max_possible_scale = min((int)(log(max(I0Mat.cols, I0Mat.rows) / (4.0 * patch_size)) / log(2.0) + 0.5), /* Original code search for maximal movement of width/4 */ - (int)(log(min(I0Mat.cols, I0Mat.rows) / patch_size) / log(2.0))); /* Deepest pyramid level greater or equal than patch*/ + int max_possible_scale = std::min((int)(std::log2(std::max(I0Mat.cols, I0Mat.rows) / (4.0 * patch_size)) + 0.5), /* Original code search for maximal movement of width/4 */ + (int)(std::log2(std::min(I0Mat.cols, I0Mat.rows) / patch_size))); /* Deepest pyramid level greater or equal than patch*/ if (user_coarsest_scale != -1) - coarsest_scale = min(user_coarsest_scale, max_possible_scale); + coarsest_scale = std::min(user_coarsest_scale, max_possible_scale); else coarsest_scale = max_possible_scale; @@ -1823,11 +1823,11 @@ void DISOpticalFlowImpl::calc(InputArray I0, InputArray I1, InputOutputArray flo flow.create(I1Mat.size(), CV_32FC2); Mat flowMat = flow.getMat(); - int max_possible_scale = min((int)(log(max(I0Mat.cols, I0Mat.rows) / (4.0 * patch_size)) / log(2.0) + 0.5), /* Original code search for maximal movement of width/4 */ - (int)(log(min(I0Mat.cols, I0Mat.rows) / patch_size) / log(2.0))); /* Deepest pyramid level greater or equal than patch*/ + int max_possible_scale = std::min((int)(std::log2(std::max(I0Mat.cols, I0Mat.rows) / (4.0 * patch_size)) + 0.5), /* Original code search for maximal movement of width/4 */ + (int)(std::log2(std::min(I0Mat.cols, I0Mat.rows) / patch_size))); /* Deepest pyramid level greater or equal than patch*/ if (user_coarsest_scale != -1) - coarsest_scale = min(user_coarsest_scale, max_possible_scale); + coarsest_scale = std::min(user_coarsest_scale, max_possible_scale); else coarsest_scale = max_possible_scale; if (coarsest_scale<0) diff --git a/modules/video/src/tracking/detail/tracker_sampler_algorithm.cpp b/modules/video/src/tracking/detail/tracker_sampler_algorithm.cpp index ba5ae41b80..0b137b36ed 100644 --- a/modules/video/src/tracking/detail/tracker_sampler_algorithm.cpp +++ b/modules/video/src/tracking/detail/tracker_sampler_algorithm.cpp @@ -93,10 +93,10 @@ std::vector TrackerSamplerCSC::sampleImage(const Mat& img, int x, int y, in float outradsq = outrad * outrad; int dist; - uint minrow = max(0, (int)y - (int)inrad); - uint maxrow = min((int)rowsz - 1, (int)y + (int)inrad); - uint mincol = max(0, (int)x - (int)inrad); - uint maxcol = min((int)colsz - 1, (int)x + (int)inrad); + uint minrow = std::max(0, (int)y - (int)inrad); + uint maxrow = std::min((int)rowsz - 1, (int)y + (int)inrad); + uint mincol = std::max(0, (int)x - (int)inrad); + uint maxcol = std::min((int)colsz - 1, (int)x + (int)inrad); //fprintf(stderr,"inrad=%f minrow=%d maxrow=%d mincol=%d maxcol=%d\n",inrad,minrow,maxrow,mincol,maxcol); @@ -117,7 +117,7 @@ std::vector TrackerSamplerCSC::sampleImage(const Mat& img, int x, int y, in } } - samples.resize(min(i, maxnum)); + samples.resize(std::min(i, maxnum)); return samples; } diff --git a/modules/video/src/tracking/detail/tracking_feature.cpp b/modules/video/src/tracking/detail/tracking_feature.cpp index 0d9a88c1a5..0bea830afd 100644 --- a/modules/video/src/tracking/detail/tracking_feature.cpp +++ b/modules/video/src/tracking/detail/tracking_feature.cpp @@ -103,7 +103,7 @@ void CvHaarEvaluator::generateFeatures(int nFeatures) } } -#define INITSIGMA(numAreas) (static_cast(sqrt(256.0f * 256.0f / 12.0f * (numAreas)))); +#define INITSIGMA(numAreas) (static_cast(std::sqrt(256.0f * 256.0f / 12.0f * (numAreas)))); CvHaarEvaluator::FeatureHaar::FeatureHaar(Size patchSize) { @@ -137,8 +137,8 @@ void CvHaarEvaluator::FeatureHaar::generateRandomFeature(Size patchSize) position.y = rand() % (patchSize.height); position.x = rand() % (patchSize.width); - baseDim.width = (int)((1 - sqrt(1 - (float)rand() * (float)(1.0 / RAND_MAX))) * patchSize.width); - baseDim.height = (int)((1 - sqrt(1 - (float)rand() * (float)(1.0 / RAND_MAX))) * patchSize.height); + baseDim.width = (int)((1 - std::sqrt(1 - (float)rand() * (float)(1.0 / RAND_MAX))) * patchSize.width); + baseDim.height = (int)((1 - std::sqrt(1 - (float)rand() * (float)(1.0 / RAND_MAX))) * patchSize.height); //select types //float probType[11] = {0.0909f, 0.0909f, 0.0909f, 0.0909f, 0.0909f, 0.0909f, 0.0909f, 0.0909f, 0.0909f, 0.0909f, 0.0950f}; diff --git a/modules/video/src/tracking/detail/tracking_online_mil.cpp b/modules/video/src/tracking/detail/tracking_online_mil.cpp index ebfb31098f..36f6da8dd1 100644 --- a/modules/video/src/tracking/detail/tracking_online_mil.cpp +++ b/modules/video/src/tracking/detail/tracking_online_mil.cpp @@ -146,11 +146,11 @@ void ClfMilBoost::update(const Mat& posx, const Mat& negx) float lll = 1.0f; for (int j = 0; j < numpos; j++) lll *= (1 - sigmoid(Hpos[j] + pospred[w][j])); - poslikl[w] = (float)-log(1 - lll + 1e-5); + poslikl[w] = (float)-std::log(1 - lll + 1e-5); lll = 0.0f; for (int j = 0; j < numneg; j++) - lll += (float)-log(1e-5f + 1 - sigmoid(Hneg[j] + negpred[w][j])); + lll += (float)-std::log(1e-5f + 1 - sigmoid(Hneg[j] + negpred[w][j])); neglikl[w] = lll; likl[w] = poslikl[w] / numpos + neglikl[w] / numneg; @@ -286,8 +286,8 @@ void ClfOnlineStump::update(const Mat& posx, const Mat& negx, const Mat_& _q = (_mu1 - _mu0) / 2; _s = sign(_mu1 - _mu0); - _log_n0 = std::log(float(1.0f / std::pow(_sig0, 0.5f))); - _log_n1 = std::log(float(1.0f / std::pow(_sig1, 0.5f))); + _log_n0 = std::log(float(1.0f / std::sqrt(_sig0))); + _log_n1 = std::log(float(1.0f / std::sqrt(_sig1))); //_e1 = -1.0f/(2.0f*_sig1+1e-99f); //_e0 = -1.0f/(2.0f*_sig0+1e-99f); _e1 = -1.0f / (2.0f * _sig1 + std::numeric_limits::min()); @@ -314,8 +314,8 @@ void ClfOnlineStump::update(const Mat& posx, const Mat& negx, const Mat_& _q = (_mu1 - _mu0) / 2; _s = sign(_mu1 - _mu0); - _log_n0 = std::log(float(1.0f / std::pow(_sig0, 0.5f))); - _log_n1 = std::log(float(1.0f / std::pow(_sig1, 0.5f))); + _log_n0 = std::log(float(1.0f / std::sqrt(_sig0))); + _log_n1 = std::log(float(1.0f / std::sqrt(_sig1))); //_e1 = -1.0f/(2.0f*_sig1+1e-99f); //_e0 = -1.0f/(2.0f*_sig0+1e-99f); _e1 = -1.0f / (2.0f * _sig1 + std::numeric_limits::min()); diff --git a/modules/video/src/tracking/detail/tracking_online_mil.hpp b/modules/video/src/tracking/detail/tracking_online_mil.hpp index b08a628296..7c090e699e 100644 --- a/modules/video/src/tracking/detail/tracking_online_mil.hpp +++ b/modules/video/src/tracking/detail/tracking_online_mil.hpp @@ -38,7 +38,7 @@ public: inline float sigmoid(float x) { - return 1.0f / (1.0f + exp(-x)); + return 1.0f / (1.0f + std::exp(-x)); } private: diff --git a/modules/video/src/tracking/tracker_dasiamrpn.cpp b/modules/video/src/tracking/tracker_dasiamrpn.cpp index dfb8a41009..d6d29c4fb8 100644 --- a/modules/video/src/tracking/tracker_dasiamrpn.cpp +++ b/modules/video/src/tracking/tracker_dasiamrpn.cpp @@ -41,7 +41,7 @@ T sizeCal(const T& w, const T& h) { T pad = (w + h) * T(0.5); T sz2 = (w + pad) * (h + pad); - return sqrt(sz2); + return std::sqrt(sz2); } template <> @@ -159,7 +159,7 @@ void TrackerDaSiamRPNImpl::trackerInit(Mat img) trackState.avgChans = mean(img); float wc = targetBox.width + trackState.contextAmount * (targetBox.width + targetBox.height); float hc = targetBox.height + trackState.contextAmount * (targetBox.width + targetBox.height); - float sz = (float)cvRound(sqrt(wc * hc)); + float sz = (float)cvRound(std::sqrt(wc * hc)); Mat zCrop = getSubwindow(img, targetBox, sz, trackState.avgChans); Mat blob; @@ -200,7 +200,7 @@ void TrackerDaSiamRPNImpl::trackerEval(Mat img) float wc = targetBox.height + trackState.contextAmount * (targetBox.width + targetBox.height); float hc = targetBox.width + trackState.contextAmount * (targetBox.width + targetBox.height); - float sz = sqrt(wc * hc); + float sz = std::sqrt(wc * hc); float scaleZ = trackState.exemplarSize / sz; float searchSize = float((trackState.instanceSize - trackState.exemplarSize) / 2); @@ -363,7 +363,7 @@ Mat TrackerDaSiamRPNImpl::generateAnchors() for (auto i = 0; i < anchorNum; i++) { - int ws = int(sqrt(size / ratios[i])); + int ws = int(std::sqrt(size / ratios[i])); int hs = int(ws * ratios[i]); float wws = float(ws) * scales; diff --git a/modules/video/src/tracking/tracker_nano.cpp b/modules/video/src/tracking/tracker_nano.cpp index 1689a5d904..2b21c1a643 100644 --- a/modules/video/src/tracking/tracker_nano.cpp +++ b/modules/video/src/tracking/tracker_nano.cpp @@ -59,7 +59,7 @@ static float sizeCal(float w, float h) { float pad = (w + h) * 0.5f; float sz2 = (w + pad) * (h + pad); - return sqrt(sz2); + return std::sqrt(sz2); } static Mat sizeCal(const Mat& w, const Mat& h) @@ -187,7 +187,7 @@ void TrackerNanoImpl::init(InputArray image_, const Rect &boundingBox_) float sumSz = targetSz[0] + targetSz[1]; float wExtent = targetSz[0] + trackState.contextAmount * (sumSz); float hExtent = targetSz[1] + trackState.contextAmount * (sumSz); - int sz = int(cv::sqrt(wExtent * hExtent)); + int sz = int(std::sqrt(wExtent * hExtent)); Mat crop; getSubwindow(crop, image, sz, exemplarSize); @@ -246,7 +246,7 @@ bool TrackerNanoImpl::update(InputArray image_, Rect &boundingBoxRes) float wc = targetSz[0] + trackState.contextAmount * targetSzSum; float hc = targetSz[1] + trackState.contextAmount * targetSzSum; - float sz = cv::sqrt(wc * hc); + float sz = std::sqrt(wc * hc); float scale_z = exemplarSize / sz; float sx = sz * (float(instanceSize) / exemplarSize); targetSz[0] *= scale_z; diff --git a/modules/video/src/tracking/tracker_vit.cpp b/modules/video/src/tracking/tracker_vit.cpp index cb5b4322c4..2c4cea6a28 100644 --- a/modules/video/src/tracking/tracker_vit.cpp +++ b/modules/video/src/tracking/tracker_vit.cpp @@ -98,7 +98,7 @@ protected: static int crop_image(const Mat& src, Mat& dst, Rect box, int factor) { int x = box.x, y = box.y, w = box.width, h = box.height; - int crop_sz = cvCeil(sqrt(w * h) * factor); + int crop_sz = cvCeil(std::sqrt(w * h) * factor); int x1 = x + (w - crop_sz) / 2; int x2 = x1 + crop_sz; diff --git a/modules/video/src/variational_refinement.cpp b/modules/video/src/variational_refinement.cpp index 889d032031..086488588a 100644 --- a/modules/video/src/variational_refinement.cpp +++ b/modules/video/src/variational_refinement.cpp @@ -582,8 +582,8 @@ void VariationalRefinementImpl::ComputeDataTerm_ParBody::operator()(const Range { CV_INSTRUMENT_REGION(); - int start_i = min(range.start * stripe_sz, h); - int end_i = min(range.end * stripe_sz, h); + int start_i = std::min(range.start * stripe_sz, h); + int end_i = std::min(range.end * stripe_sz, h); float zeta_squared = var->zeta * var->zeta; float epsilon_squared = var->epsilon * var->epsilon; @@ -698,7 +698,7 @@ void VariationalRefinementImpl::ComputeDataTerm_ParBody::operator()(const Range /* Color constancy penalty (computed by Taylor expansion):*/ Ik1z = pIz[j] + pIx[j] * pdU[j] + pIy[j] * pdV[j]; /* Weight of the color constancy term in the current fixed-point iteration divided by derivNorm: */ - weight = (delta2 / sqrt(Ik1z * Ik1z / derivNorm + epsilon_squared)) / derivNorm; + weight = (delta2 / std::sqrt(Ik1z * Ik1z / derivNorm + epsilon_squared)) / derivNorm; /* Add respective color constancy terms to the linear system coefficients: */ pa11[j] = weight * (pIx[j] * pIx[j]) + zeta_squared; pa12[j] = weight * (pIx[j] * pIy[j]); @@ -715,7 +715,7 @@ void VariationalRefinementImpl::ComputeDataTerm_ParBody::operator()(const Range Ik1zx = pIxz[j] + pIxx[j] * pdU[j] + pIxy[j] * pdV[j]; Ik1zy = pIyz[j] + pIxy[j] * pdU[j] + pIyy[j] * pdV[j]; /* Weight of the gradient constancy term in the current fixed-point iteration: */ - weight = gamma2 / sqrt(Ik1zx * Ik1zx / derivNorm + Ik1zy * Ik1zy / derivNorm2 + epsilon_squared); + weight = gamma2 / std::sqrt(Ik1zx * Ik1zx / derivNorm + Ik1zy * Ik1zy / derivNorm2 + epsilon_squared); /* Add respective gradient constancy components to the linear system coefficients: */ pa11[j] += weight * (pIxx[j] * pIxx[j] / derivNorm + pIxy[j] * pIxy[j] / derivNorm2); pa12[j] += weight * (pIxx[j] * pIxy[j] / derivNorm + pIxy[j] * pIyy[j] / derivNorm2); @@ -744,8 +744,8 @@ void VariationalRefinementImpl::ComputeSmoothnessTermHorPass_ParBody::operator() { CV_INSTRUMENT_REGION(); - int start_i = min(range.start * stripe_sz, h); - int end_i = min(range.end * stripe_sz, h); + int start_i = std::min(range.start * stripe_sz, h); + int end_i = std::min(range.end * stripe_sz, h); float epsilon_squared = var->epsilon * var->epsilon; float alpha2 = var->alpha / 2; @@ -826,7 +826,7 @@ void VariationalRefinementImpl::ComputeSmoothnessTermHorPass_ParBody::operator() uy = cW_u_next_row[j] - cW_u[j]; \ vy = cW_v_next_row[j] - cW_v[j]; \ /* Weight of the smoothness term in the current fixed-point iteration: */ \ - pWeight[j] = alpha2 / sqrt(ux * ux + vx * vx + uy * uy + vy * vy + epsilon_squared); \ + pWeight[j] = alpha2 / std::sqrt(ux * ux + vx * vx + uy * uy + vy * vy + epsilon_squared); \ /* Gradients for initial raw flow multiplied by weight:*/ \ ux = pWeight[j] * (pW_u_next[j] - pW_u[j]); \ vx = pWeight[j] * (pW_v_next[j] - pW_v[j]); @@ -912,8 +912,8 @@ void VariationalRefinementImpl::ComputeSmoothnessTermVertPass_ParBody::operator( { CV_INSTRUMENT_REGION(); - int start_i = min(range.start * stripe_sz, h); - int end_i = min(range.end * stripe_sz, h); + int start_i = std::min(range.start * stripe_sz, h); + int end_i = std::min(range.end * stripe_sz, h); float *pWeight; float *pA_u, *pA_u_next_row, *pA_v, *pA_v_next_row; @@ -1008,8 +1008,8 @@ void VariationalRefinementImpl::RedBlackSOR_ParBody::operator()(const Range &ran { CV_INSTRUMENT_REGION(); - int start = min(range.start * stripe_sz, h); - int end = min(range.end * stripe_sz, h); + int start = std::min(range.start * stripe_sz, h); + int end = std::min(range.end * stripe_sz, h); float *pa11, *pa12, *pa22, *pb1, *pb2, *pW, *pdu, *pdv; float *pW_next, *pdu_next, *pdv_next; diff --git a/modules/videoio/src/cap_aravis.cpp b/modules/videoio/src/cap_aravis.cpp index 9dd27f8014..3e3e5717e9 100644 --- a/modules/videoio/src/cap_aravis.cpp +++ b/modules/videoio/src/cap_aravis.cpp @@ -91,7 +91,7 @@ using namespace cv; #define MODE_Y16 CV_FOURCC_MACRO('Y','1','6',' ') #define MODE_GRBG CV_FOURCC_MACRO('G','R','B','G') -#define CLIP(a,b,c) (cv::max(cv::min((a),(c)),(b))) +#define CLIP(a,b,c) (std::max(std::min((a),(c)),(b))) /********************* Capturing video from camera via Aravis *********************/ diff --git a/samples/cpp/snippets/polar_transforms.cpp b/samples/cpp/snippets/polar_transforms.cpp index 9c2f798263..3389dd05d7 100644 --- a/samples/cpp/snippets/polar_transforms.cpp +++ b/samples/cpp/snippets/polar_transforms.cpp @@ -45,7 +45,7 @@ int main( int argc, char** argv ) break; Point2f center( (float)src.cols / 2, (float)src.rows / 2 ); - double maxRadius = 0.7*min(center.y, center.x); + double maxRadius = 0.7*std::min(center.y, center.x); //! [InverseMap] // direct transform using warpPolar (replacing deprecated functions) diff --git a/samples/cpp/tutorial_code/ImgProc/Threshold_inRange.cpp b/samples/cpp/tutorial_code/ImgProc/Threshold_inRange.cpp index d2ced1fcfd..c806369df8 100644 --- a/samples/cpp/tutorial_code/ImgProc/Threshold_inRange.cpp +++ b/samples/cpp/tutorial_code/ImgProc/Threshold_inRange.cpp @@ -16,7 +16,7 @@ int high_H = max_value_H, high_S = max_value, high_V = max_value; //! [low] static void on_low_H_thresh_trackbar(int, void *) { - low_H = min(high_H-1, low_H); + low_H = std::min(high_H-1, low_H); setTrackbarPos("Low H", window_detection_name, low_H); } //! [low] @@ -24,32 +24,32 @@ static void on_low_H_thresh_trackbar(int, void *) //! [high] static void on_high_H_thresh_trackbar(int, void *) { - high_H = max(high_H, low_H+1); + high_H = std::max(high_H, low_H+1); setTrackbarPos("High H", window_detection_name, high_H); } //! [high] static void on_low_S_thresh_trackbar(int, void *) { - low_S = min(high_S-1, low_S); + low_S = std::min(high_S-1, low_S); setTrackbarPos("Low S", window_detection_name, low_S); } static void on_high_S_thresh_trackbar(int, void *) { - high_S = max(high_S, low_S+1); + high_S = std::max(high_S, low_S+1); setTrackbarPos("High S", window_detection_name, high_S); } static void on_low_V_thresh_trackbar(int, void *) { - low_V = min(high_V-1, low_V); + low_V = std::min(high_V-1, low_V); setTrackbarPos("Low V", window_detection_name, low_V); } static void on_high_V_thresh_trackbar(int, void *) { - high_V = max(high_V, low_V+1); + high_V = std::max(high_V, low_V+1); setTrackbarPos("High V", window_detection_name, high_V); } diff --git a/samples/cpp/tutorial_code/photo/seamless_cloning/cloning_gui.cpp b/samples/cpp/tutorial_code/photo/seamless_cloning/cloning_gui.cpp index 1bde7ee5e4..78c2169e2e 100644 --- a/samples/cpp/tutorial_code/photo/seamless_cloning/cloning_gui.cpp +++ b/samples/cpp/tutorial_code/photo/seamless_cloning/cloning_gui.cpp @@ -35,6 +35,7 @@ #include "opencv2/imgproc.hpp" #include "opencv2/highgui.hpp" #include "opencv2/core.hpp" +#include #include #include @@ -117,10 +118,10 @@ void source(int event, int x, int y, int, void*) for(int i=0;i im1.size().width || maxyd > im1.size().height || minxd < 0 || minyd < 0) @@ -475,10 +476,10 @@ int main() for(int i=0;i