射影変換 (点群)

Namespace: FVIL.GeoTrans
Assembly: FVILbasic (in FVILbasic.dll) Version: 3.1.0.0 (3.1.0.17)

Syntax

C#
public static DPNT_T_ARRAY PerspectiveNPOINTS(
	CFviMatrix matrix,
	DPNT_T_ARRAY src
)
Visual Basic
Public Shared Function PerspectiveNPOINTS ( 
	matrix As CFviMatrix,
	src As DPNT_T_ARRAY
) As DPNT_T_ARRAY

Parameters

matrix
Type: FVIL.Data..::..CFviMatrix
同次変換行列 (3x3 の正方行列)
src
Type: FVIL..::..DPNT_T_ARRAY
変換対象の点群

Return Value

Type: DPNT_T_ARRAY
変換後の点群を返します。

Remarks

この関数は PerspectivePoints(CFviMatrix, IEnumerable<(Of <<'(CFviPoint>)>>)) の改良版です。 データコピーやインスタンス生成のコストを削減できるため、高速に取得できます。

引数 src に指定された点群を同次変換行列 matrix により変換します。




処理に失敗した場合は例外を発行します。 例外の原因と発生位置を特定するには、発行された例外クラスの ErrorCode メンバと Function メンバを参照してください。


エラーコード:
ErrorCode メンバ内容
51FVIL.ErrorCode.LICENSE_ERROR ライセンスキーが見つからない為、実行できません。 または、 FVIL._SetUp.InitVisionLibrary が実行されていません。
1FVIL.ErrorCode.FAILED_TO_ALLOCATEメモリ確保に失敗しました。
11FVIL.ErrorCode.INVALID_PARAMETER引数に指定された値が不正です。

関連する FIE 関数:

fnFIE_geotrans_perspective_npoints

Examples

ソースコード:
C# Copy imageCopy
using System;
using System.Collections.Generic;
using System.Text;
using fvalgcli;

namespace User.SampleCode
{
    public partial class GeoTrans
    {
        /// <summary>
        /// 射影変換 (点群).
        /// </summary>
        [FvPluginExecute]
        public void PerspectiveNPOINTS()
        {
            // 1) 変換対象の点群.
            fvalgcli.DPNT_T[] datas = new fvalgcli.DPNT_T[4];
            datas[0].x = 200; datas[0].y = 200;
            datas[1].x = 200; datas[1].y = 300;
            datas[2].x = 300; datas[2].y = 300;
            datas[3].x = 300; datas[3].y = 200;

            FVIL.DPNT_T_ARRAY src = new FVIL.DPNT_T_ARRAY(datas);

            // 2) 同次変換行列の作成.
            // --- 行列. (回転)
            FVIL.Data.CFviAngle angle = new FVIL.Data.CFviAngle(60);
            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(200);
            ms[1, 0] = 0.0; ms[1, 1] = 1.0; ms[1, 2] = Math.Abs(50);
            ms[2, 0] = 0.0; ms[2, 1] = 0.0; ms[2, 2] = 1.0;

            // --- 行列.
            FVIL.Data.CFviMatrix mm = ms * mr;

            // 3) 処理実行.
            FVIL.DPNT_T_ARRAY result = FVIL.GeoTrans.Function.PerspectiveNPOINTS(mm, src);

            // E) 確認.
            {

                FVIL.Data.CFviImage image = new FVIL.Data.CFviImage();
                List<FVIL.Data.CFviPoint> list_src = new List<FVIL.Data.CFviPoint>(src.Count);
                List<FVIL.Data.CFviPoint> list_result = new List<FVIL.Data.CFviPoint>(result.Count);
                for (int index = 0; index < src.Count; index++)
                {
                    FVIL.Data.CFviPoint pt_src = new FVIL.Data.CFviPoint(src[index].x, src[index].y);
                    FVIL.Data.CFviPoint pt_result = new FVIL.Data.CFviPoint(result[index].x, result[index].y);
                    list_src.Add(pt_src);
                    list_result.Add(pt_result);
                }

                FVIL.Paint.Function.DrawPolygon(image, list_src, 100.0, FVIL.Paint.FillMode.Line);
                FVIL.Paint.Function.DrawPolygon(image, list_result, 200.0, FVIL.Paint.FillMode.Line);
                FVIL.File.Function.SaveImageFile(Defs.ResultDir + "/GeoTrans.Function.PerspectiveNPOINTS.png", image);
            }

        }

    }
}


Visual Basic Copy imageCopy
Imports System.Collections.Generic
Imports System.Text
Imports fvalgcli

Namespace SampleCode
    Public Partial Class GeoTrans
        ''' <summary>
        ''' 射影変換 (点群).
        ''' </summary>
        <FvPluginExecute> _
        Public Sub PerspectiveNPOINTS()
            ' 1) 変換対象の点群.
            Dim datas As fvalgcli.DPNT_T() = New fvalgcli.DPNT_T(3) {}
            datas(0).x = 200
            datas(0).y = 200
            datas(1).x = 200
            datas(1).y = 300
            datas(2).x = 300
            datas(2).y = 300
            datas(3).x = 300
            datas(3).y = 200

            Dim src As New FVIL.DPNT_T_ARRAY(datas)

            ' 2) 同次変換行列の作成.
            ' --- 行列. (回転)
            Dim angle As New FVIL.Data.CFviAngle(60)
            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(200)
            ms(1, 0) = 0.0
            ms(1, 1) = 1.0
            ms(1, 2) = Math.Abs(50)
            ms(2, 0) = 0.0
            ms(2, 1) = 0.0
            ms(2, 2) = 1.0

            ' --- 行列.
            Dim mm As FVIL.Data.CFviMatrix = ms * mr

            ' 3) 処理実行.
            Dim result As FVIL.DPNT_T_ARRAY = FVIL.GeoTrans.[Function].PerspectiveNPOINTS(mm, src)

            ' E) 確認.
            If True Then

                Dim image As New FVIL.Data.CFviImage()
                Dim list_src As New List(Of FVIL.Data.CFviPoint)(src.Count)
                Dim list_result As New List(Of FVIL.Data.CFviPoint)(result.Count)
                For index As Integer = 0 To src.Count - 1
                    Dim pt_src As New FVIL.Data.CFviPoint(src(index).x, src(index).y)
                    Dim pt_result As New FVIL.Data.CFviPoint(result(index).x, result(index).y)
                    list_src.Add(pt_src)
                    list_result.Add(pt_result)
                Next

                FVIL.Paint.[Function].DrawPolygon(image, list_src, 100.0, FVIL.Paint.FillMode.Line)
                FVIL.Paint.[Function].DrawPolygon(image, list_result, 200.0, FVIL.Paint.FillMode.Line)
                FVIL.File.[Function].SaveImageFile(Defs.ResultDir & "/GeoTrans.Function.PerspectiveNPOINTS.png", image)
            End If

        End Sub

    End Class
End Namespace

Exceptions

ExceptionCondition
System..::..NullReferenceException引数に null が指定されました。
FVIL..::..CFviExceptionこの例外の原因については、上記のエラーコード表をご参照ください。

See Also