色抽出

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

Syntax

C#
public static int fnFIE_color_extraction(
	FHANDLE hsrc,
	FHANDLE hdst,
	F_COLOR_CHART_PTR charts,
	int num_chart,
	f_colorcheck_norm_type norm_type,
	DOUBLE_PTR weight,
	DOUBLE_PTR tolerance,
	bool back_clear
)
Visual Basic
Public Shared Function fnFIE_color_extraction ( 
	hsrc As FHANDLE,
	hdst As FHANDLE,
	charts As F_COLOR_CHART_PTR,
	num_chart As Integer,
	norm_type As f_colorcheck_norm_type,
	weight As DOUBLE_PTR,
	tolerance As DOUBLE_PTR,
	back_clear As Boolean
) As Integer

Parameters

hsrc
Type: fvalgcli..::..FHANDLE
入力画像(type:uc8,us16,double / ch:3)
hdst
Type: fvalgcli..::..FHANDLE
出力画像(type:uc8,us16,double / ch:3, type:bin / ch:1)
charts
Type: fvalgcli..::..F_COLOR_CHART_PTR
色票配列
num_chart
Type: System..::..Int32
色票数
norm_type
Type: fvalgcli..::..f_colorcheck_norm_type
ノルムタイプ
  • F_CC_EUCLIDEAN(ユークリッドノルム)
  • F_CC_WEIGHTED_EUCLIDEAN(重み付きユークリッドノルム)
  • F_CC_MAHALANOBIS(マハラノビスノルム)
  • F_CC_MANHATTAN(マンハッタンノルム)
  • F_CC_CHEBYSHEV(チェビシェフノルム)
  • F_CC_VARIANCE(分散基準)
  • F_CC_TOLERANCE(許容範囲基準)
weight
Type: fvalgcli..::..DOUBLE_PTR
重み付きユークリッドノルムの重み係数 norm_type に F_CC_WEIGHTED_EUCLIDEAN 以外を指定する場合は 本パラメータには IntPtr.Zero を指定してください。
tolerance
Type: fvalgcli..::..DOUBLE_PTR
許容範囲
back_clear
Type: System..::..Boolean
背景処理法
  • TRUE 領域外になる画素は0クリア
  • FALSE 領域外になる画素は処理しない

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_color_extraction()
        {
            fnFIE_color_extraction_euclidean();
            fnFIE_color_extraction_variance();
        }

        /// <summary>
        /// 色抽出の実行.(ユークリッドノルム)
        /// </summary>
        public void fnFIE_color_extraction_euclidean()
        {
            int status = (int)f_err.F_ERR_NONE;

            //string filepath = TestImageDir + "fie_colorcheck1.png";
            string filepath = TestImageDir + "/testdata/576x256_C32bpp.bmp";

            FHANDLE hSrc = FHANDLE.Zero;
            FHANDLE hDst = FHANDLE.Zero;
            FHANDLE hChild = FHANDLE.Zero;
            F_COLOR_CHART_PTR charts = F_COLOR_CHART_PTR.Zero;
            //DOUBLE_PTR weight = IntPtr.Zero;
            DOUBLE_PTR tollerance = DOUBLE_PTR.Zero;

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

                // 出力画像.
                int width = api.fnFIE_img_get_width(hSrc);
                int height = api.fnFIE_img_get_height(hSrc);
                int type = api.fnFIE_img_get_type(hSrc);
                int channels = 3;
                hDst = api.fnFIE_img_root_alloc(type, channels, width, height);

                // 色票リストを作成する.(色票数2)
                const int chart_size = 2;
                charts = F_COLOR_CHART_PTR.alloc(chart_size);

                // --- [0]
                hChild = api.fnFIE_img_child_alloc(hSrc, 165, 350, 25, 25);
                api.fnFIE_colorchart_calc_image(hChild, IntPtr.Zero, charts.at(0));
                hChild.Dispose();

                // --- [1]
                hChild = api.fnFIE_img_child_alloc(hSrc, 320, 215, 25, 25);
                api.fnFIE_colorchart_calc_image(hChild, IntPtr.Zero, charts.at(1));
                hChild.Dispose();

                // パラメータ.
                tollerance = DOUBLE_PTR.alloc(1);
                tollerance[0] = 10.0;

                Console.WriteLine("a");
                // 色抽出の実行.
                status = api.fnFIE_color_extraction(
                        hSrc,
                        hDst,
                        charts,
                        chart_size,
                        f_colorcheck_norm_type.F_CC_EUCLIDEAN,
                        IntPtr.Zero,
                        tollerance,
                        true);
                Console.WriteLine(status);

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

                Console.WriteLine("fnFIE_color_extraction");
                api.fnFIE_save_bmp(ResultDir + "/fnFIE_color_extraction.bmp", hDst);
            }
            finally
            {
                hSrc.Dispose();
                hDst.Dispose();
                hChild.Dispose();
                charts.Dispose();
                //weight.Dispose();
                tollerance.Dispose();
            }
        }

        /// <summary>
        /// 色抽出の実行.(分散基準)
        /// </summary>
        public void fnFIE_color_extraction_variance()
        {
            int status = (int)fvalgcli.f_err.F_ERR_NONE;

            //string filepath = TestImageDir + "fie_colorcheck1.png";
            string filepath = TestImageDir + "/testdata/576x256_C32bpp.bmp";

            FHANDLE hSrc = FHANDLE.Zero;
            FHANDLE hDst = FHANDLE.Zero;
            FHANDLE hChild = FHANDLE.Zero;
            F_COLOR_CHART_PTR charts = F_COLOR_CHART_PTR.Zero;
            //DOUBLE_PTR weight = IntPtr.Zero;
            DOUBLE_PTR tollerance = DOUBLE_PTR.Zero;

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

                // 出力画像.
                int width = api.fnFIE_img_get_width(hSrc);
                int height = api.fnFIE_img_get_height(hSrc);
                int type = api.fnFIE_img_get_type(hSrc);
                int channels = 3;
                hDst = api.fnFIE_img_root_alloc(type, channels, width, height);

                // 色票リストを作成する.(色票数2)
                const int chart_size = 2;
                charts = F_COLOR_CHART_PTR.alloc(chart_size);

                // --- [0]
                hChild = api.fnFIE_img_child_alloc(hSrc, 165, 350, 25, 25);
                api.fnFIE_colorchart_calc_image(hChild, IntPtr.Zero, charts.at(0));
                hChild.Dispose();

                // --- [1]
                hChild = api.fnFIE_img_child_alloc(hSrc, 320, 215, 25, 25);
                api.fnFIE_colorchart_calc_image(hChild, IntPtr.Zero, charts.at(1));
                hChild.Dispose();

                // パラメータ.
                tollerance = DOUBLE_PTR.alloc(3);
                tollerance[0] = 1.0;
                tollerance[1] = 2.0;
                tollerance[2] = 3.0;

                // 色抽出の実行.
                status = api.fnFIE_color_extraction(
                        hSrc,
                        hDst,
                        charts,
                        chart_size,
                        f_colorcheck_norm_type.F_CC_VARIANCE,
                        IntPtr.Zero,
                        tollerance,
                        true);

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

                Console.WriteLine("fnFIE_color_extraction");
                api.fnFIE_save_bmp(ResultDir + "/fnFIE_color_extraction_variance.bmp", hDst);
            }
            finally
            {
                hSrc.Dispose();
                hDst.Dispose();
                hChild.Dispose();
                charts.Dispose();
                //weight.Dispose();
                tollerance.Dispose();
            }
        }
    }
}


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_color_extraction()
        fnFIE_color_extraction_euclidean()
        fnFIE_color_extraction_variance()
    End Sub

    ''' <summary>
    ''' 色抽出の実行.(ユークリッドノルム)
    ''' </summary>
    Public Sub fnFIE_color_extraction_euclidean()
        Dim status As Integer = CInt(f_err.F_ERR_NONE)

        'string filepath = TestImageDir + "fie_colorcheck1.png";
        Dim filepath As String = TestImageDir & "/testdata/576x256_C32bpp.bmp"

        Dim hSrc As FHANDLE = FHANDLE.Zero
        Dim hDst As FHANDLE = FHANDLE.Zero
        Dim hChild As FHANDLE = FHANDLE.Zero
        Dim charts As F_COLOR_CHART_PTR = F_COLOR_CHART_PTR.Zero
        'DOUBLE_PTR weight = IntPtr.Zero;
        Dim tollerance As DOUBLE_PTR = DOUBLE_PTR.Zero

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

            ' 出力画像.
            Dim width As Integer = api.fnFIE_img_get_width(hSrc)
            Dim height As Integer = api.fnFIE_img_get_height(hSrc)
            Dim type As Integer = api.fnFIE_img_get_type(hSrc)
            Dim channels As Integer = 3
            hDst = api.fnFIE_img_root_alloc(type, channels, width, height)

            ' 色票リストを作成する.(色票数2)
            Const  chart_size As Integer = 2
            charts = F_COLOR_CHART_PTR.alloc(chart_size)

            ' --- [0]
            hChild = api.fnFIE_img_child_alloc(hSrc, 165, 350, 25, 25)
            api.fnFIE_colorchart_calc_image(hChild, IntPtr.Zero, charts.at(0))
            hChild.Dispose()

            ' --- [1]
            hChild = api.fnFIE_img_child_alloc(hSrc, 320, 215, 25, 25)
            api.fnFIE_colorchart_calc_image(hChild, IntPtr.Zero, charts.at(1))
            hChild.Dispose()

            ' パラメータ.
            tollerance = DOUBLE_PTR.alloc(1)
            tollerance(0) = 10.0

            Console.WriteLine("a")
            ' 色抽出の実行.
            status = api.fnFIE_color_extraction(hSrc, hDst, charts, chart_size, f_colorcheck_norm_type.F_CC_EUCLIDEAN, IntPtr.Zero, _
                tollerance, True)
            Console.WriteLine(status)

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

            Console.WriteLine("fnFIE_color_extraction")
            api.fnFIE_save_bmp(ResultDir & "/fnFIE_color_extraction.bmp", hDst)
        Finally
            hSrc.Dispose()
            hDst.Dispose()
            hChild.Dispose()
            charts.Dispose()
            'weight.Dispose();
            tollerance.Dispose()
        End Try
    End Sub

    ''' <summary>
    ''' 色抽出の実行.(分散基準)
    ''' </summary>
    Public Sub fnFIE_color_extraction_variance()
        Dim status As Integer = CInt(fvalgcli.f_err.F_ERR_NONE)

        'string filepath = TestImageDir + "fie_colorcheck1.png";
        Dim filepath As String = TestImageDir & "/testdata/576x256_C32bpp.bmp"

        Dim hSrc As FHANDLE = FHANDLE.Zero
        Dim hDst As FHANDLE = FHANDLE.Zero
        Dim hChild As FHANDLE = FHANDLE.Zero
        Dim charts As F_COLOR_CHART_PTR = F_COLOR_CHART_PTR.Zero
        'DOUBLE_PTR weight = IntPtr.Zero;
        Dim tollerance As DOUBLE_PTR = DOUBLE_PTR.Zero

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

            ' 出力画像.
            Dim width As Integer = api.fnFIE_img_get_width(hSrc)
            Dim height As Integer = api.fnFIE_img_get_height(hSrc)
            Dim type As Integer = api.fnFIE_img_get_type(hSrc)
            Dim channels As Integer = 3
            hDst = api.fnFIE_img_root_alloc(type, channels, width, height)

            ' 色票リストを作成する.(色票数2)
            Const  chart_size As Integer = 2
            charts = F_COLOR_CHART_PTR.alloc(chart_size)

            ' --- [0]
            hChild = api.fnFIE_img_child_alloc(hSrc, 165, 350, 25, 25)
            api.fnFIE_colorchart_calc_image(hChild, IntPtr.Zero, charts.at(0))
            hChild.Dispose()

            ' --- [1]
            hChild = api.fnFIE_img_child_alloc(hSrc, 320, 215, 25, 25)
            api.fnFIE_colorchart_calc_image(hChild, IntPtr.Zero, charts.at(1))
            hChild.Dispose()

            ' パラメータ.
            tollerance = DOUBLE_PTR.alloc(3)
            tollerance(0) = 1.0
            tollerance(1) = 2.0
            tollerance(2) = 3.0

            ' 色抽出の実行.
            status = api.fnFIE_color_extraction(hSrc, hDst, charts, chart_size, f_colorcheck_norm_type.F_CC_VARIANCE, IntPtr.Zero, _
                tollerance, True)

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

            Console.WriteLine("fnFIE_color_extraction")
            api.fnFIE_save_bmp(ResultDir & "/fnFIE_color_extraction_variance.bmp", hDst)
        Finally
            hSrc.Dispose()
            hDst.Dispose()
            hChild.Dispose()
            charts.Dispose()
            'weight.Dispose();
            tollerance.Dispose()
        End Try
    End Sub
End Class

See Also