From 87888984a5c99a9a5c2705f1723da87e5c951dc1 Mon Sep 17 00:00:00 2001 From: Vadim Pisarevsky Date: Wed, 25 Apr 2012 08:59:37 +0000 Subject: [PATCH] added Matx<4,4>*Scalar operator (ticket #1830) --- modules/core/include/opencv2/core/operations.hpp | 15 ++++++++++++--- modules/core/test/test_operations.cpp | 16 ++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/modules/core/include/opencv2/core/operations.hpp b/modules/core/include/opencv2/core/operations.hpp index ba45886..9739e3f 100644 --- a/modules/core/include/opencv2/core/operations.hpp +++ b/modules/core/include/opencv2/core/operations.hpp @@ -676,14 +676,23 @@ Matx<_Tp, 4, 1> operator * (const Matx<_Tp, 4, 4>& a, const Point3_<_Tp>& b) return a*Matx<_Tp, 4, 1>(b.x, b.y, b.z, 1); } - + template static inline Scalar operator * (const Matx<_Tp, 4, 4>& a, const Scalar& b) { - return Scalar(a*Matx<_Tp, 4, 1>(b[0],b[1],b[2],b[3])); -} + Matx c(Matx(a), b, Matx_MatMulOp()); + return reinterpret_cast(c); +} + +static inline +Scalar operator * (const Matx& a, const Scalar& b) +{ + Matx c(a, b, Matx_MatMulOp()); + return reinterpret_cast(c); +} + template inline Matx<_Tp, m, n> Matx<_Tp, m, n>::mul(const Matx<_Tp, m, n>& a) const { diff --git a/modules/core/test/test_operations.cpp b/modules/core/test/test_operations.cpp index 0675c1f..1069c8d 100644 --- a/modules/core/test/test_operations.cpp +++ b/modules/core/test/test_operations.cpp @@ -808,6 +808,22 @@ bool CV_OperationsTest::TestMatxMultiplication() if(res2[0] != 14.0) throw test_excep(); if(res2[1] != 6.0) throw test_excep(); if(res2[2] != 1.0) throw test_excep(); + + Matx44f mat44f(1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1); + Matx44d mat44d(1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1); + Scalar s(4, 3, 2, 1); + Scalar sf = mat44f*s; + Scalar sd = mat44d*s; + + if(sf[0] != 10.0) throw test_excep(); + if(sf[1] != 6.0) throw test_excep(); + if(sf[2] != 3.0) throw test_excep(); + if(sf[3] != 1.0) throw test_excep(); + + if(sd[0] != 10.0) throw test_excep(); + if(sd[1] != 6.0) throw test_excep(); + if(sd[2] != 3.0) throw test_excep(); + if(sd[3] != 1.0) throw test_excep(); } catch(const test_excep&) { -- 2.7.4