简体   繁体   中英

OpenCV Assertion failed on Matrix multiplication

I'm multiplying two matrices with OpenCV, A in NxM and B is MxP.

According to the documentation :

All the arrays must have the same type and the same size (or ROI size). For types that have limited range this operation is saturating.

However, by the theory of matrix multiplication :

Assume two matrices are to be multiplied (the generalization to any number is discussed below). If A is an n×m matrix and B is an m×p matrix, the result would be AB of their multiplication is an n×p matrix defined only if the number of columns m in A is equal to the number of rows m in B.

shouldn't this code be working?

- (CvMat *) multMatrix:(CvMat *)AMatrix BMatrix:(CvMat *)BMatrix 
{
  CvMat *result = cvCreateMat(AMatrix->rows, BMatrix->cols, kMatrixType);
  cvMul(AMatrix, BMatrix, result, 1.0);
  return result;
}

I get the following exception:

OpenCV Error: Assertion failed (src1.size == dst.size && src1.channels() == dst.channels()) in cvMul, file /Users/Aziz/Documents/Projects/opencv_sources/trunk/modules/core/src/arithm.cpp, line 2728

kMatrixType is CV_32F, A is 6x234, B is 234x5 and result is 6x5...

Am I doing something wrong? Or is this an OpenCV restriction to matrix multiplication ?

You are doing element-wise multiplication with cvMul .

You should look at cvMatMul for doing proper matrix multiplication.

http://opencv.willowgarage.com/wiki/Matrix_operations

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM