fixed Mat(const Matx&) constructor; added SVD(Matx)

This commit is contained in:
Vadim Pisarevsky
2010-08-30 18:05:05 +00:00
parent e48a456d48
commit eb6994f58a
3 changed files with 129 additions and 61 deletions

View File

@@ -2046,6 +2046,21 @@ public:
//! the operator that performs SVD. The previously allocated SVD::u, SVD::w are SVD::vt are released.
SVD& operator ()( const Mat& m, int flags=0 );
//! decomposes matrix and stores the results to user-provided matrices
static void compute( const Mat& m, Mat& w, Mat& u, Mat& vt, int flags=0 );
//! computes singular values of a matrix
static void compute( const Mat& m, Mat& w, int flags=0 );
//! performs back substitution
static void backSubst( const Mat& w, const Mat& u, const Mat& vt,
const Mat& rhs, Mat& dst );
template<typename _Tp, int m, int n, int nm> static void compute( const Matx<_Tp, m, n>& a,
Matx<_Tp, nm, 1>& w, Matx<_Tp, m, nm>& u, Matx<_Tp, n, nm>& vt );
template<typename _Tp, int m, int n, int nm> static void compute( const Matx<_Tp, m, n>& a,
Matx<_Tp, nm, 1>& w );
template<typename _Tp, int m, int n, int nm, int nb> static void backSubst( const Matx<_Tp, nm, 1>& w,
const Matx<_Tp, m, nm>& u, const Matx<_Tp, n, nm>& vt, const Matx<_Tp, m, nb>& rhs, Matx<_Tp, n, nb>& dst );
//! finds dst = arg min_{|dst|=1} |m*dst|
static void solveZ( const Mat& m, Mat& dst );
//! performs back substitution, so that dst is the solution or pseudo-solution of m*dst = rhs, where m is the decomposed matrix

View File

@@ -258,7 +258,7 @@ template<typename _Tp, int m, int n> inline Mat::Mat(const Matx<_Tp,m,n>& M, boo
{
rows = m;
cols = n;
step = sizeof(_Tp);
step = n*sizeof(_Tp);
data = datastart = (uchar*)M.val;
dataend = datastart + rows*step;
}
@@ -649,6 +649,35 @@ inline void SVD::solveZ( const Mat& m, Mat& dst )
svd.vt.row(svd.vt.rows-1).reshape(1,svd.vt.cols).copyTo(dst);
}
template<typename _Tp, int m, int n, int nm> inline void
SVD::compute( const Matx<_Tp, m, n>& a, Matx<_Tp, nm, 1>& w, Matx<_Tp, m, nm>& u, Matx<_Tp, n, nm>& vt )
{
assert( nm == MIN(m, n));
Mat _a(a, false), _u(u, false), _w(w, false), _vt(vt, false);
SVD::compute(_a, _w, _u, _vt);
CV_Assert(_w.data == (uchar*)&w.val[0] && _u.data == (uchar*)&u.val[0] && _vt.data == (uchar*)&vt.val[0]);
}
template<typename _Tp, int m, int n, int nm> inline void
SVD::compute( const Matx<_Tp, m, n>& a, Matx<_Tp, nm, 1>& w )
{
assert( nm == MIN(m, n));
Mat _a(a, false), _w(w, false);
SVD::compute(_a, _w);
CV_Assert(_w.data == (uchar*)&w.val[0]);
}
template<typename _Tp, int m, int n, int nm, int nb> inline void
SVD::backSubst( const Matx<_Tp, nm, 1>& w, const Matx<_Tp, m, nm>& u,
const Matx<_Tp, n, nm>& vt, const Matx<_Tp, m, nb>& rhs,
Matx<_Tp, n, nb>& dst )
{
assert( nm == MIN(m, n));
Mat _u(u, false), _w(w, false), _vt(vt, false), _rhs(_rhs, false), _dst(dst, false);
SVD::backSubst(_w, _u, _vt, _rhs, _dst);
CV_Assert(_dst.data == (uchar*)&dst.val[0]);
}
///////////////////////////////// Mat_<_Tp> ////////////////////////////////////
template<typename _Tp> inline Mat_<_Tp>::Mat_() :