EmguCV FindFundamentalMat - input params

本文关键字:params input FindFundamentalMat EmguCV | 更新日期: 2023-09-27 18:30:40

我正在为OpenCV使用EmguCV包装器,我正在尝试通过基本矩阵进行未校准的整流。

我已经从两个相机中找到了带有FindChessboardCorners函数的图像点,然后我想找到基本矩阵,但是我在将参数传递给函数eCvInvoke.cvFindFundamentalMat() CvInvoke.cvFindFundamentalMat()

困扰我的是2D点数组,只是无法获得正确的格式将其传递给OpenCv函数cvFindFundamentalMat。

据我所知,EmguCV/OpenCV openCv期望CvMat类型的一维数组,通过IntPtr...但即使我这样做,OpenCV 也会抛出一条错误消息"OpenCV:通道数、列数或行数必须为 =1"

PointsF[] points1 = Camera1.Points;
PointF[] points2 = Camera2.Points
Matrix<float> points1 = new Matrix<float> (1, Camera1.ImagePoints[0].Length*2, 1);
for (int i =0; i <  Camera1.ImagePoints[0].Length-1; i+=2)
{
      points1[0, i] = Camera1.ImagePoints[0][i].X;
      points1[0, i+1] = Camera1.ImagePoints[0][i].Y;
 }
Matrix<float> points2= new Matrix<float>(1, Camera2.ImagePoints[0].Length * 2, 1);
for (int i = 0; i < Camera2.ImagePoints[0].Length-1; i+=2)
{
      points1[0, i] = Camera2.ImagePoints[0][i].X;
      points1[0, i+1] = Camera2.ImagePoints[0][i].Y;
}
IntPtr points1Matrix = Marshal.AllocHGlobal(StructSize.MCvMat);
GCHandle handlePoints1Ptr = GCHandle.Alloc(points1.MCvMat, GCHandleType.Pinned);
points1Matrix = handlePoints1Ptr.AddrOfPinnedObject();
IntPtr points2Matrix = Marshal.AllocHGlobal(StructSize.MCvMat);
GCHandle handlePoints2Ptr = GCHandle.Alloc(points2.MCvMat, GCHandleType.Pinned);
points2Matrix = handlePoints2Ptr.AddrOfPinnedObject();
_fundamentalMatrix = new Matrix<double>(3, 3, 1);
CvInvoke.cvFindFundamentalMat(points1Matrix, points2Matrix, _fundamentalMatrix.Ptr, CV_FM.CV_FM_RANSAC, 1.0, 0.99, IntPtr.Zero);

我做错了什么?

EmguCV FindFundamentalMat - input params

有点晚了,但这是我的代码。如果它不再帮助你,它可能会帮助其他人。我不能确切地说出你的代码有什么问题,我自己对OpenCV很陌生:

public void Calculate()
{
    _pointCount = _leftPoints.Count;
    IntPtr points1 = CreatePointListPointer(_leftPoints);
    IntPtr points2 = CreatePointListPointer(_rightPoints);
    IntPtr status = CvInvoke.cvCreateMat(1, _pointCount, MAT_DEPTH.CV_8U);
    IntPtr fundamentalMatrix = CvInvoke.cvCreateMat(3, 3, MAT_DEPTH.CV_32F);
    int fmCount = CvInvoke.cvFindFundamentalMat(points1,
                                                points2,
                                                fundamentalMatrix,
                                                CV_FM.CV_FM_7POINT,
                                                3.0,
                                                0.99,
                                                status);
}

public IntPtr CreatePointListPointer(IList<PointF> points)
{
    IntPtr result = CvInvoke.cvCreateMat(_pointCount, 2, MAT_DEPTH.CV_32F);
    for (int i = 0; i < _pointCount; i++)
    {
        double currentX = points[i].X;
        double currentY = points[i].Y;
        CvInvoke.cvSet2D(result, i, 0, new MCvScalar(currentX));
        CvInvoke.cvSet2D(result, i, 1, new MCvScalar(currentY));
    }
    return result;
}