我用 OpenCV 将两个矩阵相乘,A 为 NxM,B 为 MxP。
根据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.
然而,通过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.
这段代码不能正常工作吗?
- (CvMat *) multMatrix:(CvMat *)AMatrix BMatrix:(CvMat *)BMatrix
{
CvMat *result = cvCreateMat(AMatrix->rows, BMatrix->cols, kMatrixType);
cvMul(AMatrix, BMatrix, result, 1.0);
return result;
}
我得到以下异常:
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 是 CV_32F,A 是 6x234,B 是 234x5,结果是 6x5...
我做错了什么吗?或者这是 OpenCV 对矩阵乘法的限制?
最佳答案
您正在使用 cvMul
进行逐元素乘法。
你应该看看 cvMatMul
来做正确的矩阵乘法。
关于c++ - OpenCV 断言矩阵乘法失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16981207/