From 18f6d5ed3011fc3061536fabeae42f6a54219838 Mon Sep 17 00:00:00 2001 From: Christoph Siedentop Date: Fri, 12 Aug 2011 16:46:39 +0200 Subject: [PATCH] operator* (Matx<...>, Point2<...>) fixed with a test --- .../core/include/opencv2/core/operations.hpp | 3 +- opencv/modules/core/test/test_operations.cpp | 23 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletions(-) diff --git a/opencv/modules/core/include/opencv2/core/operations.hpp b/opencv/modules/core/include/opencv2/core/operations.hpp index ee37b70..97e5a48 100644 --- a/opencv/modules/core/include/opencv2/core/operations.hpp +++ b/opencv/modules/core/include/opencv2/core/operations.hpp @@ -639,7 +639,8 @@ Point3_<_Tp> operator * (const Matx<_Tp, 3, 3>& a, const Point3_<_Tp>& b) template static inline Point3_<_Tp> operator * (const Matx<_Tp, 3, 3>& a, const Point_<_Tp>& b) { - return Point3_<_Tp>(a*Vec<_Tp,3>(b.x, b.y, 1)); + const Matx<_Tp, 3, 1> mat = a * Vec<_Tp,3>(b.x, b.y, 1); + return Point3_<_Tp>(mat(0,0), mat(1,0), mat(2,0)); } diff --git a/opencv/modules/core/test/test_operations.cpp b/opencv/modules/core/test/test_operations.cpp index 1abaf14..d0039d2 100644 --- a/opencv/modules/core/test/test_operations.cpp +++ b/opencv/modules/core/test/test_operations.cpp @@ -73,6 +73,7 @@ protected: bool TestMatND(); bool TestSparseMat(); bool operations1(); + bool TestMatxMultiplication(); void checkDiff(const Mat& m1, const Mat& m2, const string& s) { if (norm(m1, m2, NORM_INF) != 0) throw test_excep(s); } void checkDiffF(const Mat& m1, const Mat& m2, const string& s) { if (norm(m1, m2, NORM_INF) > 1e-5) throw test_excep(s); } @@ -803,6 +804,25 @@ bool CV_OperationsTest::operations1() return true; } +bool CV_OperationsTest::TestMatxMultiplication() +{ + try + { + Matx33f mat(1, 0, 0, 0, 1, 0, 0, 0, 1); // Identity matrix + Point2f pt(3, 4); + Point3f res = mat * pt; // Correctly assumes homogeneous coordinates + if(res.x != 3.0) throw test_excep(); + if(res.y != 4.0) throw test_excep(); + if(res.z != 1.0) throw test_excep(); + } + catch(const test_excep&) + { + ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_OUTPUT); + return false; + } + return true; +} + void CV_OperationsTest::run( int /* start_from */) { if (!TestMat()) @@ -823,6 +843,9 @@ void CV_OperationsTest::run( int /* start_from */) if (!operations1()) return; + if(!TestMatxMultiplication()) + return; + ts->set_failed_test_info(cvtest::TS::OK); } -- 1.7.4.1