1

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 ?

4

1 回答 1

3

您正在使用 进行逐元素乘法cvMul

您应该考虑cvMatMul进行正确的矩阵乘法。

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

于 2013-06-07T10:03:47.457 回答