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

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