Reputation: 77
In my code, at certain point i have to multiply 2 matrices and take the result in a 3rd matrix. I'm using cvMatMul()
for this and getting an assertion failed error.
The part of the code which does the matrix multiplication:
CvMat* mulMatTt = cvCreateMat(EigenVector->rows,vi->cols,CV_32FC1);
cvMatMul(vi,EigenVector,mulMatTt);
Here, vi has 1 row and 10000 cols and Eigen Vector is a 1x1 square matrix. I believe the error is while allocating the size of the matrix mulMatTt
. Can someone suggest how i can get this working?
The error:
OpenCV Error: Assertion failed ((D.rows == ((flags & CV_GEMM_A_T) == 0 ? A.rows : A.cols)) && (D.cols == ((flags & CV_GEMM_B_T) == 0 ? B.cols : B.rows)) && D.type() == A.type()) in cvGEMM, file C:\opencv\modules\core\src\matmul.cpp, line 29 30
Upvotes: 1
Views: 1472
Reputation: 4922
Well that's a pretty horrible to read assertion. It checks three things (all in the one assertion so we don't know which is wrong). So give the library writers a few minus points there.
The three things it checks are: 1) The number of rows of your results matrix is equal to the number of rows of your first matrix (unless you asked for the first matrix to be transposed before the multiplication, in which case it checks if the rows is equivalent to the columns). 2) The number of columns of your results matrix is equal to the number of columns of your second matrix (again, unless it was transposed as above). 3) That the type of your results matrix is the same as the type of your first matrix.
Basically, this is checking that the matrix D = AB is well formed. I assume that there is another check which makes sure A and B are compatible to be multiplied together (A.cols == B.rows (unless transposed) && A.type ==B.type).
So we are failing to make our results matrix correctly. I think the line:
CvMat* mulMatTt = cvCreateMat(EigenVector->rows,vi->cols,CV_32FC);
should be:
CvMat* mulMatTt = cvCreateMat(vi->rows, EigenVector->cols,CV_32FC);
I assume that the types are correct. Also, just a small nitpick on coding style, the pointer dereference should belong with the variable not the type:
CvMat *mulMatTt;
or else you might fall in to this trap:
CvMat* mulMatTt, identity_matrix;
where it looks like identity_matrix is of type CvMat* but in fact is CvMat!
Upvotes: 3
Reputation: 3119
In my book if you multiply a 1x10000 matrix by a 1x1 matrix the result is a 1x1 matrix not another 1x10000 matrix. So I think the assertion is complaining that mulMatTt
is the wrong size for the multiplication. I could be completely wrong.
Upvotes: 0