FrmLabelEdit.cs
5.9 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
using CodeLibrary;
using DL.CV;
using OnlineStore.Common;
using OnlineStore.DeviceLibrary;
using System;
using System.CodeDom;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using JsonHelper = OnlineStore.Common.JsonHelper;
namespace OnlineStore.XLRStore
{
public partial class FrmLabelEdit : Form
{
public FrmLabelEdit()
{
InitializeComponent();
CheckForIllegalCrossThreadCalls = false;
comboBox1.Items.Add($"A侧相机");
comboBox1.Items.Add($"B侧相机");
if (comboBox1.Items.Count > 0)
comboBox1.SelectedIndex = 0;
}
private void btnOpenImg_Click(object sender, EventArgs e)
{
OpenFileDialog openfile = new OpenFileDialog();
//初始显示文件目录
//openfile.InitialDirectory = @"";
openfile.Title = "请选择图片";
//过滤文件类型
openfile.Filter = "图像|*.bmp";
if (DialogResult.OK == openfile.ShowDialog())
{
//将选择的文件的全路径赋值给文本框
//textBox1.Text = openfile.FileName;
}
}
string filename = "";
List<CodeInfo> codeinfo = null;
private void btnAcquire_Click(object sender, EventArgs e)
{
Task.Factory.StartNew(delegate
{
if (comboBox1.SelectedIndex == 0)
{
(codeinfo, filename) = CodeManager.CameraScan(new List<string> { StoreManager.XLRStore.inputEquip.Config.CameraNameList_FeedA });
}
else if (comboBox1.SelectedIndex == 1)
{
(codeinfo, filename) = CodeManager.CameraScan(new List<string> { StoreManager.XLRStore.inputEquip.Config.CameraNameList_FeedB });
}
if (string.IsNullOrEmpty(filename)) return;
pictureBox1.Image = new Bitmap(filename);
});
}
LabelParam labelparam = new LabelParam();
private void btnCalculate_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(filename)) return;
labelparam.BitmapFilename = filename;
labelparam.LabelContent = new LabelContent();
labelparam.LabelContent.codeInfos = codeinfo;
labelparam.LabelContent.PN = textBox2.Text;
labelparam.TrayCenterInImg_X = int.Parse(txtX.Text);
labelparam.TrayCenterInImg_Y = int.Parse(txtY.Text);
labelparam.LabelInImgAngle = int.Parse(txtLabel_R_Angle_Diff.Text);
labelparam.RelativeAngle = int.Parse(txtRelativeAngle.Text);
(string resFile, int codeAngle, int labelAngle, int needRound) res = LabelManager.CalcLabelAngle(labelparam, true);
lblCodePos.Text = $"二维码角度:{res.codeAngle}°";
lblAngle.Text = $"旋转角度:{res.needRound}°";
lblLabelAngle.Text = $"标签角度:{res.labelAngle}°";
pictureBox2.Image = new Bitmap(res.resFile);
textBox1.Text = JsonHelper.SerializeObject(codeinfo);
}
private void load(int side = 0)
{
if (side == 0)
{
txtX.Text = ConfigAppSettings.GetValue(Setting_Init.TrayCenterInImg_X_CamA,"2600");
txtY.Text = ConfigAppSettings.GetValue(Setting_Init.TrayCenterInImg_Y_CamA,"1700");
txtLabel_R_Angle_Diff.Text = ConfigAppSettings.GetValue(Setting_Init.LabelInImgAngle_CamA,"190");
txtRelativeAngle.Text = ConfigAppSettings.GetValue(Setting_Init.RelativeAngle_CamA,"150");
}
else if (side == 1)
{
txtX.Text = ConfigAppSettings.GetValue(Setting_Init.TrayCenterInImg_X_CamB,"2600");
txtY.Text = ConfigAppSettings.GetValue(Setting_Init.TrayCenterInImg_Y_CamB,"1700");
txtLabel_R_Angle_Diff.Text = ConfigAppSettings.GetValue(Setting_Init.LabelInImgAngle_CamB,"190");
txtRelativeAngle.Text = ConfigAppSettings.GetValue(Setting_Init.RelativeAngle_CamB,"150");
}
else
return;
//labelparam.TrayCenterInImg_X = int.Parse(txtX.Text);
//labelparam.TrayCenterInImg_Y = int.Parse(txtY.Text);
//labelparam.LabelInImgAngle = int.Parse(txtLabel_R_Angle_Diff.Text);
//labelparam.RelativeAngle = int.Parse(txtRelativeAngle.Text);
}
private void save(int side = 0)
{
if (side == 0)
{
ConfigAppSettings.SaveValue(Setting_Init.TrayCenterInImg_X_CamA, txtX.Text);
ConfigAppSettings.SaveValue(Setting_Init.TrayCenterInImg_Y_CamA, txtY.Text);
ConfigAppSettings.SaveValue(Setting_Init.LabelInImgAngle_CamA, txtLabel_R_Angle_Diff.Text);
ConfigAppSettings.SaveValue(Setting_Init.RelativeAngle_CamA, txtRelativeAngle.Text);
}
else if (side == 1)
{
ConfigAppSettings.SaveValue(Setting_Init.TrayCenterInImg_X_CamB, txtX.Text);
ConfigAppSettings.SaveValue(Setting_Init.TrayCenterInImg_Y_CamB, txtY.Text);
ConfigAppSettings.SaveValue(Setting_Init.LabelInImgAngle_CamB, txtLabel_R_Angle_Diff.Text);
ConfigAppSettings.SaveValue(Setting_Init.RelativeAngle_CamB, txtRelativeAngle.Text);
}
else
return;
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
load(comboBox1.SelectedIndex);
}
private void button1_Click(object sender, EventArgs e)
{
save(comboBox1.SelectedIndex);
}
}
}