WIL説明書(.NET)  3.1.0
2値ブローブ解析

濃淡画像を2値化して、2値ブローブ解析し、2つのブローブの重心間の距離を計測する例です。


プレビュー:

Step2.Blob.Preview.2.png
2値ブローブ解析結果
Step2.Blob.Preview.3.png
2点間の距離

ワークフロー:

Step2.Blob.Component.1.png
Step2.Blob.Component.2.png
Step2.Blob.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(320, 240, FVIL.ImageType.UC8, 1);
22  FVIL.Data.CFviImage target2_out0 = new FVIL.Data.CFviImage(320, 240, FVIL.ImageType.BIN, 1);
23  FVIL.Blob.CFviBlobList target3_out0 = new FVIL.Blob.CFviBlobList();
24  FVIL.Blob.CFviBlobData target4_out0 = new FVIL.Blob.CFviBlobData();
25  FVIL.Data.CFviPoint target4_out1 = new FVIL.Data.CFviPoint(59.94997843898232, 72.105648986632175);
26  int target4_out2 = 82;
27  int target4_out3 = 94;
28  FVIL.Blob.CFviBlobData target5_out0 = new FVIL.Blob.CFviBlobData();
29  FVIL.Data.CFviPoint target5_out1 = new FVIL.Data.CFviPoint(202.01071237279058, 181.78628816282807);
30  int target5_out2 = 114;
31  int target5_out3 = 55;
32  double target6_out0 = 179.47449605977764;
33 
34  // 画像#1
35  target1_out0 = ((FVIL.Parser.IDataObject<FVIL.Data.CFviImage>)(ParserInfo)).Infos[0].Data;
36 
37  // 2値化#1
38  FVIL.Conversion.CFviBinarizeDiscrimination target2 = new FVIL.Conversion.CFviBinarizeDiscrimination();
39  target2.SrcImages[0] = target1_out0;
40  target2.DstImages[0] = target2_out0;
41  target2.Execute();
42 
43  // 2値ブローブ解析#1
44  FVIL.Blob.CFviBlob target3 = new FVIL.Blob.CFviBlob();
45  target3.SrcImages[0] = target2_out0;
46  target3.ContinueOption = FVIL.Blob.ContinueOption.None;
47  target3.OriginMode = FVIL.OriginMode.Image;
48  target3.Offset = new System.Drawing.Point(0, 0);
49  target3.Param.KeepResultsAfterOverflow = false;
50  target3.Param.PrecalcFeatures = FVIL.Blob.FeatureFlag.None;
51  target3.Param.Neighborhood = FVIL.Blob.Neighborhood.Four;
52  target3.Param.ColorMode = FVIL.Blob.ObjectColor.WhiteFG_BlackBG;
53  target3.Param.MaxRows = 0;
54  target3.Param.MaxBlobs = 0u;
55  target3.Param.MaxRuns = 0u;
56  target3.Execute();
57  System.Collections.Generic.List<FVIL.Blob.CFviBlobFilterRange> target3_filters =
58  new System.Collections.Generic.List<FVIL.Blob.CFviBlobFilterRange>();
59  target3_filters.Add(new FVIL.Blob.CFviBlobFilterRange(FVIL.Blob.FeatureType.RECT1AREA, 1000, 4294967295));
60  target3_out0 = target3.Result.GetBlobList(target3_filters);
61 
62  // ブローブデータ#1
63  target4_out0.CopyFrom(target3_out0[1]);
64  target4_out1 = target4_out0.Center;
65  target4_out2 = target4_out0.Xdiff;
66  target4_out3 = target4_out0.Ydiff;
67 
68  // ブローブデータ#2
69  target5_out0.CopyFrom(target3_out0[4]);
70  target5_out1 = target5_out0.Center;
71  target5_out2 = target5_out0.Xdiff;
72  target5_out3 = target5_out0.Ydiff;
73 
74  // 距離(2点間)#1
75  FVIL.Data.CFviPoint target6_points = new FVIL.Data.CFviPoint[2];
76  target6_points.Add(target5_out1);
77  target6_points.Add(target4_out1);
78  target6_out0 = FVIL.Caliper.Function.Distance(target6_points);
79  }
80  }
81 }

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