From 735f704b3e85f82df060e0ea00c9c66669287815 Mon Sep 17 00:00:00 2001 From: Philippe FOUBERT Date: Thu, 28 Nov 2013 00:42:19 +0100 Subject: [PATCH 1/2] Add on optional parameter to the matx invert function to know if this operation is successfull without having to analyse the matrix (it may fail in case of bad preconditioning or inappropriate decomposition method) --- modules/core/include/opencv2/core/matx.hpp | 2 +- modules/core/include/opencv2/core/operations.hpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/core/include/opencv2/core/matx.hpp b/modules/core/include/opencv2/core/matx.hpp index 86a35cd756..010e028289 100644 --- a/modules/core/include/opencv2/core/matx.hpp +++ b/modules/core/include/opencv2/core/matx.hpp @@ -154,7 +154,7 @@ public: Matx<_Tp, n, m> t() const; //! invert matrix the matrix - Matx<_Tp, n, m> inv(int method=DECOMP_LU) const; + Matx<_Tp, n, m> inv(int method=DECOMP_LU, bool *p_is_ok = NULL) const; //! solve linear system template Matx<_Tp, n, l> solve(const Matx<_Tp, m, l>& rhs, int flags=DECOMP_LU) const; diff --git a/modules/core/include/opencv2/core/operations.hpp b/modules/core/include/opencv2/core/operations.hpp index f8aeddfb11..ea23f60f12 100644 --- a/modules/core/include/opencv2/core/operations.hpp +++ b/modules/core/include/opencv2/core/operations.hpp @@ -186,7 +186,7 @@ Matx<_Tp,m,n> Matx<_Tp,m,n>::randn(_Tp a, _Tp b) } template inline -Matx<_Tp, n, m> Matx<_Tp, m, n>::inv(int method) const +Matx<_Tp, n, m> Matx<_Tp, m, n>::inv(int method, bool *p_is_ok /*= NULL*/) const { Matx<_Tp, n, m> b; bool ok; @@ -197,6 +197,7 @@ Matx<_Tp, n, m> Matx<_Tp, m, n>::inv(int method) const Mat A(*this, false), B(b, false); ok = (invert(A, B, method) != 0); } + if( NULL != p_is_ok ) { *p_is_ok = ok; } return ok ? b : Matx<_Tp, n, m>::zeros(); } From 22ad487328f75c1c422e33bd3d089c99bdb9ab19 Mon Sep 17 00:00:00 2001 From: Philippe FOUBERT Date: Thu, 28 Nov 2013 00:45:58 +0100 Subject: [PATCH 2/2] Comment correction --- modules/core/include/opencv2/core/matx.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/include/opencv2/core/matx.hpp b/modules/core/include/opencv2/core/matx.hpp index 010e028289..d7d4859573 100644 --- a/modules/core/include/opencv2/core/matx.hpp +++ b/modules/core/include/opencv2/core/matx.hpp @@ -153,7 +153,7 @@ public: //! transpose the matrix Matx<_Tp, n, m> t() const; - //! invert matrix the matrix + //! invert the matrix Matx<_Tp, n, m> inv(int method=DECOMP_LU, bool *p_is_ok = NULL) const; //! solve linear system