グレイサーチの実行(圧縮度を強制する版2:サブピクセル推定近傍指定追加版)

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

Syntax

C#
public static int fnFIE_gs2_search_enforce2(
	FHANDLE hgs,
	FHANDLE hpattern,
	FHANDLE himage,
	BOX_T search_window,
	int threshold_mid,
	int threshold_final,
	bool edge_detect,
	bool reverse_mode,
	int pitch_x,
	int pitch_y,
	int first_unit,
	int last_unit,
	f_gs2_subpxl_neib subpxl_neib,
	F_GS_RESULT_PTR result,
	int max_result_num,
	ref int result_num
)
Visual Basic
Public Shared Function fnFIE_gs2_search_enforce2 ( 
	hgs As FHANDLE,
	hpattern As FHANDLE,
	himage As FHANDLE,
	search_window As BOX_T,
	threshold_mid As Integer,
	threshold_final As Integer,
	edge_detect As Boolean,
	reverse_mode As Boolean,
	pitch_x As Integer,
	pitch_y As Integer,
	first_unit As Integer,
	last_unit As Integer,
	subpxl_neib As f_gs2_subpxl_neib,
	result As F_GS_RESULT_PTR,
	max_result_num As Integer,
	ByRef result_num As Integer
) As Integer

Parameters

hgs
Type: fvalgcli..::..FHANDLE
グレイサーチオブジェクト
hpattern
Type: fvalgcli..::..FHANDLE
グレイサーチパターンオブジェクト
himage
Type: fvalgcli..::..FHANDLE
サーチ対象となる画像オブジェクト ( type : uc8 )。 チャネル数は1でなければいけません。 また、パタンのサイズよりも縦横共に大きい必要があります。
search_window
Type: fvalgcli..::..BOX_T
サーチウインドウ。 画像オブジェクトの中でサーチを行う処理範囲を himage 上の座標で指定します。 himage の内部に納まるように座標を指定する必要があります。 また、パタンのサイズよりも大きい必要があります。
threshold_mid
Type: System..::..Int32
途中相関値 ( 1000 〜 9999 )
threshold_final
Type: System..::..Int32
最終相関値 ( 1000 〜 9999 )
edge_detect
Type: System..::..Boolean
サーチウインドウ周囲接触フラグ。
  • TRUE サーチウインドウに接したパターンも検出
  • FALSE サーチウインドウに接したパターンを検出しない
reverse_mode
Type: System..::..Boolean
反転パターン検出モードフラグ。 濃度反転しているパターンも検出するかどうかを指定します。
  • TRUE 反転パターンも検出
  • FALSE 反転パターンを検出しない
pitch_x
Type: System..::..Int32
最終的な回答の出力時に、同一の解であるとみなす範囲を指定します。 0を入力した場合、パターン幅の半分になります。
pitch_y
Type: System..::..Int32
最終的な回答の出力時に、同一の解であるとみなす範囲を指定します。 0を入力した場合、パターン高さの半分になります。
first_unit
Type: System..::..Int32
サーチ開始圧縮度を指定します。( 0 〜 9 ) 圧縮度がnのとき、2の-n乗倍の画像でサーチを開始します。
last_unit
Type: System..::..Int32
サーチ終了圧縮度を指定します。( 0 〜 9 ) 圧縮度がnのとき、2の-n乗倍の画像でサーチを完了します。
subpxl_neib
Type: fvalgcli..::..f_gs2_subpxl_neib
精サーチ・サブピクセル推定に用いる近傍を指定します。 8近傍を指定する場合、サーチ終了圧縮度(last_unit)は 0 を推奨します。
  • F_GS2_SUBPXL_NEIB_4 4近傍
  • F_GS2_SUBPXL_NEIB_8 8近傍
result
Type: fvalgcli..::..F_GS_RESULT_PTR
サーチ結果。 サーチスコア( 0 〜 10000 )と結果座標の100倍値を返します。
max_result_num
Type: System..::..Int32
サーチ結果取得個数。 相関値の上位からこの個数だけ回答します。 result はこの個数よりも大きい配列でなければいけません。
result_num
Type: System..::..Int32%
見つかったサーチ結果の個数 ( 0 〜 max_result_num )

Return Value

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

エラーコード:
f_err内容
F_ERR_NONE正常終了
F_ERR_INVALID_PARAM 引数異常 引数オブジェクトがない、範囲外の引数を与えた、継続サーチ時に圧縮フィルタ種別が同一でないなど
F_ERR_INVALID_OBJECT引数オブジェクトの種別が異常
F_ERR_NOMEMORYメモリ不足
F_ERR_INVALID_IMAGE対応していない画像が渡された
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_gs2_search_enforce2()
        {
            int status = (int)f_err.F_ERR_NONE;
            FHANDLE hgs = FHANDLE.Zero;
            FHANDLE hSrc = FHANDLE.Zero;
            FHANDLE hPtn = FHANDLE.Zero;
            FHANDLE hMask = FHANDLE.Zero;
            FHANDLE hPattern = FHANDLE.Zero;
            F_GS_RESULT_PTR result = IntPtr.Zero;

            try
            {
                // サーチ対象画像の読み込み.
                status = api.fnFIE_load_img_file(TestImageDir + "/TC/SampleCode/key_UC8_M.png", ref hSrc, f_color_img_type.F_COLOR_IMG_TYPE_UC8);
                if (status != (int)f_err.F_ERR_NONE)
                    Assert.IsTrue(status == (int)f_err.F_ERR_NONE, "画像を開くときにエラーが発生しました。({0})", (f_err)status);

                // グレイサーチオブジェクトの生成.
                uint first_buff_size = 0;
                uint last_buff_size = 0;
                uint cache_pow_num = 0;
                hgs = api.fnFIE_gs2_alloc(first_buff_size, last_buff_size, cache_pow_num);
                Assert.IsTrue(hgs != FHANDLE.Zero, "fnFIE_gs2_alloc: エラーが発生しました。({0})", hgs);

                // グレイサーチパターンオブジェクト作成.
                hPtn = api.fnFIE_img_child_alloc(hSrc, 50, 0, 80, 80);
                int mark_offsetx = 10;
                int mark_offsety = 10;
                hPattern = api.fnFIE_gs2_pattern_alloc(hPtn, hMask, mark_offsetx, mark_offsety, f_comp_filter.F_COMP_MODE_SMOOTH, ref status);
                Assert.IsTrue(status == (int)f_err.F_ERR_NONE, "fnFIE_gs2_pattern_alloc: エラーが発生しました。({0})", (f_err)status);

                // グレイサーチ実行.
                BOX_T search_window = new BOX_T();
                search_window.st.x = 0;
                search_window.st.y = 0;
                search_window.ed.x = api.fnFIE_img_get_width(hSrc) - 1;
                search_window.ed.y = api.fnFIE_img_get_height(hSrc) - 1;
                int threshold_mid = 5000;
                int threshold_final = 6000;
                bool edge_detect = true;
                bool reverse_mode = true;
                int pitch_x = 0;
                int pitch_y = 0;
                int first_unit = 0;
                int last_unit = 0;
                f_gs2_subpxl_neib subpxl_neib = f_gs2_subpxl_neib.F_GS2_SUBPXL_NEIB_8;
                int max_result_num = 10;
                result = F_GS_RESULT_PTR.alloc(max_result_num);
                int result_num = 0;

                status = api.fnFIE_gs2_search_enforce2(
                        hgs,
                        hPattern,
                        hSrc,
                        search_window,
                        threshold_mid,
                        threshold_final,
                        edge_detect,
                        reverse_mode,
                        pitch_x,
                        pitch_y,
                        first_unit,
                        last_unit,
                        subpxl_neib,
                        result,
                        max_result_num,
                        ref result_num
                    );
                Assert.IsTrue(status == (int)f_err.F_ERR_NONE, "fnFIE_gs2_search_enforce2: エラーが発生しました。({0})", (f_err)status);
                Console.WriteLine("fnFIE_gs2_search_enforce2");
                for (int i = 0; i < result_num; i++)
                    Console.WriteLine("result[{0}]=({1}, {2}, {3})", i, result[i].x, result[i].y, result[i].score);
            }
            finally
            {
                hgs.Dispose();
                hSrc.Dispose();
                hPtn.Dispose();
                hMask.Dispose();
                hPattern.Dispose();
                result.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_gs2_search_enforce2()
        Dim status As Integer = CInt(f_err.F_ERR_NONE)
        Dim hgs As FHANDLE = FHANDLE.Zero
        Dim hSrc As FHANDLE = FHANDLE.Zero
        Dim hPtn As FHANDLE = FHANDLE.Zero
        Dim hMask As FHANDLE = FHANDLE.Zero
        Dim hPattern As FHANDLE = FHANDLE.Zero
        Dim result As F_GS_RESULT_PTR = IntPtr.Zero

        Try
            ' サーチ対象画像の読み込み.
            status = api.fnFIE_load_img_file(TestImageDir & "/TC/SampleCode/key_UC8_M.png", hSrc, f_color_img_type.F_COLOR_IMG_TYPE_UC8)
            If status <> CInt(f_err.F_ERR_NONE) Then
                Assert.IsTrue(status = CInt(f_err.F_ERR_NONE), "画像を開くときにエラーが発生しました。({0})", CType(status, f_err))
            End If

            ' グレイサーチオブジェクトの生成.
            Dim first_buff_size As UInteger = 0
            Dim last_buff_size As UInteger = 0
            Dim cache_pow_num As UInteger = 0
            hgs = api.fnFIE_gs2_alloc(first_buff_size, last_buff_size, cache_pow_num)
            Assert.IsTrue(hgs <> FHANDLE.Zero, "fnFIE_gs2_alloc: エラーが発生しました。({0})", hgs)

            ' グレイサーチパターンオブジェクト作成.
            hPtn = api.fnFIE_img_child_alloc(hSrc, 50, 0, 80, 80)
            Dim mark_offsetx As Integer = 10
            Dim mark_offsety As Integer = 10
            hPattern = api.fnFIE_gs2_pattern_alloc(hPtn, hMask, mark_offsetx, mark_offsety, f_comp_filter.F_COMP_MODE_SMOOTH, status)
            Assert.IsTrue(status = CInt(f_err.F_ERR_NONE), "fnFIE_gs2_pattern_alloc: エラーが発生しました。({0})", CType(status, f_err))

            ' グレイサーチ実行.
            Dim search_window As New BOX_T()
            search_window.st.x = 0
            search_window.st.y = 0
            search_window.ed.x = api.fnFIE_img_get_width(hSrc) - 1
            search_window.ed.y = api.fnFIE_img_get_height(hSrc) - 1
            Dim threshold_mid As Integer = 5000
            Dim threshold_final As Integer = 6000
            Dim edge_detect As Boolean = True
            Dim reverse_mode As Boolean = True
            Dim pitch_x As Integer = 0
            Dim pitch_y As Integer = 0
            Dim first_unit As Integer = 0
            Dim last_unit As Integer = 0
            Dim subpxl_neib As f_gs2_subpxl_neib = f_gs2_subpxl_neib.F_GS2_SUBPXL_NEIB_8
            Dim max_result_num As Integer = 10
            result = F_GS_RESULT_PTR.alloc(max_result_num)
            Dim result_num As Integer = 0

            status = api.fnFIE_gs2_search_enforce2(hgs, hPattern, hSrc, search_window, threshold_mid, threshold_final, _
                edge_detect, reverse_mode, pitch_x, pitch_y, first_unit, last_unit, _
                subpxl_neib, result, max_result_num, result_num)
            Assert.IsTrue(status = CInt(f_err.F_ERR_NONE), "fnFIE_gs2_search_enforce2: エラーが発生しました。({0})", CType(status, f_err))
            Console.WriteLine("fnFIE_gs2_search_enforce2")
            For i As Integer = 0 To result_num - 1
                Console.WriteLine("result[{0}]=({1}, {2}, {3})", i, result(i).x, result(i).y, result(i).score)
            Next
        Finally
            hgs.Dispose()
            hSrc.Dispose()
            hPtn.Dispose()
            hMask.Dispose()
            hPattern.Dispose()
            result.Dispose()
        End Try
    End Sub
End Class

See Also