WIL説明書(.NET)  3.1.0
エッジ検出

1次元エッジ検出によりエッジ点群を抽出し、近似計算で直線と円に変換し、距離を計測する例です。


プレビュー:

Step2.Edge.Preview.1.png
エッジ検出結果
Step2.Edge.Preview.2.png
直線近似と円近似
Step2.Edge.Preview.3.png
点と直線の距離

ワークフロー:

Step2.Edge.Component.1.png
Step2.Edge.Component.2.png
Step2.Edge.Component.3.png

ソースコード:
1 Option Strict Off
2 Option Explicit On
3 
4 Imports fvalgcli
5 Imports System
6 Imports System.Collections.Generic
7 Imports System.ComponentModel
8 Imports System.Drawing
9 Imports System.Globalization
10 Imports System.Reflection
11 Imports System.Runtime.Serialization
12 Imports System.Security.Permissions
13 Imports System.Text
14 Imports System.Windows.Forms
15 
16 Namespace FVIL.Parser
17 
18  <System.SerializableAttribute(), _
19  System.ComponentModel.TypeConverterAttribute(GetType(System.ComponentModel.ExpandableObjectConverter))> _
20  Partial Public Class ParserNodeUser
21  Inherits FVIL.Parser.ParserNodeUnit
22 
23  Public Overrides Sub Execute(ByVal sender As Object, ByVal e As System.EventArgs)
24  Dim target1_out0 As FVIL.Data.CFviImage = New FVIL.Data.CFviImage(256, 240, FVIL.ImageType.UC8, 1)
25  Dim target2_out0 As FVIL.Edge.CFviEdgeResult = New FVIL.Edge.CFviEdgeResult
26  Dim target3_out0 As FVIL.Edge.CFviEdgeResult = New FVIL.Edge.CFviEdgeResult
27  Dim target4_out0 As FVIL.Edge.CFviEdgeResult = New FVIL.Edge.CFviEdgeResult
28  Dim target5_out0 As FVIL.Data.CFviLine = _
29  New FVIL.Data.CFviLine(1, 0.2532541721230761, -84.620416859384008)
30  Dim target6_out0 As FVIL.Data.CFviLine = _
31  New FVIL.Data.CFviLine(1, 0.24762089172587431, -249.30331288145166)
32  Dim target7_out0 As FVIL.Data.CFviCircle = _
33  New FVIL.Data.CFviCircle(137.67168616358185, 115.42045679202695, 21.639257493825262)
34  Dim target8_out0 As FVIL.Data.CFviCircle = _
35  New FVIL.Data.CFviCircle(137.67168616358185, 115.42045679202695, 21.639257493825262)
36  Dim target8_out1 As FVIL.Data.CFviPoint = _
37  New FVIL.Data.CFviPoint(137.67168616358185, 115.42045679202695)
38  Dim target8_out2 As Double = 21.639257493825262
39  Dim target8_out3 As Double = 137.67168616358185
40  Dim target8_out4 As Double = 115.42045679202695
41  Dim target9_out0 As Double = 79.763799312042011
42  Dim target10_out0 As Double = 80.616337793131365
43 
44  '画像#1
45  target1_out0 = CType(ParserInfo,FVIL.Parser.IDataObject(Of FVIL.Data.CFviImage)).Infos(0).Data
46 
47  '1次元エッジ検出 (矩形)#1
48  Dim target2 As FVIL.Edge.CFviBoxEdge = New FVIL.Edge.CFviBoxEdge
49  target2.SrcImages(0) = target1_out0
50  target2.Result = target2_out0
51  target2.MaxThreshold = 75
52  target2.Around = 2
53  target2.Foot = 1
54  target2.Len = 0
55  target2.EdgeDirection = FVIL.Edge.Direction.BrightToDark
56  target2.LineWidth = 0
57  target2.Threshold = -1
58  target2.ScanDirection = FVIL.ScanDirection.Right
59  target2.Number = 12
60  target2.Box = New FVIL.Data.CFviRectangle( _
61  60, 37.288247321445432, 90.92518839821922, 148.83211150513876, _
62  14.403819866037779, 0, 8.7117526785545678)
63  target2.Execute
64 
65  '1次元エッジ検出 (矩形)#2
66  Dim target3 As FVIL.Edge.CFviBoxEdge = New FVIL.Edge.CFviBoxEdge
67  target3.SrcImages(0) = target1_out0
68  target3.Result = target3_out0
69  target3.MaxThreshold = 75
70  target3.Around = 2
71  target3.Foot = 1
72  target3.Len = 0
73  target3.EdgeDirection = FVIL.Edge.Direction.BrightToDark
74  target3.LineWidth = 0
75  target3.Threshold = -1
76  target3.ScanDirection = FVIL.ScanDirection.Left
77  target3.Number = 12
78  target3.Box = New FVIL.Data.CFviRectangle( _
79  212, 76.920616462741449, 243.12403515431902, 191.80449871795281, _
80  15.390940092953223, 0, 11.079383537258551)
81  target3.Execute
82 
83  '1次元エッジ検出 (放射状)#1
84  Dim target4 As FVIL.Edge.CFviRadialEdge = New FVIL.Edge.CFviRadialEdge
85  target4.SrcImages(0) = target1_out0
86  target4.Result = target4_out0
87  target4.Threshold = 25
88  target4.ScanDirection = FVIL.Edge.ScanDirection.Inward
89  target4.Number = 12
90  target4.Radial = New FVIL.Data.CFviCircle(138, 116, 33.498769231142433)
91  target4.Execute
92 
93  '直線近似#1
94  target5_out0 = FVIL.CG.[Function].FitLine( _
95  New FVIL.DPNT_T_ARRAY(New FVIL.DPNT_T_ARRAY(target2_out0)), FVIL.CG.FitMode.MESTIMATOR, 3.291)
96 
97  '直線近似#2
98  target6_out0 = FVIL.CG.[Function].FitLine( _
99  New FVIL.DPNT_T_ARRAY(New FVIL.DPNT_T_ARRAY(target3_out0)), FVIL.CG.FitMode.MESTIMATOR, 3.291)
100 
101  '円近似#1
102  target7_out0 = FVIL.CG.[Function].FitCircle( _
103  New FVIL.DPNT_T_ARRAY(New FVIL.DPNT_T_ARRAY(target4_out0)), FVIL.CG.FitMode.MESTIMATOR, 3.291)
104 
105  '真円#1
106  target8_out0 = target7_out0
107  target8_out1 = target8_out0.Center
108  target8_out2 = target8_out0.Radius
109  target8_out3 = target8_out0.X
110  target8_out4 = target8_out0.Y
111 
112  '距離(点と直線)#1
113  target9_out0 = FVIL.Caliper.[Function].Distance(target8_out1, target5_out0)
114 
115  '距離(点と直線)#2
116  target10_out0 = FVIL.Caliper.[Function].Distance(target8_out1, target6_out0)
117  End Sub
118  End Class
119 End Namespace

Documentation copyright © 2008 FAST Corporation. [B-001864]
Generated on 2024年10月10日(木) 10時07分53秒 for WIL説明書(.NET) by doxygen 1.8.11