Updated by Andrey Kamaev almost 13 years ago

Hello.
I found an improvement and a bug which is resolved by it.

In OpenCV 2.3.1, there is only a function
<pre><code class="cpp"> <pre>
Matx<_Tp, m, n> operator * (const Matx<_Tp, m, l>& a, const Matx<_Tp, l, n>& b);
</code></pre> </pre>
and thus @operator*(Matx, Vec)@ operator*(Matx, Vec) returns @Matx<_Tp,m,1>@. Matx<_Tp,m,1>.

Therefore, some codes like the following are illegal because Vec does not have a constructor from Matx<_Tp, m, 1>.
<pre><code class="cpp"> <pre>
Matx33d m33;
Vec3d v3;
Vec3d v = m33 * v3; // compile error at constructing Vec
</code></pre> </pre>

Moreover, there is a bug in @operator*(Matx, Scalar)@ operator*(Matx, Scalar) because @Scalar@ Scalar does not have a constructor from @Matx<_Tp, Matx<_Tp, 4, 1>@. 1>.
<pre><code class="cpp"> <pre>
template<typename _Tp> 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]));
}
</code></pre> </pre>
<pre><code class="cpp"> <pre>
Scalar s1;
Matx44d m44;
m44 * s1; // bug! compile error in operator*
</code></pre> </pre>

If @operator*(Matx, Vec)@ operator*(Matx, Vec) returns @Vec@, Vec, these problems are resolved.
Because @Scalar@ Scalar has a constructor from @CvScalar@, CvScalar, which can be converted from @Vec@. Vec.

The following is a patch.
<pre><code class="cpp"> <pre>
template <typename _Tp, int m, int n> static inline
const Vec<_Tp, m> operator*(const Matx<_Tp, m, n> &a, const Matx<_Tp, n, 1> &b) {
return Vec<_Tp, m>(Matx<_Tp, m, 1>(a, b, Matx_MatMulOp()), 1, Matx_ScaleOp());
}
</code></pre> </pre>
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.

Back