operator* (Matx<_Tp,m,n>, Vec<_Tp, n>) should return Vec<_Tp,m> (Patch #1830)
Description
Hello.
I found an improvement and a bug which is resolved by it.
In OpenCV 2.3.1, there is only a function
1Matx<_Tp, m, n> operator * (const Matx<_Tp, m, l>& a, const Matx<_Tp, l, n>& b);
and thus
operator*(Matx, Vec)
returns Matx<_Tp,m,1>
.
Therefore, some codes like the following are illegal because Vec does not have a constructor from Matx<_Tp, m, 1>.
1Matx33d m33;
2Vec3d v3;
3Vec3d v = m33 * v3; // compile error at constructing Vec
Moreover, there is a bug in operator*(Matx, Scalar)
because Scalar
does not have a constructor from Matx<_Tp, 4, 1>
.
1template<typename _Tp> static inline
2Scalar operator * (const Matx<_Tp, 4, 4>& a, const Scalar& b)
3{
4 return Scalar(a*Matx<_Tp, 4, 1>(b[0],b[1],b[2],b[3]));
5}
1Scalar s1;
2Matx44d m44;
3m44 * s1; // bug! compile error in operator*
If operator*(Matx, Vec)
returns Vec
, these problems are resolved.
Because Scalar
has a constructor from CvScalar
, which can be converted from Vec
.
The following is a patch.
1template <typename _Tp, int m, int n> static inline
2const Vec<_Tp, m> operator*(const Matx<_Tp, m, n> &a, const Matx<_Tp, n, 1> &b) {
3 return Vec<_Tp, m>(Matx<_Tp, m, 1>(a, b, Matx_MatMulOp()), 1, Matx_ScaleOp());
4}
I have tested it in OpenCV 2.3.1, but not in 2.4 beta.
So if you accept this proposal, please test it.
Thank you for your kind cooperation.
Associated revisions
added "Matx*Vec -> Vec" operator (ticket #1830)
added Matx<4,4>*Scalar operator (ticket #1830)
Merge pull request #1830 from SpecLad:config-includes
History
Updated by Andrey Kamaev almost 13 years ago
- Description changed from Hello. I found an improvement and a bug which is resolved by it. In OpenCV 2... to Hello. I found an improvement and a bug which is resolved by it. In OpenCV 2... More
- Assignee set to Vadim Pisarevsky
Updated by Vadim Pisarevsky almost 13 years ago
thanks! The operator has been added in r8175
- Status changed from Open to Done
Updated by Yusuke Kameda almost 13 years ago
Thank you very much!
However, I think the bug
Scalar s1; Matx44d m44; m44 * s1; // bug! compile error in operator*
has not been fixed yet.
It is just that
Scalar(a*Matx<_Tp, 4, 1>(b[0],b[1],b[2],b[3]));
is illegal, because the code (a*Matx<_Tp, 4, 1>) still calls
Matx<_Tp, m, n> operator * (const Matx<_Tp, m, l>& a, const Matx<_Tp, l, n>& b)
instead of the added operator,
Vec<_Tp, m> operator * (const Matx<_Tp, m, n>& a, const Vec<_Tp, n>& b)
doesn't it?
From the added operator, I think the following is a patch for the bug.
template<typename _Tp> static inline Scalar operator * (const Matx<_Tp, 4, 4>& a, const Scalar& b) { Matx<double, 4, 1> c(a, b, Matx_MatMulOp()); return reinterpret_cast<const Scalar&>(c); }
So please check it.
Best regards.
Updated by Vadim Pisarevsky almost 13 years ago
thanks! added in r8191