我正在为 OpenCV 使用 EmguCV 包装器,并且我正在尝试通过基本矩阵进行未校准的校正。
我已经从两个相机中找到了带有 FindChessboardCorners 函数的图像点,然后我想找到基本矩阵,但是我在将参数传递给函数 eCvInvoke.cvFindFundamentalMat() CvInvoke.cvFindFundamentalMat( ) 时遇到问题
困扰我的是二维点数组,只是无法获得正确的格式将其传递给 OpenCv 函数 cvFindFundamentalMat。
据我了解,EmguCV/OpenCV openCv 需要通过 IntPtr 传递的 CvMat 类型的一维数组......但即使我这样做,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);
我究竟做错了什么?