From 56f5fcd28ca0695a7781120338b0f80fc748678b Mon Sep 17 00:00:00 2001 From: Vadim Pisarevsky Date: Wed, 28 Mar 2012 15:21:30 +0000 Subject: [PATCH] added Vec Matx::solve(Vec) (ticket #1376) --- modules/core/include/opencv2/core/core.hpp | 2 +- .../core/include/opencv2/core/operations.hpp | 6 ++++++ modules/nonfree/src/sift.cpp | 14 +++++++------- modules/nonfree/src/surf.cpp | 18 +++++++++--------- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/modules/core/include/opencv2/core/core.hpp b/modules/core/include/opencv2/core/core.hpp index 3d5dcac99a..0d3662b884 100644 --- a/modules/core/include/opencv2/core/core.hpp +++ b/modules/core/include/opencv2/core/core.hpp @@ -502,7 +502,7 @@ public: //! solve linear system template Matx<_Tp, n, l> solve(const Matx<_Tp, m, l>& rhs, int flags=DECOMP_LU) const; - Matx<_Tp, n, 1> solve(const Matx<_Tp, m, 1>& rhs, int method) const; + Vec<_Tp, n> solve(const Vec<_Tp, m>& rhs, int method) const; //! multiply two matrices element-wise Matx<_Tp, m, n> mul(const Matx<_Tp, m, n>& a) const; diff --git a/modules/core/include/opencv2/core/operations.hpp b/modules/core/include/opencv2/core/operations.hpp index 035ed47120..7e6a3b0354 100644 --- a/modules/core/include/opencv2/core/operations.hpp +++ b/modules/core/include/opencv2/core/operations.hpp @@ -903,6 +903,12 @@ Matx<_Tp, n, l> Matx<_Tp, m, n>::solve(const Matx<_Tp, m, l>& rhs, int method) c return ok ? x : Matx<_Tp, n, l>::zeros(); } +template inline +Vec<_Tp, n> Matx<_Tp, m, n>::solve(const Vec<_Tp, m>& rhs, int method) const +{ + Matx<_Tp, n, 1> x = solve(reinterpret_cast&>(rhs), method); + return reinterpret_cast&>(x); +} template static inline _AccTp normL2Sqr(const _Tp* a, int n) diff --git a/modules/nonfree/src/sift.cpp b/modules/nonfree/src/sift.cpp index cca832214f..92705e5dd0 100644 --- a/modules/nonfree/src/sift.cpp +++ b/modules/nonfree/src/sift.cpp @@ -343,9 +343,9 @@ static bool adjustLocalExtrema( const vector& dog_pyr, KeyPoint& kpt, int o const Mat& prev = dog_pyr[idx-1]; const Mat& next = dog_pyr[idx+1]; - Matx31f dD((img.at(r, c+1) - img.at(r, c-1))*deriv_scale, - (img.at(r+1, c) - img.at(r-1, c))*deriv_scale, - (next.at(r, c) - prev.at(r, c))*deriv_scale); + Vec3f dD((img.at(r, c+1) - img.at(r, c-1))*deriv_scale, + (img.at(r+1, c) - img.at(r-1, c))*deriv_scale, + (next.at(r, c) - prev.at(r, c))*deriv_scale); float v2 = (float)img.at(r, c)*2; float dxx = (img.at(r, c+1) + img.at(r, c-1) - v2)*second_deriv_scale; @@ -362,11 +362,11 @@ static bool adjustLocalExtrema( const vector& dog_pyr, KeyPoint& kpt, int o dxy, dyy, dys, dxs, dys, dss); - Matx31f X = H.solve<1>(dD, DECOMP_LU); + Vec3f X = H.solve(dD, DECOMP_LU); - xi = -X(2, 0); - xr = -X(1, 0); - xc = -X(0, 0); + xi = -X[2]; + xr = -X[1]; + xc = -X[0]; if( std::abs( xi ) < 0.5f && std::abs( xr ) < 0.5f && std::abs( xc ) < 0.5f ) break; diff --git a/modules/nonfree/src/surf.cpp b/modules/nonfree/src/surf.cpp index 5fbdcbc84f..6af8efb97e 100644 --- a/modules/nonfree/src/surf.cpp +++ b/modules/nonfree/src/surf.cpp @@ -228,9 +228,9 @@ static void calcLayerDetAndTrace( const Mat& sum, int size, int sampleStep, static int interpolateKeypoint( float N9[3][9], int dx, int dy, int ds, KeyPoint& kpt ) { - Matx31f b(-(N9[1][5]-N9[1][3])/2, // Negative 1st deriv with respect to x - -(N9[1][7]-N9[1][1])/2, // Negative 1st deriv with respect to y - -(N9[2][4]-N9[0][4])/2); // Negative 1st deriv with respect to s + Vec3f b(-(N9[1][5]-N9[1][3])/2, // Negative 1st deriv with respect to x + -(N9[1][7]-N9[1][1])/2, // Negative 1st deriv with respect to y + -(N9[2][4]-N9[0][4])/2); // Negative 1st deriv with respect to s Matx33f A( N9[1][3]-2*N9[1][4]+N9[1][5], // 2nd deriv x, x @@ -243,16 +243,16 @@ interpolateKeypoint( float N9[3][9], int dx, int dy, int ds, KeyPoint& kpt ) (N9[2][7]-N9[2][1]-N9[0][7]+N9[0][1])/4, // 2nd deriv y, s N9[0][4]-2*N9[1][4]+N9[2][4]); // 2nd deriv s, s - Matx31f x = A.solve<1>(b, DECOMP_LU); + Vec3f x = A.solve(b, DECOMP_LU); - bool ok = (x(0,0) != 0 || x(1,0) != 0 || x(2,0) != 0) && - std::abs(x(0,0)) <= 1 && std::abs(x(1,0)) <= 1 && std::abs(x(2,0)) <= 1; + bool ok = (x[0] != 0 || x[1] != 0 || x[2] != 0) && + std::abs(x[0]) <= 1 && std::abs(x[1]) <= 1 && std::abs(x[2]) <= 1; if( ok ) { - kpt.pt.x += x(0,0)*dx; - kpt.pt.y += x(1,0)*dy; - kpt.size = (float)cvRound( kpt.size + x(2,0)*ds ); + kpt.pt.x += x[0]*dx; + kpt.pt.y += x[1]*dy; + kpt.size = (float)cvRound( kpt.size + x[2]*ds ); } return ok; }