Linked Questions

Popular Questions

EmguCV FindFundamentalMat - input params

Asked by At

I'm using EmguCV wrapper for OpenCV and I'm trying to do uncalibrated rectification via fundamental matrix.

I've found image points with FindChessboardCorners function,from both cameras, and then I would like to find fundamental matrix, but I have problem passing parameters to function eCvInvoke.cvFindFundamentalMat() CvInvoke.cvFindFundamentalMat()

What bothers me is the array of 2D points, just can't get the right format to pass it to OpenCv function cvFindFundamentalMat.

As I've understood EmguCV/OpenCV openCv expects one dimensional array of type CvMat, passed through IntPtr... But even when I do so, OpenCV throws an error message "OpenCV: Either the number of channels or columns or rows must 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?

Related Questions