特定領域エッジ減点スコア計算

Namespace: FVIL.FPM2
Assembly: FVILbasic (in FVILbasic.dll) Version: 3.1.0.0 (3.1.0.17)

Syntax

C#
public static void MatchingRecalcWithEdgelessMask(
	CFviFPM2Template templ,
	CFviFPM2Feature target,
	int err_wide,
	double noise_weight,
	int threshold,
	int required_num,
	CFviFPM2Result result
)
Visual Basic
Public Shared Sub MatchingRecalcWithEdgelessMask ( 
	templ As CFviFPM2Template,
	target As CFviFPM2Feature,
	err_wide As Integer,
	noise_weight As Double,
	threshold As Integer,
	required_num As Integer,
	result As CFviFPM2Result
)

Parameters

templ
Type: FVIL.FPM2..::..CFviFPM2Template
特徴量オブジェクト (テンプレート)
target
Type: FVIL.FPM2..::..CFviFPM2Feature
特徴量オブジェクト (マッチング対象)
err_wide
Type: System..::..Int32
対応点誤差範囲 [0~]
noise_weight
Type: System..::..Double
エッジ減点重み係数 [0~]
※ エッジ減点領域内の 1 つのエッジに対する減点値の重みを表します。
threshold
Type: System..::..Int32
スコアしきい値 [0~100]
required_num
Type: System..::..Int32
結果取得数 [1~]
result
Type: FVIL.FPM2..::..CFviFPM2Result
マッチング結果

Remarks

指定されたエッジ減点領域情報を使用して特定領域エッジ減点スコアを計算します。

処理に失敗した場合は例外を発行します。 例外の原因と発生位置を特定するには、発行された例外クラスの ErrorCode メンバと Function メンバを参照してください。


エラーコード:
ErrorCode メンバ内容
51FVIL.ErrorCode.LICENSE_ERROR ライセンスキーが見つからない為、実行できません。 または、 FVIL._SetUp.InitVisionLibrary が実行されていません。
1FVIL.ErrorCode.FAILED_TO_ALLOCATEメモリが不足しています。
11FVIL.ErrorCode.INVALID_PARAMETERパラメータが不正です。
12FVIL.ErrorCode.INVALID_OBJECT特徴量オブジェクトが異常です。

関連する FIE 関数:

fnFIE_fpm_matching_recalc_with_edgeless_mask

Examples

ソースコード:
C# Copy imageCopy
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using fvalgcli;    // FvPluginXXXX attribute requires fvalgcli

namespace User.SampleCode
{
    public partial class FPM2
    {
        /// <summary>
        /// 特定領域エッジ減点スコア計算.
        /// </summary>
        [FvPluginExecute]
        public void MatchingRecalcWithEdgelessMask()
        {
            System.Reflection.MethodBase method = System.Reflection.MethodBase.GetCurrentMethod();
            Console.WriteLine("{0}.{1}", method.DeclaringType.FullName, method.Name);

            var timer = new FVIL.CFviTimeCounter();
            double msec;

            // 1) インスタンスの準備.
            using (var result = new FVIL.FPM2.CFviFPM2Result())
            using (var matching = new FVIL.FPM2.CFviFPM2Matching())
            using (var src = new FVIL.Data.CFviImage())
            using (var pattern = new FVIL.Data.CFviPattern())
            using (var mask = new FVIL.Data.CFviImage())
            {
                // 2-1) 処理対象画像の取り込み.
                src.Load(Defs.TestImageDir + "/key_UC8_M.png");

                // 2-2) パタン画像の読み込み.
                pattern.Load(Defs.TestImageDir + "/key1.pat");

                // 2-3) マスク画像の読み込み.
                mask.Load(Defs.TestImageDir + "/key-pattern-mask.png");

                // 3) パラメータ準備.

                // 3-1) (FPM2) 基本パラメータ設定.
                var param = matching.Param;
                param.Count = 10;
                param.AngleMin = new FVIL.Data.CFviAngle(-180);
                param.AngleMax = new FVIL.Data.CFviAngle(180);
                param.ScaleMin = 100;
                param.ScaleMax = 100;
                param.CompressionLevel = 3;
                param.ErrorRange = 1;
                param.ScoreThresholdL = 50;
                param.ScoreThresholdH = 50;

                // 3-4) (FPM2) 特徴量.
                var edge_param = new FVIL.Edge.CFviEdge2DSobelParam();
                edge_param.EdgeThreshold = 120;
                edge_param.NmsLength = 3;

                // 3-4-1) (FPM2) 特徴量(テンプレート) 生成.
                var templ = new FVIL.FPM2.CFviFPM2Template(pattern, FVIL.FPM2.MatchMode.Normal, edge_param);

                // 3-4-2) (FPM2) 特徴量(処理対象画像) 生成.
                var target = new FVIL.FPM2.CFviFPM2Feature(src, FVIL.FPM2.MatchMode.Normal, edge_param, false);

                // 4) パラメータ設定.
                matching.Param = param;
                matching.Target = target;
                matching.Template = templ;
                matching.Result = result;
                matching.EnableAreaScore = false;
                matching.EnableEssential = false;

                // 5) 画像処理実行.
                timer.Start();
                matching.Execute();
                msec = timer.Stop();
                Console.WriteLine("execute. {0:F3} msec, count={1} ", msec, result.Count);

                for (int i = 0; i < result.Count; i++)
                {
                    var item = result[i];
                    Console.WriteLine("{0}: x,y={1:F1},{2:F1} score={3} s={4:F1} q={5:F1}", i, item.x, item.y, item.score, item.s, item.q);
                }

                // 6-1) エッジ減点領域情報の設定.
                FVIL.FPM2.Function.SetTemplateEdgelessMask(templ, mask);

                // 6-2) エッジ減点領域情報の取得.
                using (var edgesless_mask = new FVIL.Data.CFviImage())
                {
                    FVIL.FPM2.Function.GetTemplateEdgelessMask(templ, edgesless_mask);

                    var ans = edgesless_mask.Compare(mask, 0.0, 1);
                    Console.WriteLine("GetTemplateEdgelessMask {0} ", ans);
                }

                // 6-3) 特定領域エッジ減点スコア計算.
                using (var edgeless_result = new FVIL.FPM2.CFviFPM2Result())
                {
                    timer.Start();

                    int err_wide = 0;
                    double noise_weight = 0.0;
                    int threshold = 60;
                    int required_num = 10;
                    FVIL.FPM2.Function.MatchingRecalcWithEdgelessMask(templ, target, err_wide, noise_weight, threshold, required_num, edgeless_result);

                    msec = timer.Stop();
                    Console.WriteLine("MatchingRecalcWithEdgelessMask. {0:F3} msec, count={1} ", msec, edgeless_result.Count);

                    for (int i = 0; i < edgeless_result.Count; i++)
                    {
                        var item = edgeless_result[i];
                        Console.WriteLine("{0}: x,y={1:F1},{2:F1} score={3} s={4:F1} q={5:F1}", i, item.x, item.y, item.score, item.s, item.q);
                    }
                }
            }
        }
    }
}

出力結果:
Copy imageCopy
User.SampleCode.FPM2.MatchingRecalcWithEdgelessMask
execute. 2.812 msec, count=3 
0: x,y=178.0,156.0 score=100 s=100.0 q=0.0
1: x,y=249.1,137.9 score=81 s=100.0 q=26.3
2: x,y=18.3,55.4 score=79 s=100.0 q=139.1
GetTemplateEdgelessMask True 
MatchingRecalcWithEdgelessMask. 0.654 msec, count=3 
0: x,y=178.0,156.0 score=100 s=100.0 q=0.0
1: x,y=249.1,137.9 score=75 s=100.0 q=26.3
2: x,y=18.3,55.4 score=60 s=100.0 q=139.1


ソースコード:
Visual Basic Copy imageCopy
Imports System.Collections.Generic
Imports System.Text
Imports System.Drawing
Imports fvalgcli
' FvPluginXXXX attribute requires fvalgcli
Namespace SampleCode
    Public Partial Class FPM2
        ''' <summary>
        ''' 特定領域エッジ減点スコア計算.
        ''' </summary>
        <FvPluginExecute> _
        Public Sub MatchingRecalcWithEdgelessMask()
            Dim method As System.Reflection.MethodBase = System.Reflection.MethodBase.GetCurrentMethod()
            Console.WriteLine("{0}.{1}", method.DeclaringType.FullName, method.Name)

            Dim timer As New FVIL.CFviTimeCounter()
            Dim msec As Double

            ' 1) インスタンスの準備.
            Dim result As New FVIL.FPM2.CFviFPM2Result()
            Dim matching As New FVIL.FPM2.CFviFPM2Matching()
            Dim src As New FVIL.Data.CFviImage()
            Dim pattern As New FVIL.Data.CFviPattern()
            Dim mask As New FVIL.Data.CFviImage()

            ' 2-1) 処理対象画像の取り込み.
            src.Load(Defs.TestImageDir & "/key_UC8_M.png")

            ' 2-2) パタン画像の読み込み.
            pattern.Load(Defs.TestImageDir & "/key1.pat")

            ' 2-3) マスク画像の読み込み.
            mask.Load(Defs.TestImageDir & "/key-pattern-mask.png")

            ' 3) パラメータ準備.

            ' 3-1) (FPM2) 基本パラメータ設定.
            Dim param = matching.Param
            param.Count = 10
            param.AngleMin = New FVIL.Data.CFviAngle(-180)
            param.AngleMax = New FVIL.Data.CFviAngle(180)
            param.ScaleMin = 100
            param.ScaleMax = 100
            param.CompressionLevel = 3
            param.ErrorRange = 1
            param.ScoreThresholdL = 50
            param.ScoreThresholdH = 50

            ' 3-4) (FPM2) 特徴量.
            Dim edge_param As New FVIL.Edge.CFviEdge2DSobelParam()
            edge_param.EdgeThreshold = 120
            edge_param.NmsLength = 3

            ' 3-4-1) (FPM2) 特徴量(テンプレート) 生成.
            Dim templ As New FVIL.FPM2.CFviFPM2Template(pattern, FVIL.FPM2.MatchMode.Normal, edge_param)

            ' 3-4-2) (FPM2) 特徴量(処理対象画像) 生成.
            Dim target As New FVIL.FPM2.CFviFPM2Feature(src, FVIL.FPM2.MatchMode.Normal, edge_param, False)

            ' 4) パラメータ設定.
            matching.Param = param
            matching.Target = target
            matching.Template = templ
            matching.Result = result
            matching.EnableAreaScore = False
            matching.EnableEssential = False

            ' 5) 画像処理実行.
            timer.Start()
            matching.Execute()
            msec = timer.[Stop]()
            Console.WriteLine("execute. {0:F3} msec, count={1} ", msec, result.Count)

            For i As Integer = 0 To result.Count - 1
                Dim item = result(i)
                Console.WriteLine("{0}: x,y={1:F1},{2:F1} score={3} s={4:F1} q={5:F1}", i, item.x, item.y, item.score, item.s, item.q)
            Next

            ' 6-1) エッジ減点領域情報の設定.
            FVIL.FPM2.[Function].SetTemplateEdgelessMask(templ, mask)

            ' 6-2) エッジ減点領域情報の取得.
            Using edgesless_mask = New FVIL.Data.CFviImage()
                FVIL.FPM2.[Function].GetTemplateEdgelessMask(templ, edgesless_mask)

                Dim ans = edgesless_mask.Compare(mask, 0.0, 1)
                Console.WriteLine("GetTemplateEdgelessMask {0} ", ans)
            End Using

            ' 6-3) 特定領域エッジ減点スコア計算.
            Using edgeless_result = New FVIL.FPM2.CFviFPM2Result()
                timer.Start()

                Dim err_wide As Integer = 0
                Dim noise_weight As Double = 0.0
                Dim threshold As Integer = 60
                Dim required_num As Integer = 10
                FVIL.FPM2.[Function].MatchingRecalcWithEdgelessMask(templ, target, err_wide, noise_weight, threshold, required_num, edgeless_result)

                msec = timer.[Stop]()
                Console.WriteLine("execute. {0:F3} msec, count={1} ", msec, edgeless_result.Count)

                For i As Integer = 0 To edgeless_result.Count - 1
                    Dim item = edgeless_result(i)
                    Console.WriteLine("{0}: x,y={1:F1},{2:F1} score={3} s={4:F1} q={5:F1}", i, item.x, item.y, item.score, item.s, item.q)
                Next
            End Using
        End Sub
    End Class
End Namespace

出力結果:
Copy imageCopy
User.SampleCode.FPM2.MatchingRecalcWithEdgelessMask
execute. 2.812 msec, count=3 
0: x,y=178.0,156.0 score=100 s=100.0 q=0.0
1: x,y=249.1,137.9 score=81 s=100.0 q=26.3
2: x,y=18.3,55.4 score=79 s=100.0 q=139.1
GetTemplateEdgelessMask True 
MatchingRecalcWithEdgelessMask. 0.654 msec, count=3 
0: x,y=178.0,156.0 score=100 s=100.0 q=0.0
1: x,y=249.1,137.9 score=75 s=100.0 q=26.3
2: x,y=18.3,55.4 score=60 s=100.0 q=139.1

Exceptions

ExceptionCondition
FVIL..::..CFviExceptionこの例外の原因については、上記のエラーコード表をご参照ください。

See Also