c++ - OpenCV 断言矩阵乘法失败

标签 c++ ios c opencv matrix-multiplication

我用 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 来做正确的矩阵乘法。

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

关于c++ - OpenCV 断言矩阵乘法失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16981207/

相关文章:

c - 将由逗号分隔的数字列表读取到 C 中的数组中

c - snprintf 在 Xcode 中使用 Guard Malloc 编译时会产生 EXC_BAD_ACCESS

c++ - 尽管没有错误,openCL内核仍返回垃圾值

c++ - VS2008下Protocol Buffer错误C2059

ios - 在没有 iOS Composer 的情况下使用 Fabric API 在 Twitter 上分享视频

ios - 以编程方式创建 UILabel 时出现的额外宽度和高度约束是什么?我怎样才能阻止他们的创造?

c - 动态链接库相互依赖时的链接顺序问题

c++ - nodejs native c++ npm模块内存错误,开罗图像处理

c++ - PocoCapsule 目前的状态如何?

ios - 在 swift 3 中单击自身时删除按钮