エッジ点の連結

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

Syntax

C#
public static int fnFIE_edge_connecting(
	F_DEDGE_PTR pedge,
	int edge_num,
	double weight,
	double threshold1,
	double threshold2,
	int area_size,
	int area_overlap,
	int min_clust_elem,
	int mode,
	ref F_EDGE_CLUST_PTR ppedge_clust,
	ref int pclust_num
)
Visual Basic
Public Shared Function fnFIE_edge_connecting ( 
	pedge As F_DEDGE_PTR,
	edge_num As Integer,
	weight As Double,
	threshold1 As Double,
	threshold2 As Double,
	area_size As Integer,
	area_overlap As Integer,
	min_clust_elem As Integer,
	mode As Integer,
	ByRef ppedge_clust As F_EDGE_CLUST_PTR,
	ByRef pclust_num As Integer
) As Integer

Parameters

pedge
Type: fvalgcli..::..F_DEDGE_PTR
エッジ点の配列(座標、勾配方向(rad))
edge_num
Type: System..::..Int32
エッジ点の個数( 2 ≦ edge_num )
weight
Type: System..::..Double
エッジ勾配方向の重み weight エッジ勾配方向のなす角の重み)( 0 ≦ weight ≦ 1 )
threshold1
Type: System..::..Double
評価閾値1:連結用( 0 < threshold1 )
threshold2
Type: System..::..Double
評価閾値2:再連結用( threshold1 < threshold2 )
area_size
Type: System..::..Int32
正方連結用局所領域のサイズ(画素: 3 ≦ area_size ≦ 20 )
area_overlap
Type: System..::..Int32
連結用局所領域の重なり(画素: area_overlap ≦ area_size / 2 )
min_clust_elem
Type: System..::..Int32
クラスタに属するエッジ点の個数の最小値( 2 ≦ min_clust_elem )
mode
Type: System..::..Int32
再連結処理(0:無効、0以外:有効)
ppedge_clust
Type: fvalgcli..::..F_EDGE_CLUST_PTR%
抽出した曲線の情報(クラスタ)の配列( IntPtr.Zero で初期化してください。)
pclust_num
Type: System..::..Int32%
抽出した曲線の個数(初期値は0を指定)

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_edge_connecting()
        {
            int status = (int)f_err.F_ERR_NONE;

            FHANDLE hsrc = FHANDLE.Zero;

            // 2次元エッジ抽出用.
            F_DEDGE_PTR edges = F_DEDGE_PTR.Zero;
            int edge_num = 0;

            // エッジ点群連結用.
            F_EDGE_CLUST_PTR clust = F_EDGE_CLUST_PTR.Zero;
            int clust_num = 0;

            try
            {
                // 入力画像の読み込み.
                // 適当な画像を読み込んでください.
                api.fnFIE_load_png(TestImageDir + "/testdata/camcalib_1_uc8.png", ref hsrc, f_color_img_type.F_COLOR_IMG_TYPE_UC8);

                // 2次元エッジ抽出(相関エッジ)用パラメータの設定.
                F_EDGE_CORR_PARAMS param = F_EDGE_CORR_PARAMS.init(13, 5, 25.0, 1.0, 160, 6);
                DPNT_T offset = DPNT_T.init(0, 0);

                // 2次元エッジ抽出(相関エッジ)
                api.fnFIE_edge_corr_subpix(
                        hsrc,
                        FHANDLE.Zero,
                        ref param,
                        f_edge_feature_mode.F_EDGE_FEAT_DIRECT,
                        f_border_mode.F_BORDER_CONTINUOUS,
                        offset,
                        ref edges,
                        ref edge_num
                    );

                // エッジ点群の連結用パラメータの設定.
                double weight = 0.07;
                double threshold1 = 2.0;
                double threshold2 = 4.0;
                int area_size = 10;
                int area_overlap = 3;
                int min_clust_elem = 3;
                int mode = 1;

                // エッジ点群の連結.
                status = api.fnFIE_edge_connecting(
                    edges, edge_num, weight, threshold1, threshold2, 
                    area_size, area_overlap, min_clust_elem, mode,
                    ref clust, ref clust_num
                    );

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

                // 確認用.
                var hdraw_image = fnPRV_draw_edge_clust(hsrc, edges, clust, clust_num);
                api.fnFIE_save_png(ResultDir + "/fnFIE_edge_connecting.png", hdraw_image, -1);
                hdraw_image.Dispose();
            }
            finally
            {
                // オブジェクトの開放.
                hsrc.Dispose();
                edges.Dispose();
                api.fnFIE_free_edge_clust(clust, clust_num);
            }
        }
    }
}

確認用の描画処理:
C# Copy imageCopy
using System;
using System.Collections.Generic;
using System.Text;
using fvalgcli;

namespace TC
{
    public partial class FIE
    {
        /// <summary>
        /// 連結された曲線を色を変えて入力画像上に描画する.
        /// </summary>
        /// <param name="hsrc">元画像</param>
        /// <param name="edges">エッジ点群</param>
        /// <param name="clust">クラスタ</param>
        /// <param name="clust_num">クラスタ数</param>
        /// <returns>
        ///        描画結果の画像。解放必要。
        /// </returns>
        private FHANDLE fnPRV_draw_edge_clust(FHANDLE hsrc, F_DEDGE_PTR edges, F_EDGE_CLUST_PTR clust, int clust_num)
        {
            FHANDLE hdst = FHANDLE.Zero;

            // 連結して生成された曲線描画用.
            double[,] colors =
            {
                {   0.0,   0.0, 255.0 },
                {   0.0,   0.0, 128.0 },
                {   0.0, 255.0,   0.0 },
                { 255.0, 255.0,   0.0 },
                { 255.0, 165.0,   0.0 },
                { 255.0,   0.0,   0.0 },
                { 255.0, 192.0, 203.0 },
                { 176.0,  48.0,  96.0 },
                {   0.0, 255.0, 255.0 },
                { 160.0,  32.0, 240.0 },
                { 255.0,   0.0, 255.0 },
                {   0.0, 100.0,   0.0 },
            };

            FHANDLE hdst0 = FHANDLE.Zero;
            FHANDLE hdst1 = FHANDLE.Zero;
            FHANDLE hdst2 = FHANDLE.Zero;
            DOUBLE_PTR color = DOUBLE_PTR.Zero;
            DPNT_T_PTR points = DPNT_T_PTR.Zero;

            try
            {
                // 入力画像の情報取得.
                int width = api.fnFIE_img_get_width(hsrc);
                int height = api.fnFIE_img_get_height(hsrc);

                // 出力画像の生成.
                hdst = api.fnFIE_img_root_alloc((int)f_imgtype.F_IMG_UC8, 3, width, height);

                hdst0 = api.fnFIE_img_child_alloc_single_ch(hdst, 0, 0, 0, width, height);    // CH0
                hdst1 = api.fnFIE_img_child_alloc_single_ch(hdst, 1, 0, 0, width, height);    // CH1
                hdst2 = api.fnFIE_img_child_alloc_single_ch(hdst, 2, 0, 0, width, height);    // CH2
                api.fnFIE_img_copy_ex(hsrc, hdst0, 1, 0, 0);
                api.fnFIE_img_copy_ex(hsrc, hdst1, 1, 0, 0);
                api.fnFIE_img_copy_ex(hsrc, hdst2, 1, 0, 0);

                // 描画色.
                color = DOUBLE_PTR.alloc(3);    // R,G,B

                for (int i = 0; i < clust_num; i++)
                {
                    color[0] = colors[i % 4, 0];
                    color[1] = colors[i % 4, 1];
                    color[2] = colors[i % 4, 2];

                    int num = clust[i].num - 1;
                    for (int j = 0; j < num; j++)
                    {
                        int index0 = clust[i].pindex[j + 0];
                        int index1 = clust[i].pindex[j + 1];
                        DPNT_T st = DPNT_T.init(edges[index0].x, edges[index0].y);
                        DPNT_T ed = DPNT_T.init(edges[index1].x, edges[index1].y);

                        // 描画.
                        api.fnFIE_draw_line_seg(hdst, color, st, ed);
                    }
                }
            }
            finally
            {
                // オブジェクトの開放.
                hdst0.Dispose();
                hdst1.Dispose();
                hdst2.Dispose();
                color.Dispose();
                points.Dispose();
            }

            return hdst;
        }
    }
}


Visual Basic Copy imageCopy
'    $Revision: 1.1 $

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

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

        Dim hsrc As FHANDLE = FHANDLE.Zero

        ' 2次元エッジ抽出用.
        Dim edges As F_DEDGE_PTR = F_DEDGE_PTR.Zero
        Dim edge_num As Integer = 0

        ' エッジ点群連結用.
        Dim clust As F_EDGE_CLUST_PTR = F_EDGE_CLUST_PTR.Zero
        Dim clust_num As Integer = 0

        Try
            ' 入力画像の読み込み.
            ' 適当な画像を読み込んでください.
            api.fnFIE_load_png(TestImageDir & "/testdata/camcalib_1_uc8.png", hsrc, f_color_img_type.F_COLOR_IMG_TYPE_UC8)

            ' 2次元エッジ抽出(相関エッジ)用パラメータの設定.
            Dim param As F_EDGE_CORR_PARAMS = F_EDGE_CORR_PARAMS.init(13, 5, 25.0, 1.0, 160, 6)
            Dim offset As DPNT_T = DPNT_T.init(0, 0)

            ' 2次元エッジ抽出(相関エッジ)
            api.fnFIE_edge_corr_subpix(hsrc, FHANDLE.Zero, param, f_edge_feature_mode.F_EDGE_FEAT_DIRECT, f_border_mode.F_BORDER_CONTINUOUS, offset, _
                edges, edge_num)

            ' エッジ点群の連結用パラメータの設定.
            Dim weight As Double = 0.07
            Dim threshold1 As Double = 2.0
            Dim threshold2 As Double = 4.0
            Dim area_size As Integer = 10
            Dim area_overlap As Integer = 3
            Dim min_clust_elem As Integer = 3
            Dim mode As Integer = 1

            ' エッジ点群の連結.
            status = api.fnFIE_edge_connecting(edges, edge_num, weight, threshold1, threshold2, area_size, _
                area_overlap, min_clust_elem, mode, clust, clust_num)

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

            ' 確認用.
            ' 確認用.
            Dim hdraw_image As FHANDLE = fnPRV_draw_edge_clust(hsrc, edges, clust, clust_num)
            api.fnFIE_save_png(ResultDir & "/fnFIE_edge_connecting2.png", hdraw_image, -1)
            hdraw_image.Dispose()
        Finally
            ' オブジェクトの開放.
            hsrc.Dispose()
            edges.Dispose()
            api.fnFIE_free_edge_clust(clust, clust_num)
        End Try
    End Sub
End Class

確認用の描画処理:
Visual Basic Copy imageCopy
Imports System.Collections.Generic
Imports System.Text
Imports fvalgcli

Public Partial Class FIE
    ''' <summary>
    ''' 連結された曲線を色を変えて入力画像上に描画する.
    ''' </summary>
    ''' <param name="hsrc">元画像</param>
    ''' <param name="edges">エッジ点群</param>
    ''' <param name="clust">クラスタ</param>
    ''' <param name="clust_num">クラスタ数</param>
    ''' <returns>
    '''        描画結果の画像。解放必要。
    ''' </returns>
    Private Function fnPRV_draw_edge_clust(hsrc As FHANDLE, edges As F_DEDGE_PTR, clust As F_EDGE_CLUST_PTR, clust_num As Integer) As FHANDLE
        Dim hdst As FHANDLE = FHANDLE.Zero

        ' 連結して生成された曲線描画用.
        Dim colors As Double(,) = {{0.0, 0.0, 255.0}, {0.0, 0.0, 128.0}, {0.0, 255.0, 0.0}, {255.0, 255.0, 0.0}, {255.0, 165.0, 0.0}, {255.0, 0.0, 0.0}, _
            {255.0, 192.0, 203.0}, {176.0, 48.0, 96.0}, {0.0, 255.0, 255.0}, {160.0, 32.0, 240.0}, {255.0, 0.0, 255.0}, {0.0, 100.0, 0.0}}

        Dim hdst0 As FHANDLE = FHANDLE.Zero
        Dim hdst1 As FHANDLE = FHANDLE.Zero
        Dim hdst2 As FHANDLE = FHANDLE.Zero
        Dim color As DOUBLE_PTR = DOUBLE_PTR.Zero
        Dim points As DPNT_T_PTR = DPNT_T_PTR.Zero

        Try
            ' 入力画像の情報取得.
            Dim width As Integer = api.fnFIE_img_get_width(hsrc)
            Dim height As Integer = api.fnFIE_img_get_height(hsrc)

            ' 出力画像の生成.
            hdst = api.fnFIE_img_root_alloc(CInt(f_imgtype.F_IMG_UC8), 3, width, height)

            hdst0 = api.fnFIE_img_child_alloc_single_ch(hdst, 0, 0, 0, width, height)
            ' CH0
            hdst1 = api.fnFIE_img_child_alloc_single_ch(hdst, 1, 0, 0, width, height)
            ' CH1
            hdst2 = api.fnFIE_img_child_alloc_single_ch(hdst, 2, 0, 0, width, height)
            ' CH2
            api.fnFIE_img_copy_ex(hsrc, hdst0, 1, 0, 0)
            api.fnFIE_img_copy_ex(hsrc, hdst1, 1, 0, 0)
            api.fnFIE_img_copy_ex(hsrc, hdst2, 1, 0, 0)

            ' 描画色.
            color = DOUBLE_PTR.alloc(3)
            ' R,G,B
            For i As Integer = 0 To clust_num - 1
                color(0) = colors(i Mod 4, 0)
                color(1) = colors(i Mod 4, 1)
                color(2) = colors(i Mod 4, 2)

                Dim num As Integer = clust(i).num - 1
                For j As Integer = 0 To num - 1
                    Dim index0 As Integer = clust(i).pindex(j + 0)
                    Dim index1 As Integer = clust(i).pindex(j + 1)
                    Dim st As DPNT_T = DPNT_T.init(edges(index0).x, edges(index0).y)
                    Dim ed As DPNT_T = DPNT_T.init(edges(index1).x, edges(index1).y)

                    ' 描画.
                    api.fnFIE_draw_line_seg(hdst, color, st, ed)
                Next
            Next
        Finally
            ' オブジェクトの開放.
            hdst0.Dispose()
            hdst1.Dispose()
            hdst2.Dispose()
            color.Dispose()
            points.Dispose()
        End Try

        Return hdst
    End Function
End Class

See Also