I\'m probably being incredibly stupid here but I\'m having trouble doing some basicaly Mat multiplication using OpenCV for Android.
I have two Mat\'s both of the sam
Reverse your 2 multiplied matrices : Core.multiply(mat2, mat1, mat3);
You are basicly trying to perform the following operation now:
[ 0 ] [ 0 1 2 ]
[ 1 ] * [ 3 4 5 ]
[ 2 ] [ 6 7 8 ]
In here * is multiplication. A matrix multiplication cannot be done this way. Read on matrix multiplications here.
The operation you would like to perform is :
[ 0 1 2 ]
[ 0 1 2 ] * [ 3 4 5 ]
[ 6 7 8 ]
To get your code working make the following changes:
Mat mat1 = new Mat(1, 3, CvType.CV_64F); // A matrix with 1 row and 3 columns
mat1.put(0, 0, 2.0); // Set row 1 , column 1
mat1.put(0, 1, 0.5); // Set row 1 , column 2
mat1.put(0, 2, 1.0); // Set row 1 , column 3
Also, you're using the method Core.multiply
. In the documentation of OpenCv it mentions:
The function multiply calculates the per-element product of two matrices.
If you are looking for a matrix product, not per-element product, see Core.gemm().
The function gemm(src1, src2, alpha, src3, beta, dest, flags)
performs the multiplication according to the following function:
dest = alpha * src1 * src2 + beta * src3
Basic matrix multiplcation (in your case) is done by:
Core.gemm(mat2, mat1, 1, NULL, 0, mat3, 0);