中心線の算出(2直線)

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

Syntax

C#
public static CFviLine CenterLine(
	CFviLine line1,
	CFviLine line2
)
Visual Basic
Public Shared Function CenterLine ( 
	line1 As CFviLine,
	line2 As CFviLine
) As CFviLine

Parameters

line1
Type: FVIL.Data..::..CFviLine
直線1
line2
Type: FVIL.Data..::..CFviLine
直線2

Return Value

Type: CFviLine
2つの直線の中心を通る直線を求めます。 2直線の交角の狭い方で中心線を検出します。2直線が直交する場合には、例外を発行します。

正常に実行できなかった場合は例外を発行します。 例外の原因と発生位置を特定するには、発行された例外クラスの ErrorCode メンバと Function メンバを参照してください。

エラーコード:

ErrorCode メンバ内容
51FVIL.ErrorCode.LICENSE_ERROR ライセンスキーが見つからない為、実行できません。 または、 FVIL._SetUp.InitVisionLibrary が実行されていません。
11FVIL.ErrorCode.INVALID_PARAMETERパラメータに誤りがあります。
29FVIL.ErrorCode.NOT_CALCULABLE計算不可能です。

Examples

C# Copy imageCopy
//    $Revision: 1.3 $

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using fvalgcli;    // FvPluginXXXX attribute requires fvalgcli

namespace User.SampleCode
{
    public partial class Caliper
    {
        /// <summary>
        /// 中心線の算出(2直線)の測定.
        /// </summary>
        /// <remarks>
        /// FVIL.Caliper.Function.CenterLine(FVIL.Data.CFviLine,FVIL.Data.CFviLine)
        /// </remarks>
        [FvPluginExecute]
        public void CenterLine_line_line()
        {
            // 1) 直線の生成.
            FVIL.Data.CFviLine line1 = new FVIL.Data.CFviLine(2, -1, 22);
            FVIL.Data.CFviLine line2 = new FVIL.Data.CFviLine(1, -1, -21);

            // 2) 計測実行.
            FVIL.Data.CFviLine line = FVIL.Caliper.Function.CenterLine(line1, line2);

            // 確認用.
            {
                // 画像、描画表示クラス、オーバーレイのインスタンスの生成.
                FVIL.Data.CFviImage image = new FVIL.Data.CFviImage(320, 240, FVIL.ImageType.UC8, 1);
                FVIL.GDI.CFviDisplay display = new FVIL.GDI.CFviDisplay();
                FVIL.GDI.CFviOverlay overlay = new FVIL.GDI.CFviOverlay();

                {
                    // 描画図形の生成.
                    // 入力線1
                    FVIL.GDI.CFviGdiLine gline1 = new FVIL.GDI.CFviGdiLine(line1);
                    gline1.Pen.Color = Color.Green;
                    gline1.Pen.Width = 1;

                    // 入力線2
                    FVIL.GDI.CFviGdiLine gline2 = new FVIL.GDI.CFviGdiLine(line2);
                    gline2.Pen.Color = Color.Green;
                    gline2.Pen.Width = 1;

                    // 結果線.
                    FVIL.GDI.CFviGdiLine gline3 = new FVIL.GDI.CFviGdiLine(line);
                    gline3.Pen.Color = Color.Red;
                    gline3.Pen.Width = 1;

                    // 描画図形の追加.
                    overlay.Figures.Add(gline1);
                    overlay.Figures.Add(gline2);
                    overlay.Figures.Add(gline3);
                    overlay.Enable = true;
                }

                // 画像表示クラスへの追加.
                display.Overlays.Add(overlay);
                display.Image = image;
                display.DisplayRect = image.Window;

                // 描画イメージの保存.
                FVIL.Data.CFviImage dstimage = new FVIL.Data.CFviImage();
                display.SaveImage(dstimage);
                FVIL.File.Function.SaveImageFile(Defs.ResultDir + "/Caliper.CenterLine_line_line.png", dstimage);
            }
        }
    }
}


Visual Basic Copy imageCopy
'    $Revision: 1.1 $

Imports System.Collections.Generic
Imports System.Text
Imports System.Drawing
Imports fvalgcli
' FvPluginXXXX attribute requires fvalgcli
Namespace SampleCode
    Public Partial Class Caliper
        ''' <summary>
        ''' 中心線の算出(2直線)の測定.
        ''' </summary>
        ''' <remarks>
        ''' FVIL.Caliper.Function.CenterLine(FVIL.Data.CFviLine,FVIL.Data.CFviLine)
        ''' </remarks>
        <FvPluginExecute> _
        Public Sub CenterLine_line_line()
            ' 1) 直線の生成.
            Dim line1 As New FVIL.Data.CFviLine(2, -1, 22)
            Dim line2 As New FVIL.Data.CFviLine(1, -1, -21)

            ' 2) 計測実行.
            Dim line As FVIL.Data.CFviLine = FVIL.Caliper.[Function].CenterLine(line1, line2)

            ' 確認用.
            If True Then
                ' 画像、描画表示クラス、オーバーレイのインスタンスの生成.
                Dim image As New FVIL.Data.CFviImage(320, 240, FVIL.ImageType.UC8, 1)
                Dim display As New FVIL.GDI.CFviDisplay()
                Dim overlay As New FVIL.GDI.CFviOverlay()

                If True Then
                    ' 描画図形の生成.
                    ' 入力線1
                    Dim gline1 As New FVIL.GDI.CFviGdiLine(line1)
                    gline1.Pen.Color = Color.Green
                    gline1.Pen.Width = 1

                    ' 入力線2
                    Dim gline2 As New FVIL.GDI.CFviGdiLine(line2)
                    gline2.Pen.Color = Color.Green
                    gline2.Pen.Width = 1

                    ' 結果線.
                    Dim gline3 As New FVIL.GDI.CFviGdiLine(line)
                    gline3.Pen.Color = Color.Red
                    gline3.Pen.Width = 1

                    ' 描画図形の追加.
                    overlay.Figures.Add(gline1)
                    overlay.Figures.Add(gline2)
                    overlay.Figures.Add(gline3)
                    overlay.Enable = True
                End If

                ' 画像表示クラスへの追加.
                display.Overlays.Add(overlay)
                display.Image = image
                display.DisplayRect = image.Window

                ' 描画イメージの保存.
                Dim dstimage As New FVIL.Data.CFviImage()
                display.SaveImage(dstimage)
                FVIL.File.[Function].SaveImageFile(Defs.ResultDir & "/Caliper.CenterLine_line_line.png", dstimage)
            End If
        End Sub
    End Class
End Namespace

Exceptions

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

See Also