5点を通る四角形の算出
Namespace: FVIL.CaliperAssembly: FVILbasic (in FVILbasic.dll) Version: 3.1.0.0 (3.1.0.17)
Syntax
C# |
---|
public static CFviCaliperRectangle Rectangle( IEnumerable<CFviPoint> points ) |
Visual Basic |
---|
Public Shared Function Rectangle ( points As IEnumerable(Of CFviPoint) ) As CFviCaliperRectangle |
Parameters
- points
- Type: System.Collections.Generic..::..IEnumerable<(Of <(<'CFviPoint>)>)>
5つの点が格納された配列
Return Value
Type: CFviCaliperRectangle5つの点を通る辺を持つ四角形を求めます。
■ 各点の説明
P1 | 四角形の基準となる辺を作る直線Lのための点 |
P2 | 四角形の基準となる辺を作る直線Lのための点 |
P3 | 直線Lと隣り合う辺を作る点 |
P4 | 直線Lと向かい合う辺を作る点 |
P5 | 直線Lと隣り合う辺を作る点 |
■ 戻り値(CFviCaliperRectangle)の各メンバ
Long1 | 長方形の長辺 |
Long2 | 長方形の長辺 |
Short1 | 長方形の短辺 |
Short2 | 長方形の短辺 |
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> /// 5点を通る四角形の算出の測定. /// </summary> /// <remarks> /// FVIL.Caliper.Function.Rectangle(System.Collections.Generic.IList{FVIL.Data.CFviPoint}) /// </remarks> [FvPluginExecute] public void Rectangle_points() { // 1) 5つの点が格納された点列の生成. System.Collections.Generic.List<FVIL.Data.CFviPoint> points = new List<FVIL.Data.CFviPoint>(); points.Add(new FVIL.Data.CFviPoint(210, 50)); points.Add(new FVIL.Data.CFviPoint(230, 70)); points.Add(new FVIL.Data.CFviPoint(80, 90)); points.Add(new FVIL.Data.CFviPoint(100, 210)); points.Add(new FVIL.Data.CFviPoint(140, 190)); // 2) 計測実行. FVIL.Caliper.CFviCaliperRectangle rect1 = FVIL.Caliper.Function.Rectangle(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 gcenter = new FVIL.GDI.CFviGdiPoint(rect1.Center); gcenter.Pen.Color = Color.Red; gcenter.Pen.Width = 4; // 補助線(四角形の各辺) FVIL.Data.CFviLineSegment ls_bottom, ls_top, ls_right, ls_left; { FVIL.Data.CFviLineSegment lineSeg_12 = new FVIL.Data.CFviLineSegment(points[0], points[1]); FVIL.Data.CFviLine line_12 = lineSeg_12.ToCFviLine(); FVIL.Data.CFviLine line_4 = new FVIL.Data.CFviLine(); line_4.a = line_12.a; line_4.b = line_12.b; line_4.c = -line_4.a * points[3].X - line_4.b * points[3].Y; FVIL.Data.CFviLine line_3 = new FVIL.Data.CFviLine(); line_3.a = line_12.b; line_3.b = -line_12.a; line_3.c = -line_3.a * points[2].X - line_3.b * points[2].Y; FVIL.Data.CFviLine line_5 = new FVIL.Data.CFviLine(); line_5.a = line_12.b; line_5.b = -line_12.a; line_5.c = -line_5.a * points[4].X - line_5.b * points[4].Y; FVIL.Data.CFviPoint cp_123 = FVIL.Caliper.Function.CrossPoint(line_12, line_3); FVIL.Data.CFviPoint cp_125 = FVIL.Caliper.Function.CrossPoint(line_12, line_5); FVIL.Data.CFviPoint cp_43 = FVIL.Caliper.Function.CrossPoint(line_4, line_3); FVIL.Data.CFviPoint cp_45 = FVIL.Caliper.Function.CrossPoint(line_4, line_5); ls_bottom = new FVIL.Data.CFviLineSegment(cp_123, cp_125); ls_top = new FVIL.Data.CFviLineSegment(cp_43, cp_45); ls_right = new FVIL.Data.CFviLineSegment(cp_123, cp_43); ls_left = new FVIL.Data.CFviLineSegment(cp_125, cp_45); } System.Collections.Generic.List<FVIL.GDI.CFviGdiLineSegment> glines = new List<FVIL.GDI.CFviGdiLineSegment>(); glines.Add (new FVIL.GDI.CFviGdiLineSegment(ls_bottom)); glines.Add(new FVIL.GDI.CFviGdiLineSegment(ls_left )); glines.Add(new FVIL.GDI.CFviGdiLineSegment(ls_right)); glines.Add(new FVIL.GDI.CFviGdiLineSegment(ls_top)); foreach (FVIL.GDI.CFviGdiLineSegment gline in glines) { gline.Pen.Color = Color.Red; gline.Pen.Style = FVIL.GDI.PenStyle.Dot; gline.Pen.Width = 1; } // 描画図形の追加. foreach (FVIL.GDI.CFviGdiPoint gpoint in gpoints) { overlay.Figures.Add(gpoint); } overlay.Figures.Add(gcenter); foreach (FVIL.GDI.CFviGdiLineSegment gline in glines) { overlay.Figures.Add(gline); } 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.Rectangle_points.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> ''' 5点を通る四角形の算出の測定. ''' </summary> ''' <remarks> ''' FVIL.Caliper.Function.Rectangle(System.Collections.Generic.IList{FVIL.Data.CFviPoint}) ''' </remarks> <FvPluginExecute> _ Public Sub Rectangle_points() ' 1) 5つの点が格納された点列の生成. Dim points As System.Collections.Generic.List(Of FVIL.Data.CFviPoint) = New List(Of FVIL.Data.CFviPoint)() points.Add(New FVIL.Data.CFviPoint(210, 50)) points.Add(New FVIL.Data.CFviPoint(230, 70)) points.Add(New FVIL.Data.CFviPoint(80, 90)) points.Add(New FVIL.Data.CFviPoint(100, 210)) points.Add(New FVIL.Data.CFviPoint(140, 190)) ' 2) 計測実行. Dim rect1 As FVIL.Caliper.CFviCaliperRectangle = FVIL.Caliper.[Function].Rectangle(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 gcenter As New FVIL.GDI.CFviGdiPoint(rect1.Center) gcenter.Pen.Color = Color.Red gcenter.Pen.Width = 4 ' 補助線(四角形の各辺) Dim ls_bottom As FVIL.Data.CFviLineSegment, ls_top As FVIL.Data.CFviLineSegment, ls_right As FVIL.Data.CFviLineSegment, ls_left As FVIL.Data.CFviLineSegment If True Then Dim lineSeg_12 As New FVIL.Data.CFviLineSegment(points(0), points(1)) Dim line_12 As FVIL.Data.CFviLine = lineSeg_12.ToCFviLine() Dim line_4 As New FVIL.Data.CFviLine() line_4.a = line_12.a line_4.b = line_12.b line_4.c = -line_4.a * points(3).X - line_4.b * points(3).Y Dim line_3 As New FVIL.Data.CFviLine() line_3.a = line_12.b line_3.b = -line_12.a line_3.c = -line_3.a * points(2).X - line_3.b * points(2).Y Dim line_5 As New FVIL.Data.CFviLine() line_5.a = line_12.b line_5.b = -line_12.a line_5.c = -line_5.a * points(4).X - line_5.b * points(4).Y Dim cp_123 As FVIL.Data.CFviPoint = FVIL.Caliper.[Function].CrossPoint(line_12, line_3) Dim cp_125 As FVIL.Data.CFviPoint = FVIL.Caliper.[Function].CrossPoint(line_12, line_5) Dim cp_43 As FVIL.Data.CFviPoint = FVIL.Caliper.[Function].CrossPoint(line_4, line_3) Dim cp_45 As FVIL.Data.CFviPoint = FVIL.Caliper.[Function].CrossPoint(line_4, line_5) ls_bottom = New FVIL.Data.CFviLineSegment(cp_123, cp_125) ls_top = New FVIL.Data.CFviLineSegment(cp_43, cp_45) ls_right = New FVIL.Data.CFviLineSegment(cp_123, cp_43) ls_left = New FVIL.Data.CFviLineSegment(cp_125, cp_45) End If Dim glines As System.Collections.Generic.List(Of FVIL.GDI.CFviGdiLineSegment) = New List(Of FVIL.GDI.CFviGdiLineSegment)() glines.Add(New FVIL.GDI.CFviGdiLineSegment(ls_bottom)) glines.Add(New FVIL.GDI.CFviGdiLineSegment(ls_left)) glines.Add(New FVIL.GDI.CFviGdiLineSegment(ls_right)) glines.Add(New FVIL.GDI.CFviGdiLineSegment(ls_top)) For Each gline As FVIL.GDI.CFviGdiLineSegment In glines gline.Pen.Color = Color.Red gline.Pen.Style = FVIL.GDI.PenStyle.Dot gline.Pen.Width = 1 Next ' 描画図形の追加. For Each gpoint As FVIL.GDI.CFviGdiPoint In gpoints overlay.Figures.Add(gpoint) Next overlay.Figures.Add(gcenter) For Each gline As FVIL.GDI.CFviGdiLineSegment In glines overlay.Figures.Add(gline) Next 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.Rectangle_points.png", dstimage) End If End Sub End Class End Namespace |
Exceptions
Exception | Condition |
---|---|
FVIL..::..CFviException | この例外の原因については、上記のエラーコード表をご参照ください。 |