From fd901d8323b6eb6d6491f8d1058b47413d96fe1f Mon Sep 17 00:00:00 2001 From: Vadim Pisarevsky Date: Thu, 28 Jun 2012 15:52:34 +0000 Subject: [PATCH] fixed #2108 (thanks to Vincent for the report and proposed solution) --- modules/core/include/opencv2/core/mat.hpp | 3 ++- modules/core/test/test_operations.cpp | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/modules/core/include/opencv2/core/mat.hpp b/modules/core/include/opencv2/core/mat.hpp index 1c79f50..ccc0257 100644 --- a/modules/core/include/opencv2/core/mat.hpp +++ b/modules/core/include/opencv2/core/mat.hpp @@ -759,7 +759,8 @@ inline SVD::SVD() {} inline SVD::SVD( InputArray m, int flags ) { operator ()(m, flags); } inline void SVD::solveZ( InputArray m, OutputArray _dst ) { - SVD svd(m); + Mat mtx = m.getMat(); + SVD svd(mtx, (mtx.rows >= mtx.cols ? 0 : SVD::FULL_UV)); _dst.create(svd.vt.cols, 1, svd.vt.type()); Mat dst = _dst.getMat(); svd.vt.row(svd.vt.rows-1).reshape(1,svd.vt.cols).copyTo(dst); diff --git a/modules/core/test/test_operations.cpp b/modules/core/test/test_operations.cpp index 5297f95..fd9c42b 100644 --- a/modules/core/test/test_operations.cpp +++ b/modules/core/test/test_operations.cpp @@ -75,6 +75,7 @@ protected: bool TestVec(); bool TestMatxMultiplication(); bool TestSubMatAccess(); + bool TestSVD(); bool operations1(); void checkDiff(const Mat& m1, const Mat& m2, const string& s) @@ -934,6 +935,29 @@ bool CV_OperationsTest::operations1() return true; } + +bool CV_OperationsTest::TestSVD() +{ + try + { + Mat A = (Mat_(3,4) << 1, 2, -1, 4, 2, 4, 3, 5, -1, -2, 6, 7); + Mat x; + SVD::solveZ(A,x); + if( norm(A*x, CV_C) > FLT_EPSILON ) + throw test_excep(); + + SVD svd(A, SVD::FULL_UV); + if( norm(A*svd.vt.row(3).t(), CV_C) > FLT_EPSILON ) + throw test_excep(); + } + catch(const test_excep&) + { + ts->set_failed_test_info(cvtest::TS::FAIL_MISMATCH); + return false; + } + return true; +} + void CV_OperationsTest::run( int /* start_from */) { if (!TestMat()) @@ -959,6 +983,9 @@ void CV_OperationsTest::run( int /* start_from */) if (!TestSubMatAccess()) return; + + if (!TestSVD()) + return; if (!operations1()) return; -- 2.7.4