2016-11-24 3 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(ベクトル2)を返します:

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); 
    } 

私の問題は、浮動小数点[、]、行列変換、またはcoordToUnityのアルゴリズムに依存していると思います。

問題:coordToUnityは常に0を返します。EmguCV.HomographyFindを実装するのは間違っていますか?

答えて

0

答えは、私のすべての値に浮動小数点を使用することに頼っていました。このEmguCVバージョンのメソッドはdouble型しか受け付けません。

倍精度を使用しない場合、出力ホログラフは0を返します。

関連する問題