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?