十字マークの中心の検出

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

Syntax

C#
public static CFviPoint CrossMark(
	IEnumerable<CFviPoint> points
)
Visual Basic
Public Shared Function CrossMark ( 
	points As IEnumerable(Of CFviPoint)
) As CFviPoint

Parameters

points
Type: System.Collections.Generic..::..IEnumerable<(Of <(<'CFviPoint>)>)>
8つの点が格納された配列

Return Value

Type: CFviPoint
十字マークの中心座標を検出します。

■ 検出手順

  1. P1,P2,P3,P4,P5,P6,P7,P8の各中点を4つ検出します。 -
  2. 中点12と中点56、中点34と中点78を通る2本の直線を検出します。 -
  3. 求めた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>
        /// 十字マークの中心の検出の測定.
        /// </summary>
        /// <remarks>
        /// FVIL.Caliper.Function.CrossMark(System.Collections.Generic.IList{FVIL.Data.CFviPoint})
        /// </remarks>
        [FvPluginExecute]
        public void CrossMark_points()
        {
            // 1) 8つの点が格納された点列の生成.
            System.Collections.Generic.List<FVIL.Data.CFviPoint> points = new List<FVIL.Data.CFviPoint>();
            points.Add(new FVIL.Data.CFviPoint(80, 50));
            points.Add(new FVIL.Data.CFviPoint(150, 50));
            points.Add(new FVIL.Data.CFviPoint(180, 100));
            points.Add(new FVIL.Data.CFviPoint(180, 150));
            points.Add(new FVIL.Data.CFviPoint(100, 200));
            points.Add(new FVIL.Data.CFviPoint(150, 200));
            points.Add(new FVIL.Data.CFviPoint(50, 150));
            points.Add(new FVIL.Data.CFviPoint(50, 80));

            // 2) 計測実行.
            FVIL.Data.CFviPoint point = FVIL.Caliper.Function.CrossMark(points);

            // 確認用.
            {
                // 画像、描画表示クラス、オーバーレイのインスタンスの生成.
                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();

                {
                    // 描画図形の生成.
                    // 補助線(各2点(計測対象点)を通る線分)
                    System.Collections.Generic.List<FVIL.Data.CFviLineSegment> lines = new List<FVIL.Data.CFviLineSegment>();
                    for (int index = 0; (index + 1) < points.Count; index = index + 2)
                    {
                        lines.Add(new FVIL.Data.CFviLineSegment(points[index], points[index + 1]));
                    }
                    System.Collections.Generic.List<FVIL.GDI.CFviGdiLineSegment> glines1 = new List<FVIL.GDI.CFviGdiLineSegment>();
                    for(int index = 0; index < lines.Count ; index++)
                    {
                        glines1.Add( new FVIL.GDI.CFviGdiLineSegment(lines[index]));
                        glines1[index].Pen.Color = Color.Green;
                        glines1[index].Pen.Width = 1;
                        glines1[index].Pen.Style = FVIL.GDI.PenStyle.Dot;
                    }

                    // 補助線(中点同士を通る線分)
                    FVIL.Data.CFviPoint point1 = FVIL.Caliper.Function.CenterPoint(points[0], points[1]);
                    FVIL.Data.CFviPoint point2 = FVIL.Caliper.Function.CenterPoint(points[2], points[3]);
                    FVIL.Data.CFviPoint point3 = FVIL.Caliper.Function.CenterPoint(points[4], points[5]);
                    FVIL.Data.CFviPoint point4 = FVIL.Caliper.Function.CenterPoint(points[6], points[7]);
                    FVIL.Data.CFviLineSegment line5 = new FVIL.Data.CFviLineSegment(point1, point3);
                    FVIL.Data.CFviLineSegment line6 = new FVIL.Data.CFviLineSegment(point2, point4);
                    System.Collections.Generic.List<FVIL.GDI.CFviGdiLineSegment> glines2= new List<FVIL.GDI.CFviGdiLineSegment>();
                    glines2.Add( new FVIL.GDI.CFviGdiLineSegment( line5 ));
                    glines2.Add( new FVIL.GDI.CFviGdiLineSegment( line6 ));
                    for( int index = 0; index < glines2.Count; index++ )
                    {
                        glines2[index].Pen.Color = Color.Green;
                        glines2[index].Pen.Width = 1;
                        glines2[index].Pen.Style = FVIL.GDI.PenStyle.DashDotDot;
                    }

                    // 入力点群.
                    System.Collections.Generic.List<FVIL.GDI.CFviGdiPoint> gpoints = new List<FVIL.GDI.CFviGdiPoint>();
                    for( int index = 0; index < points.Count ; index++ )
                    {
                        gpoints.Add(new FVIL.GDI.CFviGdiPoint(points[index]));
                        gpoints[index].Pen.Color = Color.Green;
                        gpoints[index].Pen.Width = 4;
                    }

                    // 結果点.
                    FVIL.GDI.CFviGdiPoint gpoint2 = new FVIL.GDI.CFviGdiPoint(point);
                    gpoint2.Pen.Color = Color.Red;
                    gpoint2.Pen.Width = 4;

                    // 描画図形の追加.
                    foreach (FVIL.GDI.CFviGdiLineSegment gline1 in glines1)
                    {
                        overlay.Figures.Add(gline1);
                    }
                    foreach (FVIL.GDI.CFviGdiLineSegment gline2 in glines2)
                    {
                        overlay.Figures.Add(gline2);
                    }
                    foreach (FVIL.GDI.CFviGdiPoint gpoint in gpoints)
                    {
                        overlay.Figures.Add(gpoint);
                    }
                    overlay.Figures.Add(gpoint2);
                    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.CrossMark_points.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>
        ''' 十字マークの中心の検出の測定.
        ''' </summary>
        ''' <remarks>
        ''' FVIL.Caliper.Function.CrossMark(System.Collections.Generic.IList{FVIL.Data.CFviPoint})
        ''' </remarks>
        <FvPluginExecute> _
        Public Sub CrossMark_points()
            ' 1) 8つの点が格納された点列の生成.
            Dim points As System.Collections.Generic.List(Of FVIL.Data.CFviPoint) = New List(Of FVIL.Data.CFviPoint)()
            points.Add(New FVIL.Data.CFviPoint(80, 50))
            points.Add(New FVIL.Data.CFviPoint(150, 50))
            points.Add(New FVIL.Data.CFviPoint(180, 100))
            points.Add(New FVIL.Data.CFviPoint(180, 150))
            points.Add(New FVIL.Data.CFviPoint(100, 200))
            points.Add(New FVIL.Data.CFviPoint(150, 200))
            points.Add(New FVIL.Data.CFviPoint(50, 150))
            points.Add(New FVIL.Data.CFviPoint(50, 80))

            ' 2) 計測実行.
            Dim point As FVIL.Data.CFviPoint = FVIL.Caliper.[Function].CrossMark(points)

            ' 確認用.
            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
                    ' 描画図形の生成.
                    ' 補助線(各2点(計測対象点)を通る線分)
                    Dim lines As System.Collections.Generic.List(Of FVIL.Data.CFviLineSegment) = New List(Of FVIL.Data.CFviLineSegment)()
                    Dim index As Integer = 0
                    While (index + 1) < points.Count
                        lines.Add(New FVIL.Data.CFviLineSegment(points(index), points(index + 1)))
                        index = index + 2
                    End While
                    Dim glines1 As System.Collections.Generic.List(Of FVIL.GDI.CFviGdiLineSegment) = New List(Of FVIL.GDI.CFviGdiLineSegment)()
                    For index = 0 To lines.Count - 1
                        glines1.Add(New FVIL.GDI.CFviGdiLineSegment(lines(index)))
                        glines1(index).Pen.Color = Color.Green
                        glines1(index).Pen.Width = 1
                        glines1(index).Pen.Style = FVIL.GDI.PenStyle.Dot
                    Next

                    ' 補助線(中点同士を通る線分)
                    Dim point1 As FVIL.Data.CFviPoint = FVIL.Caliper.[Function].CenterPoint(points(0), points(1))
                    Dim point2 As FVIL.Data.CFviPoint = FVIL.Caliper.[Function].CenterPoint(points(2), points(3))
                    Dim point3 As FVIL.Data.CFviPoint = FVIL.Caliper.[Function].CenterPoint(points(4), points(5))
                    Dim point4 As FVIL.Data.CFviPoint = FVIL.Caliper.[Function].CenterPoint(points(6), points(7))
                    Dim line5 As New FVIL.Data.CFviLineSegment(point1, point3)
                    Dim line6 As New FVIL.Data.CFviLineSegment(point2, point4)
                    Dim glines2 As System.Collections.Generic.List(Of FVIL.GDI.CFviGdiLineSegment) = New List(Of FVIL.GDI.CFviGdiLineSegment)()
                    glines2.Add(New FVIL.GDI.CFviGdiLineSegment(line5))
                    glines2.Add(New FVIL.GDI.CFviGdiLineSegment(line6))
                    For index = 0 To glines2.Count - 1
                        glines2(index).Pen.Color = Color.Green
                        glines2(index).Pen.Width = 1
                        glines2(index).Pen.Style = FVIL.GDI.PenStyle.DashDotDot
                    Next

                    ' 入力点群.
                    Dim gpoints As System.Collections.Generic.List(Of FVIL.GDI.CFviGdiPoint) = New List(Of FVIL.GDI.CFviGdiPoint)()
                    For index = 0 To points.Count - 1
                        gpoints.Add(New FVIL.GDI.CFviGdiPoint(points(index)))
                        gpoints(index).Pen.Color = Color.Green
                        gpoints(index).Pen.Width = 4
                    Next

                    ' 結果点.
                    Dim gpoint2 As New FVIL.GDI.CFviGdiPoint(point)
                    gpoint2.Pen.Color = Color.Red
                    gpoint2.Pen.Width = 4

                    ' 描画図形の追加.
                    For Each gline1 As FVIL.GDI.CFviGdiLineSegment In glines1
                        overlay.Figures.Add(gline1)
                    Next
                    For Each gline2 As FVIL.GDI.CFviGdiLineSegment In glines2
                        overlay.Figures.Add(gline2)
                    Next
                    For Each gpoint As FVIL.GDI.CFviGdiPoint In gpoints
                        overlay.Figures.Add(gpoint)
                    Next
                    overlay.Figures.Add(gpoint2)
                    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.CrossMark_points.png", dstimage)
            End If
        End Sub
    End Class
End Namespace

Exceptions

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

See Also