Skip to content

Commit 0a3a2df

Browse files
committed
fixed U non-orthogonality in SVD (http://code.opencv.org/issues/3801)
1 parent b28d134 commit 0a3a2df

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

modules/core/src/lapack.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ JacobiSVDImpl_(_Tp* At, size_t astep, _Tp* _W, _Tp* Vt, size_t vstep,
688688
At[i*astep + k] = t;
689689
asum += std::abs(t);
690690
}
691-
asum = asum ? 1/asum : 0;
691+
asum = asum > eps * 100 ? 1 / asum : 0;
692692
for( k = 0; k < m; k++ )
693693
At[i*astep + k] *= asum;
694694
}

modules/core/test/test_mat.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,20 @@ TEST(Core_Mat, copyNx1ToVector)
919919
ASSERT_PRED_FORMAT2(cvtest::MatComparator(0, 0), ref_dst16, cv::Mat_<ushort>(dst16));
920920
}
921921

922+
TEST(Core_SVD, orthogonality)
923+
{
924+
for (int i = 0; i < 2; i++)
925+
{
926+
int type = i == 0 ? CV_32F : CV_64F;
927+
Mat mat_D(2, 2, type);
928+
mat_D.setTo(88.);
929+
Mat mat_U, mat_W;
930+
SVD::compute(mat_D, mat_W, mat_U, noArray(), SVD::FULL_UV);
931+
mat_U *= mat_U.t();
932+
ASSERT_LT(norm(mat_U, Mat::eye(2, 2, type), NORM_INF), 1e-5);
933+
}
934+
}
935+
922936
TEST(Core_Mat, multiDim)
923937
{
924938
int d[]={3,3,3};

0 commit comments

Comments
 (0)