diff --git a/modules/core/src/lapack.cpp b/modules/core/src/lapack.cpp index 7ee84a6d45..0168610572 100644 --- a/modules/core/src/lapack.cpp +++ b/modules/core/src/lapack.cpp @@ -688,7 +688,7 @@ JacobiSVDImpl_(_Tp* At, size_t astep, _Tp* _W, _Tp* Vt, size_t vstep, At[i*astep + k] = t; asum += std::abs(t); } - asum = asum ? 1/asum : 0; + asum = asum > eps * 100 ? 1 / asum : 0; for( k = 0; k < m; k++ ) At[i*astep + k] *= asum; } diff --git a/modules/core/test/test_mat.cpp b/modules/core/test/test_mat.cpp index f854abed7e..0aef147b60 100644 --- a/modules/core/test/test_mat.cpp +++ b/modules/core/test/test_mat.cpp @@ -919,6 +919,20 @@ TEST(Core_Mat, copyNx1ToVector) ASSERT_PRED_FORMAT2(cvtest::MatComparator(0, 0), ref_dst16, cv::Mat_(dst16)); } +TEST(Core_SVD, orthogonality) +{ + for (int i = 0; i < 2; i++) + { + int type = i == 0 ? CV_32F : CV_64F; + Mat mat_D(2, 2, type); + mat_D.setTo(88.); + Mat mat_U, mat_W; + SVD::compute(mat_D, mat_W, mat_U, noArray(), SVD::FULL_UV); + mat_U *= mat_U.t(); + ASSERT_LT(norm(mat_U, Mat::eye(2, 2, type), NORM_INF), 1e-5); + } +} + TEST(Core_Mat, multiDim) { int d[]={3,3,3};