2016-11-24 80 views
0

我在Unity中工作并尝试进行网格和相机同步。EmguCV HomographyFind - 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

推断此,我团结翻译也返回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总是返回0.我在哪里实现EmguCV.HomographyFind错误?

回答

0

答案依赖于所有我的价值使用花车。此EmguCV版本中的方法只接受双打。

如果不使用双打,输出同形异义将返回0.