EmguCV FindFundamentalMat - input parameters

I am using the EmguCV shell for OpenCV, and I am trying to perform an uncalibrated correction using a fundamental matrix.

I found image points with the FindChessboardCorners function from both cameras, and then I would like to find the main matrix, but I have problems passing parameters for the eCvInvoke.cvFindFundamentalMat () function CvInvoke.cvFindFundamentalMat ()

What bothers me is the array of two-dimensional points, it simply cannot get the correct format to pass to the OpenCv function cvFindFundamentalMat.

As I understand it, EmguCV / OpenCV openCv expects one dimensional array of type CvMat, passed through IntPtr ... But even when I do this, OpenCV gives an error message "OpenCV: either the number of channels, or columns or rows should be = 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);

What am I doing wrong?

+3
source share
1 answer

A bit late, but here is my code. It may help some others if it doesn't help you anymore. I can’t say for sure what is wrong with your code, I am very new to 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;
}
+3
source

All Articles