FrmTongsLearn.cs
3.7 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
using OnlineStore.DeviceLibrary;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace OnlineStore.XLRStore
{
public partial class FrmTongsLearn : Form
{
public FrmTongsLearn()
{
InitializeComponent();
boxEquip = StoreManager.XLRStore.boxEquip;
txtScoreThreshold.Text = boxEquip.Config.TongsDetectThreshold.ToString();
}
Bitmap srcBitmap = null;
BoxEquip boxEquip;
string camName = "box_A";
private void btnSelect_Click(object sender, EventArgs e)
{
OpenFileDialog fileDialog = new OpenFileDialog();
fileDialog.InitialDirectory = Application.StartupPath+Common.ConfigAppSettings.GetValue(Common.Setting_Init.ImagePath);
fileDialog.Filter = "图片|*.bmp";
fileDialog.RestoreDirectory = true;
if(fileDialog.ShowDialog()==DialogResult.OK)
{
txtImagePath.Text = System.IO.Path.GetFullPath(fileDialog.FileName);
srcBitmap = new Bitmap(txtImagePath.Text);
picSrc.Image = srcBitmap;
}
}
private void btnAcquire_Click(object sender, EventArgs e)
{
srcBitmap = boxEquip.AcqImage(camName);
picSrc.Image = srcBitmap;
}
private void SideCheckedChanged(object sender, EventArgs e)
{
if(rdoAside.Checked)
{
camName = "box_A";
}
else if(rdoBside.Checked)
{
camName = "box_B";
}
}
private void btnSave_Click(object sender, EventArgs e)
{
boxEquip.Config.TongsDetectThreshold = float.Parse(txtScoreThreshold.Text);
StoreManager.SaveBoxConfig(boxEquip.Config);
}
private void btnMatch_Click(object sender, EventArgs e)
{
if(srcBitmap !=null)
{
float score= boxEquip.match(srcBitmap, out string pn, out Bitmap bitmap);
picResult.Image = bitmap;
updateResult(score);
}
}
private void updateResult(float score)
{
lblResult.Text = score.ToString("f2");
if (score<boxEquip.Config.TongsDetectThreshold)
{
lblResult.BackColor = Color.Red;
}
else
{
lblResult.BackColor = Color.GreenYellow;
}
}
private void btnLearn_Click(object sender, EventArgs e)
{
if (srcBitmap != null)
boxEquip.learn(srcBitmap, Guid.NewGuid().ToString());
}
private void btnSelectPatch_Click(object sender, EventArgs e)
{
FolderBrowserDialog folderDialog = new FolderBrowserDialog();
folderDialog.Description = "请选择需要训练图像的路径";
if (folderDialog.ShowDialog() == DialogResult.OK)
{
txtImagePath.Text = folderDialog.SelectedPath+@"\";
string[] files = System.IO.Directory.GetFiles(txtImagePath.Text);
lblResult.Text = "开始学习...";
System.Threading.Tasks.Task task = System.Threading.Tasks.Task.Factory.StartNew(delegate {
foreach (var item in files)
{
boxEquip.learn(item, Guid.NewGuid().ToString());
}
});
task.Wait();
lblResult.Text = "学习完成";
lblResult.BackColor = Color.AliceBlue;
}
}
}
}