射影変換行列の計算
Namespace: FVIL.GeoTransAssembly: FVILbasic (in FVILbasic.dll) Version: 3.1.0.0 (3.1.0.17)
Syntax
C# |
---|
public static CFviMatrix EstimateMatrixPerspective( DPNT_T_ARRAY fromPoints, DPNT_T_ARRAY toPoints ) |
Visual Basic |
---|
Public Shared Function EstimateMatrixPerspective ( fromPoints As DPNT_T_ARRAY, toPoints As DPNT_T_ARRAY ) As CFviMatrix |
Parameters
- fromPoints
- Type: FVIL..::..DPNT_T_ARRAY
変換前の点列 (要素数 4 以上)
- toPoints
- Type: FVIL..::..DPNT_T_ARRAY
変換後の点列 (要素数 4 以上)
Return Value
Type: CFviMatrix計算された行列を返します。
Remarks
本関数は最小二乗法を使用し、「変換前の点座標と変換後の点座標のペア」の 配列から射影変換行列を求めます。
点のペアは同一直線上にない4組以上が必要です。
求められた行列は射影変換行列を使用する機能(例: CFviPerspective)で使用できます。 射影変換は、線分の直線性は保たれますが、平行性は失われます。 つまり、任意の四角形を別の任意の四角形に移す変換であるといえます。
処理に失敗した場合は例外を発行します。 例外の原因と発生位置を特定するには、発行された例外クラスの ErrorCode メンバと Function メンバを参照してください。
エラーコード:
値 | ErrorCode メンバ | 内容 |
---|---|---|
51 | FVIL.ErrorCode.LICENSE_ERROR | ライセンスキーが見つからない為、実行できません。 または、 FVIL._SetUp.InitVisionLibrary が実行されていません。 |
12 | FVIL.ErrorCode.INVALID_OBJECT | 行列オブジェクトが不正です。 |
11 | FVIL.ErrorCode.INVALID_PARAMETER | 引数に指定された値が不正です。 |
1 | FVIL.ErrorCode.FAILED_TO_ALLOCATE | メモリ確保に失敗しました。 |
29 | FVIL.ErrorCode.NOT_CALCULABLE | 計算不可能です。 |
関連する FIE 関数:
fnFIE_geotrans_estimate_perspective_matrix
Examples
ソースコード:
C# | Copy |
---|---|
using System; using System.Collections.Generic; using System.Text; using fvalgcli; namespace User.SampleCode { public partial class GeoTrans { /// <summary> /// 射影変換行列の計算. /// </summary> [FvPluginExecute] public void EstimateMatrixPerspective() { // 1) 変換前後の点群. fvalgcli.DPNT_T[] datas1 = new fvalgcli.DPNT_T[4]; datas1[0].x = 200; datas1[0].y = 200; datas1[1].x = 200; datas1[1].y = 300; datas1[2].x = 300; datas1[2].y = 300; datas1[3].x = 300; datas1[3].y = 200; FVIL.DPNT_T_ARRAY fromPoints = new FVIL.DPNT_T_ARRAY(datas1); FVIL.Data.CFviMatrix mat = GetMatrix(60, 200, 50); FVIL.DPNT_T_ARRAY toPoints = FVIL.GeoTrans.Function.AffineNPOINTS(mat, fromPoints); // 2) 処理実行. FVIL.Data.CFviMatrix result = FVIL.GeoTrans.Function.EstimateMatrixPerspective(fromPoints, toPoints); // E) 確認. { // 出力. Console.Out.WriteLine(" ---GeoTrans.Function.EstimateMatrixPerspective"); Console.Out.WriteLine("{0:f} {1:f} {2:f}", result[0, 0], result[0, 1], result[0, 2]); Console.Out.WriteLine("{0:f} {1:f} {2:f}", result[1, 0], result[1, 1], result[1, 2]); Console.Out.WriteLine("{0:f} {1:f} {2:f}", result[2, 0], result[2, 1], result[2, 2]); Console.Out.WriteLine(" ---Expected"); Console.Out.WriteLine("{0:f} {1:f} {2:f}", mat[0, 0], mat[0, 1], mat[0, 2]); Console.Out.WriteLine("{0:f} {1:f} {2:f}", mat[1, 0], mat[1, 1], mat[1, 2]); Console.Out.WriteLine("{0:f} {1:f} {2:f}", mat[2, 0], mat[2, 1], mat[2, 2]); // 比較. Assert.IsTrue(mat.Columns == result.Columns, "mat.Columns:{0}, result.Columns:{1}", mat.Columns, result.Columns); Assert.IsTrue(mat.Rows == result.Rows, "mat.Rows:{0}, result.Rows:{1}", mat.Rows, result.Rows); } } } } |
Visual Basic | Copy |
---|---|
Imports System.Collections.Generic Imports System.Text Imports fvalgcli Namespace SampleCode Public Partial Class GeoTrans ''' <summary> ''' 射影変換行列の計算. ''' </summary> <FvPluginExecute> _ Public Sub EstimateMatrixPerspective() ' 1) 変換前後の点群. Dim datas1 As fvalgcli.DPNT_T() = New fvalgcli.DPNT_T(3) {} datas1(0).x = 200 datas1(0).y = 200 datas1(1).x = 200 datas1(1).y = 300 datas1(2).x = 300 datas1(2).y = 300 datas1(3).x = 300 datas1(3).y = 200 Dim fromPoints As New FVIL.DPNT_T_ARRAY(datas1) Dim mat As FVIL.Data.CFviMatrix = GetMatrix(60, 200, 50) Dim toPoints As FVIL.DPNT_T_ARRAY = FVIL.GeoTrans.[Function].AffineNPOINTS(mat, fromPoints) ' 2) 処理実行. Dim result As FVIL.Data.CFviMatrix = FVIL.GeoTrans.[Function].EstimateMatrixPerspective(fromPoints, toPoints) ' E) 確認. If True Then ' 出力. Console.Out.WriteLine(" ---GeoTrans.Function.EstimateMatrixPerspective") Console.Out.WriteLine("{0:f} {1:f} {2:f}", result(0, 0), result(0, 1), result(0, 2)) Console.Out.WriteLine("{0:f} {1:f} {2:f}", result(1, 0), result(1, 1), result(1, 2)) Console.Out.WriteLine("{0:f} {1:f} {2:f}", result(2, 0), result(2, 1), result(2, 2)) Console.Out.WriteLine(" ---Expected") Console.Out.WriteLine("{0:f} {1:f} {2:f}", mat(0, 0), mat(0, 1), mat(0, 2)) Console.Out.WriteLine("{0:f} {1:f} {2:f}", mat(1, 0), mat(1, 1), mat(1, 2)) Console.Out.WriteLine("{0:f} {1:f} {2:f}", mat(2, 0), mat(2, 1), mat(2, 2)) ' 比較. Assert.IsTrue(mat.Columns = result.Columns, "mat.Columns:{0}, result.Columns:{1}", mat.Columns, result.Columns) Assert.IsTrue(mat.Rows = result.Rows, "mat.Rows:{0}, result.Rows:{1}", mat.Rows, result.Rows) End If End Sub End Class End Namespace |
C# | Copy |
---|---|
using System; using System.Collections.Generic; using System.Text; using fvalgcli; namespace User.SampleCode { public partial class GeoTrans { private FVIL.Data.CFviMatrix GetMatrix(double degree, int shift_x, int shift_y) { // --- 行列. (回転) FVIL.Data.CFviAngle angle = new FVIL.Data.CFviAngle(degree); FVIL.Data.CFviMatrix mr = new FVIL.Data.CFviMatrix(3, 3); mr[0, 0] = +Math.Cos(angle.Radian); mr[0, 1] = -Math.Sin(angle.Radian); mr[0, 2] = 0.0; mr[1, 0] = +Math.Sin(angle.Radian); mr[1, 1] = +Math.Cos(angle.Radian); mr[1, 2] = 0.0; mr[2, 0] = 0.0; mr[2, 1] = 0.0; mr[2, 2] = 1.0; // --- 行列. (平行移動) FVIL.Data.CFviMatrix ms = new FVIL.Data.CFviMatrix(3, 3); ms[0, 0] = 1.0; ms[0, 1] = 0.0; ms[0, 2] = Math.Abs(shift_x); ms[1, 0] = 0.0; ms[1, 1] = 1.0; ms[1, 2] = Math.Abs(shift_y); ms[2, 0] = 0.0; ms[2, 1] = 0.0; ms[2, 2] = 1.0; // --- 行列. FVIL.Data.CFviMatrix mat = new FVIL.Data.CFviMatrix(); mat = ms * mr; return mat; } } } |
Visual Basic | Copy |
---|---|
Imports System.Collections.Generic Imports System.Text Imports fvalgcli Namespace SampleCode Public Partial Class GeoTrans Private Function GetMatrix(degree As Double, shift_x As Integer, shift_y As Integer) As FVIL.Data.CFviMatrix ' --- 行列. (回転) Dim angle As New FVIL.Data.CFviAngle(degree) Dim mr As New FVIL.Data.CFviMatrix(3, 3) mr(0, 0) = +Math.Cos(angle.Radian) mr(0, 1) = -Math.Sin(angle.Radian) mr(0, 2) = 0.0 mr(1, 0) = +Math.Sin(angle.Radian) mr(1, 1) = +Math.Cos(angle.Radian) mr(1, 2) = 0.0 mr(2, 0) = 0.0 mr(2, 1) = 0.0 mr(2, 2) = 1.0 ' --- 行列. (平行移動) Dim ms As New FVIL.Data.CFviMatrix(3, 3) ms(0, 0) = 1.0 ms(0, 1) = 0.0 ms(0, 2) = Math.Abs(shift_x) ms(1, 0) = 0.0 ms(1, 1) = 1.0 ms(1, 2) = Math.Abs(shift_y) ms(2, 0) = 0.0 ms(2, 1) = 0.0 ms(2, 2) = 1.0 ' --- 行列. Dim mat As New FVIL.Data.CFviMatrix() mat = ms * mr Return mat End Function End Class End Namespace |
Exceptions
Exception | Condition |
---|---|
System..::..NullReferenceException | 引数に null が指定されました。 |
FVIL..::..CFviException | この例外の原因については、上記のエラーコード表をご参照ください。 |