DP法による点列の折れ線化

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

Syntax

C#
public static int fnFIE_cg_vectorize2d_dp(
	PNT_T_PTR src,
	uint num_src,
	PNT_T_PTR dst,
	UINT_PTR index,
	ref uint num_dst,
	double threshold
)
Visual Basic
Public Shared Function fnFIE_cg_vectorize2d_dp ( 
	src As PNT_T_PTR,
	num_src As UInteger,
	dst As PNT_T_PTR,
	index As UINT_PTR,
	ByRef num_dst As UInteger,
	threshold As Double
) As Integer

Parameters

src
Type: fvalgcli..::..PNT_T_PTR
入力座標点列
num_src
Type: System..::..UInt32
入力座標点列のサイズ。3点以上を与えてください。
dst
Type: fvalgcli..::..PNT_T_PTR
出力座標点列。 num_src 以上の大きさを持つ配列を与えてください。不要な場合は IntPtr.Zero を与えてください。
index
Type: fvalgcli..::..UINT_PTR
出力座標点列のインデックス配列。出力座標点列を src の先頭からのオフセットで表現したものです。 num_src 以上の大きさを持つ配列を与えてください。不要な場合は IntPtr.Zero を与えてください。
num_dst
Type: System..::..UInt32%
出力座標点列のサイズ
threshold
Type: System..::..Double
折れ線閾値。ゼロより大きい値を与えてください。 折れ線と点列を比較したとき点列が折れ線の方向から垂直に何ピクセル外れていたら折るかを指定します。 出力する点列は元の点列から threshold より大きく外れません。

Return Value

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

エラーコード:
f_err内容
F_ERR_NONE正常終了
F_ERR_NOMEMORYメモリ不足エラー
F_ERR_INVALID_PARAMパラメータ異常
F_ERR_NO_LICENCEライセンスエラー

Remarks

Examples

C# Copy imageCopy
//    $Revision: 1.1 $

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

namespace TC
{
    public partial class FIE
    {
        [FvPluginExecute]
        public void fnFIE_cg_vectorize2d_dp()
        {
            int status = (int)f_err.F_ERR_NONE;

            //ブローブ解析用パラメータ.
            FHANDLE himg = FHANDLE.Zero;
            FHANDLE hbinary = FHANDLE.Zero;
            FHANDLE measure_result = FHANDLE.Zero;
            F_MEASURE_PARAMS param = new F_MEASURE_PARAMS();
            PNT_T orgin;
            int exerr = 0;
            uint blobnum = 0;

            //周囲座標取得用パラメータ.
            PNT_T_PTR pnts = PNT_T_PTR.Zero;
            uint blobno = 1;
            uint pnum = 0;

            //DP法用パラメータ.
            PNT_T_PTR dst_pnts = PNT_T_PTR.Zero;
            UINT_PTR index = UINT_PTR.Zero;
            uint num_dst = 0;
            double threshold = 3.0;

            //点列の可視化用.
            DOUBLE_PTR val = DOUBLE_PTR.Zero;
            FHANDLE hdst = FHANDLE.Zero;
            FHANDLE hrgb_r = FHANDLE.Zero;
            FHANDLE hrgb_g = FHANDLE.Zero;
            FHANDLE hrgb_b = FHANDLE.Zero;
            DPNT_T_PTR dst_pnts_d = DPNT_T_PTR.Zero;

            try
            {
                /* ブローブ解析 */

                api.fnFIE_load_img_file(TestImageDir + "/testdata/image_file_8bpp.bmp", ref himg, f_color_img_type.F_COLOR_IMG_TYPE_UC8);
                int width = api.fnFIE_img_get_width(himg);
                int height = api.fnFIE_img_get_height(himg);

                hbinary = api.fnFIE_img_root_alloc((int)f_imgtype.F_IMG_BIN, 1, width, height);

                // 判別分析法により2値画像を生成.
                api.fnFIE_discrimination_threshold(himg, hbinary, INT_PTR.Zero);

                // 座標原点の指定.
                orgin.x = 0;
                orgin.y = 0;

                // パラメータ設定.
                param.color_mode = f_measure_color_mode.F_MEASURE_BLACKFG_WHITEBG;
                param.neighborhood = 8;

                // メジャー実行.
                measure_result = api.fnFIE_measure_execute(hbinary, orgin, ref param, ref exerr);

                // 全ブローブ数の取得.
                api.fnFIE_measure_get_blobnum(measure_result, ref blobnum);

                /* 周囲座標の取得 */

                // 1番(ロゴの部分)のブローブの周囲座標を取得.
                api.fnFIE_measure_get_boundary(measure_result, blobno, ref pnts, ref pnum);

                /* DP法による点列の折れ線化 */

                dst_pnts = PNT_T_PTR.alloc((int)pnum);
                index = UINT_PTR.alloc((int)pnum);

                // DP法の実行.
                status = api.fnFIE_cg_vectorize2d_dp(pnts, pnum, dst_pnts, index, ref num_dst, threshold);

                Assert.IsTrue(status == (int)f_err.F_ERR_NONE, "エラーが発生しました。({0})", (f_err)status);

                /* 点列の可視化 */

                // 領域確保.
                hdst = api.fnFIE_img_root_alloc((int)f_imgtype.F_IMG_UC8, 3, width, height);
                hrgb_r = api.fnFIE_img_child_alloc_single_ch(hdst, 0, 0, 0, width, height);
                hrgb_g = api.fnFIE_img_child_alloc_single_ch(hdst, 1, 0, 0, width, height);
                hrgb_b = api.fnFIE_img_child_alloc_single_ch(hdst, 2, 0, 0, width, height);
                val = DOUBLE_PTR.alloc(3);
                dst_pnts_d = DPNT_T_PTR.alloc((int)pnum);

                // 読み込み画像をコピー.
                api.fnFIE_img_copy(himg, hrgb_r);
                api.fnFIE_img_copy(himg, hrgb_g);
                api.fnFIE_img_copy(himg, hrgb_b);

                // 描画用濃度値の設定.
                val[0] = 255;    // R.
                val[1] = 0;        // G.
                val[2] = 0;        // B.

                // 描画(UC8 3チャネル RGB).
                for (int i = 0; i < num_dst; i++)
                {
                    // 描画用関数に渡すためにPNT_TからDNT_Tに変換.
                    dst_pnts_d[i] = DPNT_T.init((double)dst_pnts[i].x, (double)dst_pnts[i].y);
                    // 頂点を円で描画.
                    api.fnFIE_draw_circle(hdst, val, f_draw_fill_mode.F_DRAW_FILL_IN, dst_pnts_d[i], 2);
                }
                // 折れ線の描画.
                api.fnFIE_draw_curve(hdst, val, dst_pnts_d, (int)num_dst, f_draw_curve_mode.F_DRAW_POLYGONAL_LINE);

                // 結果を出力する.
                ConsoleOut.WriteFunctionName(":\n");
                Console.WriteLine("src_pnts_num = {0}, dst_pnts_num = {1}", pnum, num_dst);
                Console.Write(" ...");
                ConsoleOut.IsTrue(hdst != FHANDLE.Zero);
                api.fnFIE_save_bmp(ResultDir + "/fnFIE_cg_vectorize2d_dp.bmp", hdst);
            }
            finally
            {
                // 解放.
                himg.Dispose();
                hbinary.Dispose();
                hdst.Dispose();
                hrgb_r.Dispose();
                hrgb_g.Dispose();
                hrgb_b.Dispose();
                measure_result.Dispose();
                pnts.Dispose();
                dst_pnts.Dispose();
                index.Dispose();
                dst_pnts_d.Dispose();
                val.Dispose();
            }
        }
    }
}


Visual Basic Copy imageCopy
'    $Revision: 1.1 $

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

Public Partial Class FIE
    <FvPluginExecute> _
    Public Sub fnFIE_cg_vectorize2d_dp()
        Dim status As Integer = CInt(f_err.F_ERR_NONE)

        'ブローブ解析用パラメータ.
        Dim himg As FHANDLE = FHANDLE.Zero
        Dim hbinary As FHANDLE = FHANDLE.Zero
        Dim measure_result As FHANDLE = FHANDLE.Zero
        Dim param As New F_MEASURE_PARAMS()
        Dim orgin As PNT_T
        Dim exerr As Integer = 0
        Dim blobnum As UInteger = 0

        '周囲座標取得用パラメータ.
        Dim pnts As PNT_T_PTR = PNT_T_PTR.Zero
        Dim blobno As UInteger = 1
        Dim pnum As UInteger = 0

        'DP法用パラメータ.
        Dim dst_pnts As PNT_T_PTR = PNT_T_PTR.Zero
        Dim index As UINT_PTR = UINT_PTR.Zero
        Dim num_dst As UInteger = 0
        Dim threshold As Double = 3.0

        '点列の可視化用.
        Dim val As DOUBLE_PTR = DOUBLE_PTR.Zero
        Dim hdst As FHANDLE = FHANDLE.Zero
        Dim hrgb_r As FHANDLE = FHANDLE.Zero
        Dim hrgb_g As FHANDLE = FHANDLE.Zero
        Dim hrgb_b As FHANDLE = FHANDLE.Zero
        Dim dst_pnts_d As DPNT_T_PTR = DPNT_T_PTR.Zero

        Try
            ' ブローブ解析 


            api.fnFIE_load_img_file(TestImageDir & "/testdata/image_file_8bpp.bmp", himg, f_color_img_type.F_COLOR_IMG_TYPE_UC8)
            Dim width As Integer = api.fnFIE_img_get_width(himg)
            Dim height As Integer = api.fnFIE_img_get_height(himg)

            hbinary = api.fnFIE_img_root_alloc(CInt(f_imgtype.F_IMG_BIN), 1, width, height)

            ' 判別分析法により2値画像を生成.
            api.fnFIE_discrimination_threshold(himg, hbinary, INT_PTR.Zero)

            ' 座標原点の指定.
            orgin.x = 0
            orgin.y = 0

            ' パラメータ設定.
            param.color_mode = f_measure_color_mode.F_MEASURE_BLACKFG_WHITEBG
            param.neighborhood = 8

            ' メジャー実行.
            measure_result = api.fnFIE_measure_execute(hbinary, orgin, param, exerr)

            ' 全ブローブ数の取得.
            api.fnFIE_measure_get_blobnum(measure_result, blobnum)

            ' 周囲座標の取得 


            ' 1番(ロゴの部分)のブローブの周囲座標を取得.
            api.fnFIE_measure_get_boundary(measure_result, blobno, pnts, pnum)

            ' DP法による点列の折れ線化 


            dst_pnts = PNT_T_PTR.alloc(CInt(pnum))
            index = UINT_PTR.alloc(CInt(pnum))

            ' DP法の実行.
            status = api.fnFIE_cg_vectorize2d_dp(pnts, pnum, dst_pnts, index, num_dst, threshold)

            Assert.IsTrue(status = CInt(f_err.F_ERR_NONE), "エラーが発生しました。({0})", CType(status, f_err))

            ' 点列の可視化 


            ' 領域確保.
            hdst = api.fnFIE_img_root_alloc(CInt(f_imgtype.F_IMG_UC8), 3, width, height)
            hrgb_r = api.fnFIE_img_child_alloc_single_ch(hdst, 0, 0, 0, width, height)
            hrgb_g = api.fnFIE_img_child_alloc_single_ch(hdst, 1, 0, 0, width, height)
            hrgb_b = api.fnFIE_img_child_alloc_single_ch(hdst, 2, 0, 0, width, height)
            val = DOUBLE_PTR.alloc(3)
            dst_pnts_d = DPNT_T_PTR.alloc(CInt(pnum))

            ' 読み込み画像をコピー.
            api.fnFIE_img_copy(himg, hrgb_r)
            api.fnFIE_img_copy(himg, hrgb_g)
            api.fnFIE_img_copy(himg, hrgb_b)

            ' 描画用濃度値の設定.
            val(0) = 255
            ' R.
            val(1) = 0
            ' G.
            val(2) = 0
            ' B.
            ' 描画(UC8 3チャネル RGB).
            For i As Integer = 0 To CType(num_dst, Integer) - 1
                ' 描画用関数に渡すためにPNT_TからDNT_Tに変換.
                dst_pnts_d(i) = DPNT_T.init(CDbl(dst_pnts(i).x), CDbl(dst_pnts(i).y))
                ' 頂点を円で描画.
                api.fnFIE_draw_circle(hdst, val, f_draw_fill_mode.F_DRAW_FILL_IN, dst_pnts_d(i), 2)
            Next
            ' 折れ線の描画.
            api.fnFIE_draw_curve(hdst, val, dst_pnts_d, CInt(num_dst), f_draw_curve_mode.F_DRAW_POLYGONAL_LINE)

            ' 結果を出力する.
            ConsoleOut.WriteFunctionName(":" & vbLf)
            Console.WriteLine("src_pnts_num = {0}, dst_pnts_num = {1}", pnum, num_dst)
            Console.Write(" ...")
            ConsoleOut.IsTrue(hdst <> FHANDLE.Zero)
            api.fnFIE_save_bmp(ResultDir & "/fnFIE_cg_vectorize2d_dp.bmp", hdst)
        Finally
            ' 解放.
            himg.Dispose()
            hbinary.Dispose()
            hdst.Dispose()
            hrgb_r.Dispose()
            hrgb_g.Dispose()
            hrgb_b.Dispose()
            measure_result.Dispose()
            pnts.Dispose()
            dst_pnts.Dispose()
            index.Dispose()
            dst_pnts_d.Dispose()
            val.Dispose()
        End Try
    End Sub
End Class

See Also