CvInvoke.cvMul exception

本文关键字:exception cvMul CvInvoke | 更新日期: 2025-02-19 11:02:58

我试图将基本矩阵与一列矩阵(2D齐次坐标)相乘,但我得到以下错误:CvException occurred - OpenCV: src1.size == dst.size && src1.channels() == dst.channels()

代码如下:

IntPtr fundamentalMatrix = CvInvoke.cvCreateMat(3, 3, MAT_DEPTH.CV_32F);
[... finding the fundamental matrix ...]
IntPtr cam1PointRef = CvInvoke.cvCreateMat(3, 1, MAT_DEPTH.CV_32F);
IntPtr cam2PointRef = CvInvoke.cvCreateMat(3, 1, MAT_DEPTH.CV_32F);
//cam1Point is known
CvInvoke.cvSet2D(cam1PointRef, 0, 0, new MCvScalar(cam1Point.X));
CvInvoke.cvSet2D(cam1PointRef, 1, 0, new MCvScalar(cam1Point.Y));
CvInvoke.cvSet2D(cam1PointRef, 2, 0, new MCvScalar(1));
CvInvoke.cvMul(fundamentalMatrix, cam1PointRef, cam2PointRef, 1);
Matrix<float> cam2PointMat = new Matrix<float>(3, 1, cam2PointRef);
PointF cam2Point = new PointF();
cam2Point.X = cam2PointMat[0, 0] / cam2PointMat[0, 2];
cam2Point.Y = cam2PointMat[0, 1] / cam2PointMat[0, 2];

如果我像这样反转乘法顺序:CvInvoke.cvMul(cam1PointRef, fundamentalMatrix, cam2PointRef, 1);,我会得到另一个异常:

OpenCV: The operation is neither 'array op array' (where arrays have the same size and the same number of channels), nor 'array op scalar', nor 'scalar op array'

我做错了什么?为什么我不能用(3×3)矩阵和(3×1)矩阵相乘来得到对应点?

CvInvoke.cvMul exception

现在我没有带电脑,但您应该使用Matrix使其更简单<,>泛型类,而不是旧的cvinvoke语法。使用矩阵类,我从未发现矩阵运算中有任何问题。

您的错误在于使用数组乘法方法对矩阵进行乘法运算;

cvmul
计算两个数组的每个元素乘积dst(I)=scale*src1(I)*src2(I)所有数组必须具有相同的类型,和相同大小(或ROI大小)的

public static void cvMul(
    IntPtr  src1,
    IntPtr  src2,
    IntPtr  dst,
    double  scale
)