0

我正在尝试将基本矩阵与一列矩阵(二维齐次坐标)相乘,但出现以下错误: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 x 3) 矩阵与 (3 x 1) 矩阵相乘以获得对应点?

4

1 回答 1

0

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

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

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

public static void cvMul(
    IntPtr  src1,
    IntPtr  src2,
    IntPtr  dst,
    double  scale
)
于 2012-08-31T21:26:04.193 回答