色判定の実行

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

Syntax

C#
public static int fnFIE_colorcheck_execute(
	FHANDLE htbl,
	F_COLOR_CHART_PTR target,
	f_colorcheck_norm_type norm_type,
	DOUBLE_PTR weight,
	double threshold,
	F_COLOR_CHART_PTR right,
	ref int id,
	ref double norm
)
Visual Basic
Public Shared Function fnFIE_colorcheck_execute ( 
	htbl As FHANDLE,
	target As F_COLOR_CHART_PTR,
	norm_type As f_colorcheck_norm_type,
	weight As DOUBLE_PTR,
	threshold As Double,
	right As F_COLOR_CHART_PTR,
	ByRef id As Integer,
	ByRef norm As Double
) As Integer

Parameters

htbl
Type: fvalgcli..::..FHANDLE
ノルムテーブルのハンドル
target
Type: fvalgcli..::..F_COLOR_CHART_PTR
対象色票
norm_type
Type: fvalgcli..::..f_colorcheck_norm_type
ノルムタイプ
  • F_CC_EUCLIDEAN(ユークリッドノルム)
  • F_CC_WEIGHTED_EUCLIDEAN(重み付きユークリッドノルム)
  • F_CC_MAHALANOBIS(マハラノビスノルム)
  • F_CC_MANHATTAN(マンハッタンノルム)
  • F_CC_CHEBYSHEV(チェビシェフノルム)
weight
Type: fvalgcli..::..DOUBLE_PTR
重み付きユークリッドノルムの重み係数
threshold
Type: System..::..Double
閾値(ノルム)
right
Type: fvalgcli..::..F_COLOR_CHART_PTR
正解色票
id
Type: System..::..Int32%
正解色票のID
norm
Type: System..::..Double%
ノルム

Return Value

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

エラーコード:
f_err内容
F_ERR_NONE正常終了
F_ERR_INVALID_IMAGE画像オブジェクトの異常
F_ERR_INVALID_OBJECT 不正なオブジェクトが渡された
F_ERR_INVALID_PARAMパラメータ異常
F_ERR_NOMEMORYメモリ不足エラー
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
    {
        /// <summary>
        /// 色判定の実行.
        /// </summary>
        [FvPluginExecute]
        public void fnFIE_colorcheck_execute()
        {
            int status = (int)f_err.F_ERR_NONE;

            string filepath = TestImageDir + "fie_colorcheck1.png";
            const int max_size = 10;    // 最大色票数.

            FHANDLE hTable = FHANDLE.Zero;
            FHANDLE hSrc = FHANDLE.Zero;
            FHANDLE hChild = FHANDLE.Zero;
            F_COLOR_CHART_PTR right = IntPtr.Zero;
            F_COLOR_CHART_PTR target = IntPtr.Zero;
            DOUBLE_PTR color = IntPtr.Zero;
            DOUBLE_PTR weight = IntPtr.Zero;

            try
            {
                // 入力画像.
                api.fnFIE_load_png(filepath, ref hSrc, f_color_img_type.F_COLOR_IMG_TYPE_UC8);

                // 生成.
                hTable = api.fnFIE_colorcheck_open_table(max_size);

                // 正解色票を色票テーブルに設定する.
                right = F_COLOR_CHART_PTR.alloc(1);

                // --- ID1
                hChild = api.fnFIE_img_child_alloc(hSrc, 165, 350, 25, 25);
                api.fnFIE_colorchart_calc_image(hChild, IntPtr.Zero, right);
                api.fnFIE_colorcheck_set_right_color_chart(hTable, 1, right);
                hChild.Dispose();

                // --- ID5
                hChild = api.fnFIE_img_child_alloc(hSrc, 320, 215, 25, 25);
                api.fnFIE_colorchart_calc_image(hChild, IntPtr.Zero, right);
                api.fnFIE_colorcheck_set_right_color_chart(hTable, 5, right);
                hChild.Dispose();

                // 対象色票.
                target = F_COLOR_CHART_PTR.alloc(1);
                color = DOUBLE_PTR.alloc(3);
                color[0] = 64.0;
                color[1] = 128.0;
                color[2] = 192.0;
                api.fnFIE_colorchart_set_color(color, target);
                color.Dispose();

                // 色判定.
                right[0] = F_COLOR_CHART.init();
                double threshold = -1;
                int id = 0;
                double norm = 0;

                // --- 実行.
                status = api.fnFIE_colorcheck_execute(
                        hTable,
                        target,
                        f_colorcheck_norm_type.F_CC_EUCLIDEAN,
                        weight,
                        threshold,
                        right,
                        ref id,
                        ref norm);

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

                Console.WriteLine("fnFIE_colorcheck_execute");
                Console.WriteLine("id={0}", id);
                Console.WriteLine("norm={0}", norm);
                Console.WriteLine("right: {0}", ChartToString(right[0]));

                // 詳細情報取得.
                fnFIE_colorcheck_get_detail_result(hTable, 1);
                fnFIE_colorcheck_get_detail_result(hTable, 5);
            }
            finally
            {
                hTable.Dispose();
                hSrc.Dispose();
                hChild.Dispose();
                right.Dispose();
                target.Dispose();
                color.Dispose();
                weight.Dispose();
            }
        }

        /// <summary>
        /// コンソール出力.
        /// </summary>
        /// <param name="chart">色票</param>
        public string ChartToString(F_COLOR_CHART chart)
        {
            return string.Format("color={0},{1},{2} flag={3}",
                chart.color[0],
                chart.color[1],
                chart.color[2],
                chart.flag);
        }
    }
}


Visual Basic Copy imageCopy
'    $Revision: 1.1 $

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

Public Partial Class FIE
    ''' <summary>
    ''' 色判定の実行.
    ''' </summary>
    <FvPluginExecute> _
    Public Sub fnFIE_colorcheck_execute()
        Dim status As Integer = CInt(f_err.F_ERR_NONE)

        Dim filepath As String = TestImageDir & "fie_colorcheck1.png"
        Const  max_size As Integer = 10
        ' 最大色票数.
        Dim hTable As FHANDLE = FHANDLE.Zero
        Dim hSrc As FHANDLE = FHANDLE.Zero
        Dim hChild As FHANDLE = FHANDLE.Zero
        Dim right As F_COLOR_CHART_PTR = IntPtr.Zero
        Dim target As F_COLOR_CHART_PTR = IntPtr.Zero
        Dim color As DOUBLE_PTR = IntPtr.Zero
        Dim weight As DOUBLE_PTR = IntPtr.Zero

        Try
            ' 入力画像.
            api.fnFIE_load_png(filepath, hSrc, f_color_img_type.F_COLOR_IMG_TYPE_UC8)

            ' 生成.
            hTable = api.fnFIE_colorcheck_open_table(max_size)

            ' 正解色票を色票テーブルに設定する.
            right = F_COLOR_CHART_PTR.alloc(1)

            ' --- ID1
            hChild = api.fnFIE_img_child_alloc(hSrc, 165, 350, 25, 25)
            api.fnFIE_colorchart_calc_image(hChild, IntPtr.Zero, right)
            api.fnFIE_colorcheck_set_right_color_chart(hTable, 1, right)
            hChild.Dispose()

            ' --- ID5
            hChild = api.fnFIE_img_child_alloc(hSrc, 320, 215, 25, 25)
            api.fnFIE_colorchart_calc_image(hChild, IntPtr.Zero, right)
            api.fnFIE_colorcheck_set_right_color_chart(hTable, 5, right)
            hChild.Dispose()

            ' 対象色票.
            target = F_COLOR_CHART_PTR.alloc(1)
            color = DOUBLE_PTR.alloc(3)
            color(0) = 64.0
            color(1) = 128.0
            color(2) = 192.0
            api.fnFIE_colorchart_set_color(color, target)
            color.Dispose()

            ' 色判定.
            right(0) = F_COLOR_CHART.init()
            Dim threshold As Double = -1
            Dim id As Integer = 0
            Dim norm As Double = 0

            ' --- 実行.
            status = api.fnFIE_colorcheck_execute(hTable, target, f_colorcheck_norm_type.F_CC_EUCLIDEAN, weight, threshold, right, _
                id, norm)

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

            Console.WriteLine("fnFIE_colorcheck_execute")
            Console.WriteLine("id={0}", id)
            Console.WriteLine("norm={0}", norm)
            Console.WriteLine("right: {0}", ChartToString(right(0)))

            ' 詳細情報取得.
            fnFIE_colorcheck_get_detail_result(hTable, 1)
            fnFIE_colorcheck_get_detail_result(hTable, 5)
        Finally
            hTable.Dispose()
            hSrc.Dispose()
            hChild.Dispose()
            right.Dispose()
            target.Dispose()
            color.Dispose()
            weight.Dispose()
        End Try
    End Sub

    ''' <summary>
    ''' コンソール出力.
    ''' </summary>
    ''' <param name="chart">色票</param>
    Public Function ChartToString(chart As F_COLOR_CHART) As String
        Return String.Format("color={0},{1},{2} flag={3}", chart.color(0), chart.color(1), chart.color(2), chart.flag)
    End Function
End Class

See Also