From 20afae5a144e4bdee9b341d7f8d3209e696e426d Mon Sep 17 00:00:00 2001 From: berak Date: Thu, 28 Feb 2019 11:28:38 +0100 Subject: [PATCH] core: fix mat matx multiplication --- modules/core/include/opencv2/core/mat.hpp | 4 ++-- modules/core/test/test_mat.cpp | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/modules/core/include/opencv2/core/mat.hpp b/modules/core/include/opencv2/core/mat.hpp index a5fef4415a..2c23a2abb4 100644 --- a/modules/core/include/opencv2/core/mat.hpp +++ b/modules/core/include/opencv2/core/mat.hpp @@ -3627,9 +3627,9 @@ CV_EXPORTS MatExpr operator * (const MatExpr& e, double s); CV_EXPORTS MatExpr operator * (double s, const MatExpr& e); CV_EXPORTS MatExpr operator * (const MatExpr& e1, const MatExpr& e2); template static inline -MatExpr operator * (const Mat& a, const Matx<_Tp, m, n>& b) { return a + Mat(b); } +MatExpr operator * (const Mat& a, const Matx<_Tp, m, n>& b) { return a * Mat(b); } template static inline -MatExpr operator * (const Matx<_Tp, m, n>& a, const Mat& b) { return Mat(a) + b; } +MatExpr operator * (const Matx<_Tp, m, n>& a, const Mat& b) { return Mat(a) * b; } CV_EXPORTS MatExpr operator / (const Mat& a, const Mat& b); CV_EXPORTS MatExpr operator / (const Mat& a, double s); diff --git a/modules/core/test/test_mat.cpp b/modules/core/test/test_mat.cpp index f69140bb8c..dc430d08a3 100644 --- a/modules/core/test/test_mat.cpp +++ b/modules/core/test/test_mat.cpp @@ -2001,6 +2001,22 @@ TEST(Core_Vectors, issue_13078_workaround) ASSERT_EQ(7, ints[3]); } +TEST(Core_MatExpr, issue_13926) +{ + Mat M1 = (Mat_(4,4,CV_64FC1) << 1, 2, 3, 4, + 5, 6, 7, 8, + 9, 10, 11, 12, + 13, 14, 15, 16); + + Matx44d M2(1, 2, 3, 4, + 5, 6, 7, 8, + 9, 10, 11, 12, + 13, 14, 15, 16); + + EXPECT_GE(1e-6, cvtest::norm(M1*M2, M1*M1, NORM_INF)) << Mat(M1*M2) << std::endl << Mat(M1*M1); + EXPECT_GE(1e-6, cvtest::norm(M2*M1, M2*M2, NORM_INF)) << Mat(M2*M1) << std::endl << Mat(M2*M2); +} + #ifdef HAVE_EIGEN TEST(Core_Eigen, eigen2cv_check_Mat_type)