From 400572b19f01ebda905c828c6ed43d61156c4de7 Mon Sep 17 00:00:00 2001 From: whuaegeansea Date: Wed, 1 Feb 2023 01:34:22 +0800 Subject: [PATCH 1/4] Fix bug --- modules/features2d/src/sift.simd.hpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/modules/features2d/src/sift.simd.hpp b/modules/features2d/src/sift.simd.hpp index d2fe0bb429..70f773b7bd 100644 --- a/modules/features2d/src/sift.simd.hpp +++ b/modules/features2d/src/sift.simd.hpp @@ -850,7 +850,6 @@ else // CV_8U #endif } #else - float* dst = dstMat.ptr(row); float nrm1 = 0; for( k = 0; k < len; k++ ) { @@ -858,20 +857,22 @@ else // CV_8U nrm1 += rawDst[k]; } nrm1 = 1.f/std::max(nrm1, FLT_EPSILON); -if( dstMat.type() == CV_32F ) -{ - for( k = 0; k < len; k++ ) + if( dstMat.type() == CV_32F ) { - dst[k] = std::sqrt(rawDst[k] * nrm1); + float *dst = dstMat.ptr(row); + for( k = 0; k < len; k++ ) + { + dst[k] = std::sqrt(rawDst[k] * nrm1); + } } -} -else // CV_8U -{ - for( k = 0; k < len; k++ ) + else // CV_8U { - dst[k] = saturate_cast(std::sqrt(rawDst[k] * nrm1)*SIFT_INT_DESCR_FCTR); + uint8_t *dst = dstMat.ptr(row); + for( k = 0; k < len; k++ ) + { + dst[k] = saturate_cast(std::sqrt(rawDst[k] * nrm1)*SIFT_INT_DESCR_FCTR); + } } -} #endif } From 3d635cb4a7fa5e6a5190768092d45d3bb685e45d Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Thu, 2 Feb 2023 13:57:20 +0300 Subject: [PATCH 2/4] Warning supression fix for XCode 13.1 and newer. Backport #23203 --- 3rdparty/libpng/CMakeLists.txt | 5 +++++ modules/calib3d/test/test_cameracalibration.cpp | 9 --------- modules/flann/include/opencv2/flann/index_testing.h | 2 -- modules/ml/src/kdtree.cpp | 3 --- modules/ts/include/opencv2/ts.hpp | 3 +++ modules/video/test/test_optflowpyrlk.cpp | 3 +-- 6 files changed, 9 insertions(+), 16 deletions(-) diff --git a/3rdparty/libpng/CMakeLists.txt b/3rdparty/libpng/CMakeLists.txt index f72b966079..921391eadf 100644 --- a/3rdparty/libpng/CMakeLists.txt +++ b/3rdparty/libpng/CMakeLists.txt @@ -66,6 +66,11 @@ if(PPC64LE OR PPC64) endif() endif() +if(APPLE AND CV_CLANG AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 13.1) + ocv_warnings_disable(CMAKE_C_FLAGS -Wnull-pointer-subtraction) + ocv_warnings_disable(CMAKE_C_FLAGS -Wunused-but-set-variable) +endif() + # ---------------------------------------------------------------------------------- # Define the library target: # ---------------------------------------------------------------------------------- diff --git a/modules/calib3d/test/test_cameracalibration.cpp b/modules/calib3d/test/test_cameracalibration.cpp index a63c131a0f..407b9004b1 100644 --- a/modules/calib3d/test/test_cameracalibration.cpp +++ b/modules/calib3d/test/test_cameracalibration.cpp @@ -559,12 +559,9 @@ void CV_CameraCalibrationTest::run( int start_from ) i = 0; double dx,dy; double rx,ry; - double meanDx,meanDy; double maxDx = 0.0; double maxDy = 0.0; - meanDx = 0; - meanDy = 0; for( currImage = 0; currImage < numImages; currImage++ ) { double imageMeanDx = 0; @@ -576,9 +573,6 @@ void CV_CameraCalibrationTest::run( int start_from ) dx = rx - imagePoints[i].x; dy = ry - imagePoints[i].y; - meanDx += dx; - meanDy += dy; - imageMeanDx += dx*dx; imageMeanDy += dy*dy; @@ -601,9 +595,6 @@ void CV_CameraCalibrationTest::run( int start_from ) perViewErrors[currImage] = goodPerViewErrors[currImage]; } - meanDx /= numImages * etalonSize.width * etalonSize.height; - meanDy /= numImages * etalonSize.width * etalonSize.height; - /* ========= Compare parameters ========= */ /* ----- Compare focal lengths ----- */ diff --git a/modules/flann/include/opencv2/flann/index_testing.h b/modules/flann/include/opencv2/flann/index_testing.h index 207adef449..4c00143326 100644 --- a/modules/flann/include/opencv2/flann/index_testing.h +++ b/modules/flann/include/opencv2/flann/index_testing.h @@ -246,7 +246,6 @@ void test_index_precisions(NNIndex& index, const Matrix& index, const Matrix 0)&&(time > maxTime)&&(p2 middle; k-- ) { CV_Assert(vals[ofs[k]] >= pivot); - more += vals[ofs[k]] > pivot; } return vals[ofs[middle]]; diff --git a/modules/ts/include/opencv2/ts.hpp b/modules/ts/include/opencv2/ts.hpp index 5364143d15..3777c8eb2b 100644 --- a/modules/ts/include/opencv2/ts.hpp +++ b/modules/ts/include/opencv2/ts.hpp @@ -122,6 +122,9 @@ //#pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wsuggest-override" #endif +#if defined(__OPENCV_BUILD) && defined(__APPLE__) && defined(__clang__) && ((__clang_major__*100 + __clang_minor__) >= 1301) +#pragma clang diagnostic ignored "-Wdeprecated-copy" +#endif #include "opencv2/ts/ts_gtest.h" #if defined(__OPENCV_BUILD) && defined(__GNUC__) && __GNUC__ >= 5 //#pragma GCC diagnostic pop diff --git a/modules/video/test/test_optflowpyrlk.cpp b/modules/video/test/test_optflowpyrlk.cpp index 1f08270ec7..a7e9a2d3a5 100644 --- a/modules/video/test/test_optflowpyrlk.cpp +++ b/modules/video/test/test_optflowpyrlk.cpp @@ -65,7 +65,7 @@ void CV_OptFlowPyrLKTest::run( int ) const int bad_points_max = 8; /* test parameters */ - double max_err = 0., sum_err = 0; + double max_err = 0.; int pt_cmpd = 0; int pt_exceed = 0; int merr_i = 0, merr_j = 0, merr_k = 0, merr_nan = 0; @@ -175,7 +175,6 @@ void CV_OptFlowPyrLKTest::run( int ) } pt_exceed += err > success_error_level; - sum_err += err; pt_cmpd++; } else From c280cd7290c11c8e9f4d4ed9cb24ca16483ee29c Mon Sep 17 00:00:00 2001 From: Ibai Gorordo <43162939+ibaiGorordo@users.noreply.github.com> Date: Thu, 9 Feb 2023 02:33:06 +0900 Subject: [PATCH 3/4] Merge pull request #23210 from ibaiGorordo:rect_nfa_bugfix Fix rect_nfa (lsd) * Fix missing log_gamma in nfa() Comparing the nfa function with the function in the binomial_nfa repository (https://github.com/rafael-grompone-von-gioi/binomial_nfa/blob/main/C99/log_binomial_nfa.c#L152), the first log_gamma call is missing. * Fix rect_nfa pixel index * Replace std::rotate * Rename tmp to v_tmp * Replace auto and std::min_element * Change slope equality check to int * Fix left limit check --- modules/imgproc/src/lsd.cpp | 154 ++++++++++++------------------------ 1 file changed, 50 insertions(+), 104 deletions(-) diff --git a/modules/imgproc/src/lsd.cpp b/modules/imgproc/src/lsd.cpp index c4a77ee265..2f13c5a8a0 100644 --- a/modules/imgproc/src/lsd.cpp +++ b/modules/imgproc/src/lsd.cpp @@ -69,12 +69,6 @@ const double DEG_TO_RADS = CV_PI / 180; #define log_gamma(x) ((x)>15.0?log_gamma_windschitl(x):log_gamma_lanczos(x)) -struct edge -{ - cv::Point p; - bool taken; -}; - ///////////////////////////////////////////////////////////////////////////////////////// inline double distSq(const double x1, const double y1, @@ -120,10 +114,20 @@ inline bool double_equal(const double& a, const double& b) return (abs_diff / abs_max) <= (RELATIVE_ERROR_FACTOR * DBL_EPSILON); } -inline bool AsmallerB_XoverY(const edge& a, const edge& b) -{ - if (a.p.x == b.p.x) return a.p.y < b.p.y; - else return a.p.x < b.p.x; +// function to sort points by y and then by x +inline bool AsmallerB_YoverX(const cv::Point2d &a, const cv::Point2d &b) { + if (a.y == b.y) return a.x < b.x; + else return a.y < b.y; +} + +// function to get the slope of the rectangle for a specific row +inline double get_slope(cv::Point2d p1, cv::Point2d p2) { + return ((int) ceil(p2.y) != (int) ceil(p1.y)) ? (p2.x - p1.x) / (p2.y - p1.y) : 0; +} + +// function to get the limit of the rectangle for a specific row +inline double get_limit(cv::Point2d p, int row, double slope) { + return p.x + (row - p.y) * slope; } /** @@ -945,105 +949,53 @@ double LineSegmentDetectorImpl::rect_nfa(const rect& rec) const double dyhw = rec.dy * half_width; double dxhw = rec.dx * half_width; - edge ordered_x[4]; - edge* min_y = &ordered_x[0]; - edge* max_y = &ordered_x[0]; // Will be used for loop range - - ordered_x[0].p.x = int(rec.x1 - dyhw); ordered_x[0].p.y = int(rec.y1 + dxhw); ordered_x[0].taken = false; - ordered_x[1].p.x = int(rec.x2 - dyhw); ordered_x[1].p.y = int(rec.y2 + dxhw); ordered_x[1].taken = false; - ordered_x[2].p.x = int(rec.x2 + dyhw); ordered_x[2].p.y = int(rec.y2 - dxhw); ordered_x[2].taken = false; - ordered_x[3].p.x = int(rec.x1 + dyhw); ordered_x[3].p.y = int(rec.y1 - dxhw); ordered_x[3].taken = false; - - std::sort(ordered_x, ordered_x + 4, AsmallerB_XoverY); - - // Find min y. And mark as taken. find max y. - for(unsigned int i = 1; i < 4; ++i) - { - if(min_y->p.y > ordered_x[i].p.y) {min_y = &ordered_x[i]; } - if(max_y->p.y < ordered_x[i].p.y) {max_y = &ordered_x[i]; } - } - min_y->taken = true; - - // Find leftmost untaken point; - edge* leftmost = 0; - for(unsigned int i = 0; i < 4; ++i) - { - if(!ordered_x[i].taken) - { - if(!leftmost) // if uninitialized - { - leftmost = &ordered_x[i]; - } - else if (leftmost->p.x > ordered_x[i].p.x) - { - leftmost = &ordered_x[i]; - } - } - } - CV_Assert(leftmost != NULL); - leftmost->taken = true; - - // Find rightmost untaken point; - edge* rightmost = 0; - for(unsigned int i = 0; i < 4; ++i) - { - if(!ordered_x[i].taken) - { - if(!rightmost) // if uninitialized - { - rightmost = &ordered_x[i]; - } - else if (rightmost->p.x < ordered_x[i].p.x) - { - rightmost = &ordered_x[i]; - } + cv::Point2d v_tmp[4]; + v_tmp[0] = cv::Point2d(rec.x1 - dyhw, rec.y1 + dxhw); + v_tmp[1] = cv::Point2d(rec.x2 - dyhw, rec.y2 + dxhw); + v_tmp[2] = cv::Point2d(rec.x2 + dyhw, rec.y2 - dxhw); + v_tmp[3] = cv::Point2d(rec.x1 + dyhw, rec.y1 - dxhw); + + // Find the vertex with the smallest y coordinate (or the smallest x if there is a tie). + int offset = 0; + for (int i = 1; i < 4; ++i) { + if (AsmallerB_YoverX(v_tmp[i], v_tmp[offset])){ + offset = i; } } - CV_Assert(rightmost != NULL); - rightmost->taken = true; - // Find last untaken point; - edge* tailp = 0; - for(unsigned int i = 0; i < 4; ++i) - { - if(!ordered_x[i].taken) - { - if(!tailp) // if uninitialized - { - tailp = &ordered_x[i]; - } - else if (tailp->p.x > ordered_x[i].p.x) - { - tailp = &ordered_x[i]; - } - } + // Rotate the vertices so that the first one is the one with the smallest y coordinate (or the smallest x if there is a tie). + // The rest will be then ordered counterclockwise. + cv::Point2d ordered_y[4]; + for (int i = 0; i < 4; ++i) { + ordered_y[i] = v_tmp[(i + offset) % 4]; } - CV_Assert(tailp != NULL); - tailp->taken = true; - - double flstep = (min_y->p.y != leftmost->p.y) ? - (min_y->p.x - leftmost->p.x) / (min_y->p.y - leftmost->p.y) : 0; //first left step - double slstep = (leftmost->p.y != tailp->p.x) ? - (leftmost->p.x - tailp->p.x) / (leftmost->p.y - tailp->p.x) : 0; //second left step - double frstep = (min_y->p.y != rightmost->p.y) ? - (min_y->p.x - rightmost->p.x) / (min_y->p.y - rightmost->p.y) : 0; //first right step - double srstep = (rightmost->p.y != tailp->p.x) ? - (rightmost->p.x - tailp->p.x) / (rightmost->p.y - tailp->p.x) : 0; //second right step + double flstep = get_slope(ordered_y[0], ordered_y[1]); //first left step + double slstep = get_slope(ordered_y[1], ordered_y[2]); //second left step - double lstep = flstep, rstep = frstep; + double frstep = get_slope(ordered_y[0], ordered_y[3]); //first right step + double srstep = get_slope(ordered_y[3], ordered_y[2]); //second right step - double left_x = min_y->p.x, right_x = min_y->p.x; + double top_y = ordered_y[0].y, bottom_y = ordered_y[2].y; // Loop around all points in the region and count those that are aligned. - int min_iter = min_y->p.y; - int max_iter = max_y->p.y; - for(int y = min_iter; y <= max_iter; ++y) + std::vector points; + double left_limit, right_limit; + for(int y = (int) ceil(top_y); y <= (int) ceil(bottom_y); ++y) { if (y < 0 || y >= img_height) continue; - for(int x = int(left_x); x <= int(right_x); ++x) - { + if(y <= int(ceil(ordered_y[1].y))) + left_limit = get_limit(ordered_y[0], y, flstep); + else + left_limit = get_limit(ordered_y[1], y, slstep); + + if(y < int(ceil(ordered_y[3].y))) + right_limit = get_limit(ordered_y[0], y, frstep); + else + right_limit = get_limit(ordered_y[3], y, srstep); + + for(int x = (int) ceil(left_limit); x <= (int)(right_limit); ++x) { if (x < 0 || x >= img_width) continue; ++total_pts; @@ -1052,12 +1004,6 @@ double LineSegmentDetectorImpl::rect_nfa(const rect& rec) const ++alg_pts; } } - - if(y >= leftmost->p.y) { lstep = slstep; } - if(y >= rightmost->p.y) { rstep = srstep; } - - left_x += lstep; - right_x += rstep; } return nfa(total_pts, alg_pts, rec.p); @@ -1071,7 +1017,7 @@ double LineSegmentDetectorImpl::nfa(const int& n, const int& k, const double& p) double p_term = p / (1 - p); - double log1term = (double(n) + 1) - log_gamma(double(k) + 1) + 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); From 56102737d775f147a0a99578cbad3e218a3633d3 Mon Sep 17 00:00:00 2001 From: Yannis Guyon Date: Fri, 10 Feb 2023 23:46:21 +0100 Subject: [PATCH 4/4] Merge pull request #23131 from y-guyon:align_ptr_intrin_sse Fix misaligned-pointer-use in intrin_sse.hpp * Fix misaligned-pointer-use in intrin_sse.hpp * Use _mm_loadu_si32() instead of memcpy() * Use CV_DECL_ALIGNED instead of _mm_loadu_si32() --- modules/core/include/opencv2/core/hal/intrin_sse.hpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/modules/core/include/opencv2/core/hal/intrin_sse.hpp b/modules/core/include/opencv2/core/hal/intrin_sse.hpp index 443ee16097..9d17f71666 100644 --- a/modules/core/include/opencv2/core/hal/intrin_sse.hpp +++ b/modules/core/include/opencv2/core/hal/intrin_sse.hpp @@ -1921,11 +1921,12 @@ OPENCV_HAL_IMPL_SSE_EXPAND(v_int16x8, v_int32x4, short, _v128_cvtepi16_epi OPENCV_HAL_IMPL_SSE_EXPAND(v_uint32x4, v_uint64x2, unsigned, _v128_cvtepu32_epi64) OPENCV_HAL_IMPL_SSE_EXPAND(v_int32x4, v_int64x2, int, _v128_cvtepi32_epi64) -#define OPENCV_HAL_IMPL_SSE_EXPAND_Q(_Tpvec, _Tp, intrin) \ - inline _Tpvec v_load_expand_q(const _Tp* ptr) \ - { \ - __m128i a = _mm_cvtsi32_si128(*(const int*)ptr); \ - return _Tpvec(intrin(a)); \ +#define OPENCV_HAL_IMPL_SSE_EXPAND_Q(_Tpvec, _Tp, intrin) \ + inline _Tpvec v_load_expand_q(const _Tp* ptr) \ + { \ + typedef int CV_DECL_ALIGNED(1) unaligned_int; \ + __m128i a = _mm_cvtsi32_si128(*(const unaligned_int*)ptr); \ + return _Tpvec(intrin(a)); \ } OPENCV_HAL_IMPL_SSE_EXPAND_Q(v_uint32x4, uchar, _v128_cvtepu8_epi32)