EmguCV HomographyFind - Unity 总是收到零
EmguCV HomographyFind - Unity always receive zero
我正在使用 Unity 并尝试使网格和相机同步。
为此,我使用了 EmguCV/OpenCV 方法 HomographyFind:http://www.emgu.com/wiki/files/1.4.0.0/html/3906193c-e458-2cb5-7667-fbb94114d179.htm
我的校准函数如下所示:
Matrix<float> homography = new Matrix<float>(3, 3);
float[,] sourcePoints;
float[,] destPoints;
void Calibrate()
{
sourcePoints = new float[,]{{Cam.greenRect[0].X, Cam.greenRect[0].Y}, {Cam.greenRect[1].X, Cam.greenRect[1].Y}, {Cam.greenRect[2].X, Cam.greenRect[2].Y}, {Cam.greenRect[3].X, Cam.greenRect[3].Y}};
destPoints = new float[,] { { goTile[0].transform.position.x, goTile[0].transform.position.y }, { goTile[32].transform.position.x, goTile[32].transform.position.y }, { goTile[858].transform.position.x, goTile[858].transform.position.y }, { goTile[890].transform.position.x, goTile[890].transform.position.y } };
Emgu.CV.Matrix<float> sourceMat = new Matrix<float>(sourcePoints);
Emgu.CV.Matrix<float> destMat = new Matrix<float>(destPoints);
CvInvoke.FindHomography(sourceMat, destMat, homography, Emgu.CV.CvEnum.HomographyMethod.Default);
call.GetComponent<Text>();
call.text = destPoints[3,0].ToString();
calibrationComplete = true;
}
Cam.greenRect 和 goTile 值似乎合适,但我的单应性中的所有位置似乎都是 0。
推理这个,我的Unity翻译也是returns 0 (Vector2):
Vector2 coordToUnity(Vector2 fingerPos)
{
float x = (fingerPos.x * homography.Data[0, 0]) + (fingerPos.y * homography[0, 1]) + (1 * homography[0, 2]);
float y = (fingerPos.x * homography.Data[1, 0]) + (fingerPos.y * homography[1, 1]) + (1 * homography[1, 2]);
return new Vector2(x, y);
}
我认为问题可能在于我的 float[] 到矩阵转换,或者我在 coordToUnity 中的算法。
问题:coordToUnity 总是 return0。我在哪里实现 EmguCV.HomographyFind 错误?
答案取决于对我所有的值都使用浮点数。此 EmguCV 版本中的方法仅接受双打。
如果不使用双打,输出的同形异义词将return 0。
我正在使用 Unity 并尝试使网格和相机同步。
为此,我使用了 EmguCV/OpenCV 方法 HomographyFind:http://www.emgu.com/wiki/files/1.4.0.0/html/3906193c-e458-2cb5-7667-fbb94114d179.htm
我的校准函数如下所示:
Matrix<float> homography = new Matrix<float>(3, 3);
float[,] sourcePoints;
float[,] destPoints;
void Calibrate()
{
sourcePoints = new float[,]{{Cam.greenRect[0].X, Cam.greenRect[0].Y}, {Cam.greenRect[1].X, Cam.greenRect[1].Y}, {Cam.greenRect[2].X, Cam.greenRect[2].Y}, {Cam.greenRect[3].X, Cam.greenRect[3].Y}};
destPoints = new float[,] { { goTile[0].transform.position.x, goTile[0].transform.position.y }, { goTile[32].transform.position.x, goTile[32].transform.position.y }, { goTile[858].transform.position.x, goTile[858].transform.position.y }, { goTile[890].transform.position.x, goTile[890].transform.position.y } };
Emgu.CV.Matrix<float> sourceMat = new Matrix<float>(sourcePoints);
Emgu.CV.Matrix<float> destMat = new Matrix<float>(destPoints);
CvInvoke.FindHomography(sourceMat, destMat, homography, Emgu.CV.CvEnum.HomographyMethod.Default);
call.GetComponent<Text>();
call.text = destPoints[3,0].ToString();
calibrationComplete = true;
}
Cam.greenRect 和 goTile 值似乎合适,但我的单应性中的所有位置似乎都是 0。
推理这个,我的Unity翻译也是returns 0 (Vector2):
Vector2 coordToUnity(Vector2 fingerPos)
{
float x = (fingerPos.x * homography.Data[0, 0]) + (fingerPos.y * homography[0, 1]) + (1 * homography[0, 2]);
float y = (fingerPos.x * homography.Data[1, 0]) + (fingerPos.y * homography[1, 1]) + (1 * homography[1, 2]);
return new Vector2(x, y);
}
我认为问题可能在于我的 float[] 到矩阵转换,或者我在 coordToUnity 中的算法。
问题:coordToUnity 总是 return0。我在哪里实现 EmguCV.HomographyFind 错误?
答案取决于对我所有的值都使用浮点数。此 EmguCV 版本中的方法仅接受双打。
如果不使用双打,输出的同形异义词将return 0。