AoiRgbControl.cs
4.5 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
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 Asa.Theme;
namespace AccAOI.control
{
public partial class AoiRgbControl : ABaseControl
{
public AoiRgbControl()
{
InitializeComponent();
}
private AoiMethodRgb methodRgb = null;
public override void ShowAoiInfo()
{
if (this.AoiInfo is AoiMethodRgb)
{
methodRgb = (AoiMethodRgb)AoiInfo;
//txtMinR.Text = methodRgb.minR.ToString();
//txtMaxR.Text = methodRgb.maxR.ToString();
//txtMinG.Text = methodRgb.minG.ToString();
// txtMaxG.Text = methodRgb.maxG.ToString();
// txtMaxB.Text = methodRgb.maxB.ToString();
// txtMinB.Text = methodRgb.minB.ToString();
SetTbValue(tbMinR, methodRgb.minR);
SetTbValue(tbMaxR, methodRgb.maxR);
SetTbValue(tbMinG, methodRgb.minG);
SetTbValue(tbMaxG, methodRgb.maxG);
SetTbValue(tbMaxB, methodRgb.maxB);
SetTbValue(tbMinB, methodRgb.minB);
txtminRate.Text = methodRgb.minRate.ToString();
txtmaxRate.Text = methodRgb.maxRate.ToString();
}
}
public override AoiMethod GetAoiInfo()
{
if (this.AoiInfo is AoiMethodRgb)
{
methodRgb = (AoiMethodRgb)AoiInfo;
methodRgb.minR = FormUtil.GetIntValue(txtMinR);
methodRgb.maxR = FormUtil.GetIntValue(txtMaxR);
methodRgb.minG = FormUtil.GetIntValue(txtMinG);
methodRgb.maxG = FormUtil.GetIntValue(txtMaxG);
methodRgb.maxB = FormUtil.GetIntValue(txtMaxB);
methodRgb.minB = FormUtil.GetIntValue(txtMinB);
SetTbValue(tbMinR, methodRgb.minR);
SetTbValue(tbMaxR, methodRgb.maxR);
SetTbValue(tbMinG, methodRgb.minG);
SetTbValue(tbMaxG, methodRgb.maxG);
SetTbValue(tbMaxB, methodRgb.maxB);
SetTbValue(tbMinB, methodRgb.minB);
methodRgb.minRate = FormUtil.GetIntValue(txtminRate);
methodRgb.maxRate = FormUtil.GetIntValue(txtmaxRate);
if (currPath != null)
{
methodRgb.RoiPath = currPath;
}
AoiInfo = methodRgb;
}
return AoiInfo;
}
public override void UpdateImage()
{
if (BaseImage == null)
{
return;
}
GetAoiInfo();
Image cutImg = null;
Image dstCutImg = null;
float rate = methodRgb.GetRate(BaseImage, out cutImg, out dstCutImg);
txtRate.Text = rate.ToString();
this.aoiImage.Image = cutImg;
}
private void btnUpdate_Click(object sender, EventArgs e)
{
UpdateImage();
}
private void txtMinR_TextChanged(object sender, EventArgs e)
{
UpdateImage();
}
private void tbMinR_ValueChanged(object sender, EventArgs e)
{
SetText(txtMinR, tbMinR.Value);
}
private void tbMaxR_ValueChanged(object sender, EventArgs e)
{
SetText(txtMaxR, tbMaxR.Value);
}
private void tbMinG_ValueChanged(object sender, EventArgs e)
{
SetText(txtMinG, tbMinG.Value);
}
private void tbMaxG_ValueChanged(object sender, EventArgs e)
{
SetText(txtMaxG, tbMaxG.Value);
}
private void tbMinB_ValueChanged(object sender, EventArgs e)
{
SetText(txtMinB, tbMinB.Value);
}
private void tbMaxB_ValueChanged(object sender, EventArgs e)
{
SetText(txtMaxB, tbMaxB.Value);
}
private void SetText(FlatText text, int value)
{
if (text.Text.ToString().Equals(value.ToString()))
{
return;
}
text.Text = value.ToString();
}
private void SetTbValue(TrackBar tb, int value)
{
if (tb.Value.Equals(value.ToString()))
{
return;
}
tb.Value = value;
}
}
}