マスクによる エッジ点群のフィルタリング
Namespace: fvalgcliAssembly: fvalgcli (in fvalgcli.dll) Version: 3.1.0.0 (3.1.0.11)
Syntax
C# |
---|
public static int fnFIE_refilter_edge_by_mask( F_DEDGE_PTR src_edges, int src_edge_num, FHANDLE hmask, int mask_mode, ref F_DEDGE_PTR dst_edges, ref int dst_edge_num ) |
Visual Basic |
---|
Public Shared Function fnFIE_refilter_edge_by_mask ( src_edges As F_DEDGE_PTR, src_edge_num As Integer, hmask As FHANDLE, mask_mode As Integer, ByRef dst_edges As F_DEDGE_PTR, ByRef dst_edge_num As Integer ) As Integer |
Parameters
- src_edges
- Type: fvalgcli..::..F_DEDGE_PTR
入力エッジ点 配列
- src_edge_num
- Type: System..::..Int32
入力エッジ点の個数 ( 1 ≦ src_edge_num )
- hmask
- Type: fvalgcli..::..FHANDLE
マスク (リージョンオブジェクト、画像オブジェクト ( type:bin / ch:1 ))
- mask_mode
- Type: System..::..Int32
マスクモード (0:リージョンに含まれるエッジ点を省く、1:リージョンに含まれるエッジ点を残す)
- dst_edges
- Type: fvalgcli..::..F_DEDGE_PTR%
出力エッジ点 配列 ( 初期値は IntPtr.Zero を指定 )
- dst_edge_num
- Type: System..::..Int32%
出力エッジ点の個数
Return Value
Type: Int32以下のエラーコードを返します。
エラーコード:
f_err | 内容 |
---|---|
F_ERR_NONE | 正常終了 |
F_ERR_INVALID_IMAGE | 不正な画像オブジェクトが渡された |
F_ERR_INVALID_IMAGE | マスクとして渡された画像オブジェクトが不正である |
F_ERR_INVALID_PARAM | パラメータ異常 |
F_ERR_NOMEMORY | メモリ不足エラー |
F_ERR_NO_LICENCE | ライセンスエラー |
Examples
C# | Copy |
---|---|
using System; using System.Collections.Generic; using System.Text; using fvalgcli; namespace TC { public partial class FIE { [FvPluginExecute] public void fnFIE_refilter_edge_by_mask() { int status = (int)f_err.F_ERR_NONE; FHANDLE hsrc = FHANDLE.Zero; FHANDLE hmask = FHANDLE.Zero; FHANDLE hmag = FHANDLE.Zero; F_DEDGE_PTR src_edges = IntPtr.Zero; F_DEDGE_PTR dst_edges = IntPtr.Zero; int src_edge_num = 0; int dst_edge_num = 0; try { // 入力画像. api.fnFIE_load_img_file(TestImageDir + "/testdata/key_UC8_M.png", ref hsrc, f_color_img_type.F_COLOR_IMG_TYPE_UC8); api.fnFIE_load_img_file(TestImageDir + "/testdata/key_BIN_M.png", ref hmask, f_color_img_type.F_COLOR_IMG_TYPE_UC8); F_EDGE_SOBEL_PARAMS param; param.mag_threshold = 120; param.nms_length = 1; DPNT_T offset; offset.x = 0; offset.y = 0; var border_mode = f_border_mode.F_BORDER_NONE; var feat_mode = f_edge_feature_mode.F_EDGE_FEAT_DIRECT; // エッジ検出実行. status = api.fnFIE_edge_sobel_subpix(hsrc, IntPtr.Zero, ref param, feat_mode, border_mode, offset, ref src_edges, ref src_edge_num); Assert.IsTrue(status == (int)f_err.F_ERR_NONE, "fnFIE_edge_sobel_subpix: エラーが発生しました。({0})", (f_err)status); // マスクによるエッジ点群のフィルタリング. status = api.fnFIE_refilter_edge_by_mask( src_edges, src_edge_num, hmask, 1, ref dst_edges, ref dst_edge_num); Assert.IsTrue(status == (int)f_err.F_ERR_NONE, "エラーが発生しました。({0})", (f_err)status); // 確認用. { var hdraw_image = fnPRV_draw_edges(hsrc, src_edges, src_edge_num); api.fnFIE_save_png(ResultDir + "/fnFIE_refilter_edge_by_mask_1.png", hdraw_image, -1); hdraw_image.Dispose(); } // 確認用. { var hdraw_image = fnPRV_draw_edges(hsrc, dst_edges, dst_edge_num); api.fnFIE_save_png(ResultDir + "/fnFIE_refilter_edge_by_mask_2.png", hdraw_image, -1); hdraw_image.Dispose(); } } finally { hsrc.Dispose(); hmask.Dispose(); hmag.Dispose(); src_edges.Dispose(); dst_edges.Dispose(); } } } } |
確認用の描画処理: (エッジ点群)
C# | Copy |
---|---|
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="edge_num">エッジ点数</param> /// <returns> /// 描画結果の画像。解放必要。 /// </returns> private FHANDLE fnPRV_draw_edges(FHANDLE hsrc, F_DEDGE_PTR edges, int edge_num) { FHANDLE hdst = 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); FHANDLE hdst0 = FHANDLE.Zero; FHANDLE hdst1 = FHANDLE.Zero; FHANDLE hdst2 = FHANDLE.Zero; try { 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); } finally { hdst0.Dispose(); hdst1.Dispose(); hdst2.Dispose(); } // 描画色. color = DOUBLE_PTR.alloc(3); // R,G,B color[0] = 255; color[1] = 0; color[2] = 0; // 描画. for (int i = 0; i < edge_num; i++) { DPNT_T point = DPNT_T.init(edges[i].x, edges[i].y); api.fnFIE_draw_point(hdst, color, point); } } finally { // オブジェクトの開放. color.Dispose(); points.Dispose(); } return hdst; } } } |
確認用の描画処理: (エッジ点群のクラスタ)
C# | Copy |
---|---|
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 |
---|---|
Imports System.Collections.Generic Imports System.Text Imports fvalgcli Public Partial Class FIE <FvPluginExecute> _ Public Sub fnFIE_refilter_edge_by_mask() Dim status As Integer = CInt(f_err.F_ERR_NONE) Dim hsrc As FHANDLE = FHANDLE.Zero Dim hmask As FHANDLE = FHANDLE.Zero Dim hmag As FHANDLE = FHANDLE.Zero Dim src_edges As F_DEDGE_PTR = IntPtr.Zero Dim dst_edges As F_DEDGE_PTR = IntPtr.Zero Dim src_edge_num As Integer = 0 Dim dst_edge_num As Integer = 0 Try ' 入力画像. api.fnFIE_load_img_file(TestImageDir & "/testdata/key_UC8_M.png", hsrc, f_color_img_type.F_COLOR_IMG_TYPE_UC8) api.fnFIE_load_img_file(TestImageDir & "/testdata/key_BIN_M.png", hmask, f_color_img_type.F_COLOR_IMG_TYPE_UC8) Dim param As F_EDGE_SOBEL_PARAMS param.mag_threshold = 120 param.nms_length = 1 Dim offset As DPNT_T offset.x = 0 offset.y = 0 Dim border_mode As f_border_mode = f_border_mode.F_BORDER_NONE Dim feat_mode As f_edge_feature_mode = f_edge_feature_mode.F_EDGE_FEAT_DIRECT ' エッジ検出実行. status = api.fnFIE_edge_sobel_subpix(hsrc, IntPtr.Zero, param, feat_mode, border_mode, offset, _ src_edges, src_edge_num) Assert.IsTrue(status = CInt(f_err.F_ERR_NONE), "fnFIE_edge_sobel_subpix: エラーが発生しました。({0})", CType(status, f_err)) ' マスクによるエッジ点群のフィルタリング. status = api.fnFIE_refilter_edge_by_mask(src_edges, src_edge_num, hmask, 1, dst_edges, dst_edge_num) Assert.IsTrue(status = CInt(f_err.F_ERR_NONE), "エラーが発生しました。({0})", CType(status, f_err)) ' 確認用. If True Then Dim hdraw_image As FHANDLE = fnPRV_draw_edges(hsrc, src_edges, src_edge_num) api.fnFIE_save_png(ResultDir & "/fnFIE_refilter_edge_by_mask_1.png", hdraw_image, -1) hdraw_image.Dispose() End If ' 確認用. If True Then Dim hdraw_image As FHANDLE = fnPRV_draw_edges(hsrc, dst_edges, dst_edge_num) api.fnFIE_save_png(ResultDir & "/fnFIE_refilter_edge_by_mask_2.png", hdraw_image, -1) hdraw_image.Dispose() End If Finally hsrc.Dispose() hmask.Dispose() hmag.Dispose() src_edges.Dispose() dst_edges.Dispose() End Try End Sub End Class |
確認用の描画処理: (エッジ点群)
Visual Basic | Copy |
---|---|
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="edge_num">エッジ点数</param> ''' <returns> ''' 描画結果の画像。解放必要。 ''' </returns> Private Function fnPRV_draw_edges(hsrc As FHANDLE, edges As F_DEDGE_PTR, edge_num As Integer) As FHANDLE Dim hdst 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) Dim hdst0 As FHANDLE = FHANDLE.Zero Dim hdst1 As FHANDLE = FHANDLE.Zero Dim hdst2 As FHANDLE = FHANDLE.Zero Try 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) Finally hdst0.Dispose() hdst1.Dispose() hdst2.Dispose() End Try ' 描画色. color = DOUBLE_PTR.alloc(3) ' R,G,B color(0) = 255 color(1) = 0 color(2) = 0 ' 描画. For i As Integer = 0 To edge_num - 1 Dim point As DPNT_T = DPNT_T.init(edges(i).x, edges(i).y) api.fnFIE_draw_point(hdst, color, point) Next Finally ' オブジェクトの開放. color.Dispose() points.Dispose() End Try Return hdst End Function End Class |
確認用の描画処理: (エッジ点群のクラスタ)
Visual Basic | Copy |
---|---|
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 |