AoiBlobControl.cs
3.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using AOI;
using OpenCvSharp.Blob;
namespace AccAOI.control
{
public partial class AoiBlobControl : ABaseControl
{
public AoiBlobControl()
{
InitializeComponent();
}
private void trackBarThresh_ValueChanged(object sender, EventArgs e)
{
int value = trackBarThresh.Value;
lblthresh.Text = value.ToString();
UpdateImage();
}
private AoiBlobMethod MethodBlob = null;
public override void ShowAoiInfo()
{
if(this.AoiInfo is AoiBlobMethod)
{
MethodBlob = (AoiBlobMethod)AoiInfo;
if (MethodBlob.thresh < 0)
{
trackBarThresh.Value = 0;
}
else
{
trackBarThresh.Value = MethodBlob.thresh;
}
chkwhiteOnBlack.Checked = MethodBlob.whiteOnBlack;
txtmaxArea.Text = MethodBlob.maxArea.ToString();
txtminArea.Text = MethodBlob.minArea.ToString();
txtmaxNum.Text = MethodBlob.maxNum.ToString();
txtminNum.Text = MethodBlob.minNum.ToString();
}
}
public override AoiMethod GetAoiInfo()
{
if (this.AoiInfo is AoiBlobMethod)
{
MethodBlob = (AoiBlobMethod)AoiInfo;
if (trackBarThresh.Value.Equals(0))
{
MethodBlob.thresh = -1;
}
else
{
MethodBlob.thresh= trackBarThresh.Value;
}
MethodBlob.whiteOnBlack= chkwhiteOnBlack.Checked ;
MethodBlob.maxArea = FormUtil.GetIntValue(txtmaxArea);
MethodBlob.minArea = FormUtil.GetIntValue(txtminArea);
MethodBlob.maxNum = FormUtil.GetIntValue(txtmaxNum);
MethodBlob.minNum = FormUtil.GetIntValue(txtminNum);
if (currPath != null)
{
MethodBlob.RoiPath = currPath;
}
AoiInfo = MethodBlob;
}
return AoiInfo;
}
public override void UpdateImage()
{
if (BaseImage == null)
{
return;
}
GetAoiInfo();
Image outImage = null;
List<CvBlob> list = new List<CvBlob>();
float result = MethodBlob.GetBlobNum(BaseImage, out outImage, out list);
txtNumResult.Text = result.ToString();
this.aoiImage.Image = outImage;
}
private void btnUpdate_Click(object sender, EventArgs e)
{
UpdateImage();
}
private void chkwhiteOnBlack_CheckedChanged(object sender)
{
UpdateImage();
}
}
}