構造要素の設定

Namespace: fvalgcli
Assembly: fvalgcli (in fvalgcli.dll) Version: 3.1.0.0 (3.1.0.11)

Syntax

C#
public static int fnFIE_morphology_se_init(
	FHANDLE hse,
	UCHAR_PTR ucpMask,
	int size_x,
	int size_y,
	int step_x,
	int anchor_x,
	int anchor_y
)
Visual Basic
Public Shared Function fnFIE_morphology_se_init ( 
	hse As FHANDLE,
	ucpMask As UCHAR_PTR,
	size_x As Integer,
	size_y As Integer,
	step_x As Integer,
	anchor_x As Integer,
	anchor_y As Integer
) As Integer

Parameters

hse
Type: fvalgcli..::..FHANDLE
設定する構造要素オブジェクトのハンドル
ucpMask
Type: fvalgcli..::..UCHAR_PTR
構造要素の値を指定するマスクの先頭ポインタ
size_x
Type: System..::..Int32
マスク幅(1以上)
size_y
Type: System..::..Int32
マスク高さ(1以上)
step_x
Type: System..::..Int32
マスクメモリ横幅(UCHAR単位)
anchor_x
Type: System..::..Int32
構造要素のX方向アンカー位置( 0 ≦ anchor_x < size_x )
anchor_y
Type: System..::..Int32
anchor_y 構造要素のY方向アンカー位置( 0 ≦ anchor_y < size_y )

Return Value

Type: Int32
以下のエラーコードを返します。

エラーコード:
f_err内容
F_ERR_NONE正常終了
F_ERR_INVALID_OBJECT 不正なハンドルが渡されたため異常終了
F_ERR_INVALID_PARAMパラメータ異常
F_ERR_NO_LICENCEライセンスエラー、または未初期化エラー

Examples

C# Copy imageCopy
//    $Revision: 1.1 $

using System;
using System.Collections.Generic;
using System.Text;
using fvalgcli;

namespace TC
{
    public partial class FIE
    {
        /// <summary>
        /// 構造要素の設定.
        /// </summary>
        /// <remarks>
        /// 一元配列ptrn1 で確保・初期化した構造要素について、一元配列ptrn2 により再設定する.
        /// それから構造要素を取得し、反映されているかどうかを確認する.
        /// ※ptrn1 とptrn2 の幅、高さなどは同じであること.
        /// </remarks>
        [FvPluginExecute]
        public void fnFIE_morphology_se_init()
        {
            int status = (int)f_err.F_ERR_NONE;

            FHANDLE hse = FHANDLE.Zero;            // 構造要素.
            UCHAR_PTR ptrn1 = UCHAR_PTR.Zero;    // 構造要素の値を指定する1次元配列.
            UCHAR_PTR ptrn2 = UCHAR_PTR.Zero;    // 構造要素の値を指定する1次元配列.
            UCHAR_PTR check = UCHAR_PTR.Zero;    // 確認用.

            int size_x = 3;
            int size_y = 3;
            int anchor_x = 1;
            int anchor_y = 1;

            try
            {

                //    ptrn1 = {
                //            0,0,0,
                //            0,1,0,
                //            0,0,0
                //            };

                ptrn1 = UCHAR_PTR.alloc(9);    // size_x * size_y
                for (int i = 0; i < 9; i++)
                {
                    if (i == 4)
                        ptrn1[i] = 1;
                    else
                        ptrn1[i] = 0;
                }

                //    ptrn2 = {
                //            1,1,1,
                //            1,0,1,
                //            1,1,1,
                //            };
                ptrn2 = UCHAR_PTR.alloc(9);    // size_x * size_y
                for (int i = 0; i < 9; i++)
                {
                    if (i == 4)
                        ptrn2[i] = 0;
                    else
                        ptrn2[i] = 1;
                }

                // 構造要素オブジェクトの確保と構造要素の設定.
                hse = api.fnFIE_morphology_se_alloc(ptrn1, size_x, size_y, size_x, anchor_x, anchor_y);
                Assert.IsTrue(hse != FHANDLE.Zero, "fnFIE_morphology_se_alloc:エラーが発生しました.");

                // 処理の実行.(構造要素の設定)
                status = api.fnFIE_morphology_se_init(hse, ptrn2, size_x, size_y, size_x, anchor_x, anchor_y);
                Assert.IsTrue(status == (int)f_err.F_ERR_NONE, "エラーが発生しました。({0})", (f_err)status);

                // 確認.
                int size_getx = 0;
                int size_gety = 0;
                int anchor_getx = 0;
                int anchor_gety = 0;
                status = api.fnFIE_morphology_get_params(hse, ref size_getx, ref size_gety, ref anchor_getx, ref anchor_gety);
                Assert.IsTrue(status == (int)f_err.F_ERR_NONE, "エラーが発生しました。({0})", (f_err)status);
                Assert.IsTrue(size_x == size_getx && size_y == size_gety, "期待値と一致しません.");

                check = UCHAR_PTR.alloc(size_getx * size_gety);
                status = api.fnFIE_morphology_get_mask(hse, check, size_getx);
                Assert.IsTrue(status == (int)f_err.F_ERR_NONE, "エラーが発生しました。({0})", (f_err)status);

                for (int i = 0; i < size_getx * size_gety ; i++)
                {
                    Assert.IsTrue((1 == ptrn2[i] && 255 == check[i])
                        || (0 == ptrn2[i] && 0 == check[i]), "期待値と一致しません.");
                }
            }
            finally
            {
                // オブジェクトの開放.
                hse.Dispose();
                ptrn1.Dispose();
                ptrn2.Dispose();
                check.Dispose();
            }
        }
    }
}


Visual Basic Copy imageCopy
'    $Revision: 1.1 $

Imports System.Collections.Generic
Imports System.Text
Imports fvalgcli

Public Partial Class FIE
    ''' <summary>
    ''' 構造要素の設定.
    ''' </summary>
    ''' <remarks>
    ''' 一元配列ptrn1 で確保・初期化した構造要素について、一元配列ptrn2 により再設定する.
    ''' それから構造要素を取得し、反映されているかどうかを確認する.
    ''' ※ptrn1 とptrn2 の幅、高さなどは同じであること.
    ''' </remarks>
    <FvPluginExecute> _
    Public Sub fnFIE_morphology_se_init()
        Dim status As Integer = CInt(f_err.F_ERR_NONE)

        Dim hse As FHANDLE = FHANDLE.Zero
        ' 構造要素.
        Dim ptrn1 As UCHAR_PTR = UCHAR_PTR.Zero
        ' 構造要素の値を指定する1次元配列.
        Dim ptrn2 As UCHAR_PTR = UCHAR_PTR.Zero
        ' 構造要素の値を指定する1次元配列.
        Dim check As UCHAR_PTR = UCHAR_PTR.Zero
        ' 確認用.
        Dim size_x As Integer = 3
        Dim size_y As Integer = 3
        Dim anchor_x As Integer = 1
        Dim anchor_y As Integer = 1

        Try

            '    ptrn1 = {
            '            0,0,0,
            '            0,1,0,
            '            0,0,0
            '            };

            ptrn1 = UCHAR_PTR.alloc(9)
            ' size_x * size_y
            For i As Integer = 0 To 8
                If i = 4 Then
                    ptrn1(i) = 1
                Else
                    ptrn1(i) = 0
                End If
            Next

            '    ptrn2 = {
            '            1,1,1,
            '            1,0,1,
            '            1,1,1,
            '            };
            ptrn2 = UCHAR_PTR.alloc(9)
            ' size_x * size_y
            For i As Integer = 0 To 8
                If i = 4 Then
                    ptrn2(i) = 0
                Else
                    ptrn2(i) = 1
                End If
            Next

            ' 構造要素オブジェクトの確保と構造要素の設定.
            hse = api.fnFIE_morphology_se_alloc(ptrn1, size_x, size_y, size_x, anchor_x, anchor_y)
            Assert.IsTrue(hse <> FHANDLE.Zero, "fnFIE_morphology_se_alloc:エラーが発生しました.")

            ' 処理の実行.(構造要素の設定)
            status = api.fnFIE_morphology_se_init(hse, ptrn2, size_x, size_y, size_x, anchor_x, _
                anchor_y)
            Assert.IsTrue(status = CInt(f_err.F_ERR_NONE), "エラーが発生しました。({0})", CType(status, f_err))

            ' 確認.
            Dim size_getx As Integer = 0
            Dim size_gety As Integer = 0
            Dim anchor_getx As Integer = 0
            Dim anchor_gety As Integer = 0
            status = api.fnFIE_morphology_get_params(hse, size_getx, size_gety, anchor_getx, anchor_gety)
            Assert.IsTrue(status = CInt(f_err.F_ERR_NONE), "エラーが発生しました。({0})", CType(status, f_err))
            Assert.IsTrue(size_x = size_getx AndAlso size_y = size_gety, "期待値と一致しません.")

            check = UCHAR_PTR.alloc(size_getx * size_gety)
            status = api.fnFIE_morphology_get_mask(hse, check, size_getx)
            Assert.IsTrue(status = CInt(f_err.F_ERR_NONE), "エラーが発生しました。({0})", CType(status, f_err))

            For i As Integer = 0 To size_getx * size_gety - 1
                Assert.IsTrue((1 = ptrn2(i) AndAlso 255 = check(i)) OrElse (0 = ptrn2(i) AndAlso 0 = check(i)), "期待値と一致しません.")
            Next
        Finally
            ' オブジェクトの開放.
            hse.Dispose()
            ptrn1.Dispose()
            ptrn2.Dispose()
            check.Dispose()
        End Try
    End Sub
End Class

See Also