I am using OpenCV for some time and now I hit the point where I need a multiplication of this type:
Define a matrix
T
, which contains elements of the typeVec3d
1 . MatrixT
has the size: M X N. MatrixT
has to be multiplied with a VectorPhi
, which has the size: N X 1, containingdouble
s as values. Each element of the result has to be the result of a matrix multiplication of both matrices.
I don't want to do a component-wise multiplication, but a "real" matrix multiplication, e.g. multiplying the first element of T
2 with the first element of matrix J
, then multiplying the second element of matrix T
3 with the second element of matrix J
. Do this until you completed the first row of T
and then sum up the results. The result is a M X 1.
For example, if T
would be a 3 X 2 matrix and Phi
a 2 X 1 matrix, then the calculation should be T_11 * phi_11 + T_12 * phi_21
for the first value of the result. Currently I'm using two for loops which are slow:
for (int i = 0; i<M; ++i){
cv::Mat summedResult = cv::Mat(3, 1, CV_64F, double(0));
for (uint32 j = 0; j<N; ++j){
summedResult = summedResult +
(cv::Mat(mMatrixT.at<cv::Vec3d>(i, j)) * mMatrixPhi.at<double>(j));
}
// The result matrix contains values of type Vec3d again
mResultMatrix.at<cv::Vec3d>(i) = cv::Vec3d(summedResult);
}
More generally: Is it possible to efficiently multiply matrices containing Vec3ds
and double
s in OpenCV?
1. three dimensional vector containing doubles.
2. coordinate: 1,1
3. coordinate: 1,2
mMatrixT.at(i, j)
is just fine (i.e., do not explicitly give the template parameter if it has already been deduced) - BrandlingoA * B
. - Brandlingo