長穴の測定
Namespace: FVIL.CaliperAssembly: FVILbasic (in FVILbasic.dll) Version: 3.1.0.0 (3.1.0.17)
Syntax
C# |
---|
public static CFviCaliperRectangle LongHole( IEnumerable<CFviPoint> points ) |
Visual Basic |
---|
Public Shared Function LongHole ( points As IEnumerable(Of CFviPoint) ) As CFviCaliperRectangle |
Parameters
- points
- Type: System.Collections.Generic..::..IEnumerable<(Of <(<'CFviPoint>)>)>
6つの点が格納された配列
Return Value
Type: CFviCaliperRectangle6つの点によって作られる長穴を測定します。
■ 検出手順
- P1とP2、P4とP5の作る各直線(L12、L45)を求め、2直線の中心線を検出します。 -
- P2とP3とP4の作る円1、P5とP6とP1の作る円2を検出します。 -
- 円1と中心線の交点P1、円2と中心線の交点P2を求めます。 -
- P1上での接線TL1、P2上での接線TL2を求めます。 -
- 以上のL12、TL1、L45、TL2の4つの直線が作る四角形から長穴を測定します。 -
■ 戻り値(CFviCaliperRectangle)の各メンバ
長辺と短辺を格納する Long1 と Short1 は、四角形の L12 と TL1 の長さを比較して 長い方が Long1 に格納され、短い方は Short1 に格納されます。 Long2 と Short2 については Long1 に L12 が入った場合には Long2 は L45、 Short2 には TL2 のように L12 と L45、TL1 と TL2 の向かい合う辺が対応して Long と Short に格納されます。
Long1 | 四角形の L12 と TL1 の長さを比較して長い方 |
Short1 | 四角形の L12 と TL1 の長さを比較して短い方 |
Long2 | Long1 と向かい合う辺 |
Short2 | Short1 と向かい合う辺 |
Center | 長方形の中心座標 |
正常に実行できなかった場合は例外を発行します。 例外の原因と発生位置を特定するには、発行された例外クラスの ErrorCode メンバと Function メンバを参照してください。
エラーコード:
値 | ErrorCode メンバ | 内容 |
---|---|---|
51 | FVIL.ErrorCode.LICENSE_ERROR | ライセンスキーが見つからない為、実行できません。 または、 FVIL._SetUp.InitVisionLibrary が実行されていません。 |
11 | FVIL.ErrorCode.INVALID_PARAMETER | パラメータに誤りがあります。 |
29 | FVIL.ErrorCode.NOT_CALCULABLE | 計算不可能です。 |
Examples
C# | Copy |
---|---|
// $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.LongHole(System.Collections.Generic.IList{FVIL.Data.CFviPoint}) /// </remarks> [FvPluginExecute] public void LongHole() { // 1) 6つの点が格納された点列の生成. System.Collections.Generic.List<FVIL.Data.CFviPoint> points = new List<FVIL.Data.CFviPoint>(); points.Add(new FVIL.Data.CFviPoint(100,80)); points.Add(new FVIL.Data.CFviPoint(220, 80)); points.Add(new FVIL.Data.CFviPoint(250, 130)); points.Add(new FVIL.Data.CFviPoint(220, 180)); points.Add(new FVIL.Data.CFviPoint(100, 180)); points.Add(new FVIL.Data.CFviPoint(50, 130)); // 2) 計測実行. FVIL.Caliper.CFviCaliperRectangle rect1 = FVIL.Caliper.Function.LongHole(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(); { // 描画図形の生成. // 入力点群. 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 gpoint1 = new FVIL.GDI.CFviGdiPoint(rect1.Center); gpoint1.Pen.Color = Color.Red; gpoint1.Pen.Width = 4; // 描画図形の追加. foreach (FVIL.GDI.CFviGdiPoint gpoint in gpoints) { overlay.Figures.Add(gpoint); } overlay.Figures.Add(gpoint1); 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.LongHole.png", dstimage); } } } } |
Visual Basic | Copy |
---|---|
' $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.LongHole(System.Collections.Generic.IList{FVIL.Data.CFviPoint}) ''' </remarks> <FvPluginExecute> _ Public Sub LongHole() ' 1) 6つの点が格納された点列の生成. Dim points As System.Collections.Generic.List(Of FVIL.Data.CFviPoint) = New List(Of FVIL.Data.CFviPoint)() points.Add(New FVIL.Data.CFviPoint(100, 80)) points.Add(New FVIL.Data.CFviPoint(220, 80)) points.Add(New FVIL.Data.CFviPoint(250, 130)) points.Add(New FVIL.Data.CFviPoint(220, 180)) points.Add(New FVIL.Data.CFviPoint(100, 180)) points.Add(New FVIL.Data.CFviPoint(50, 130)) ' 2) 計測実行. Dim rect1 As FVIL.Caliper.CFviCaliperRectangle = FVIL.Caliper.[Function].LongHole(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 ' 描画図形の生成. ' 入力点群. Dim gpoints As System.Collections.Generic.List(Of FVIL.GDI.CFviGdiPoint) = New List(Of FVIL.GDI.CFviGdiPoint)() For index As Integer = 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 gpoint1 As New FVIL.GDI.CFviGdiPoint(rect1.Center) gpoint1.Pen.Color = Color.Red gpoint1.Pen.Width = 4 ' 描画図形の追加. For Each gpoint As FVIL.GDI.CFviGdiPoint In gpoints overlay.Figures.Add(gpoint) Next overlay.Figures.Add(gpoint1) 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.LongHole.png", dstimage) End If End Sub End Class End Namespace |
Exceptions
Exception | Condition |
---|---|
FVIL..::..CFviException | この例外の原因については、上記のエラーコード表をご参照ください。 |