UsrCamera.cs
4.3 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
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using BLL;
using CameraVisionLib.Model;
using DocumentFormat.OpenXml.Spreadsheet;
using Model;
namespace SmartScan
{
public partial class UsrCamera : UserControl, ISetMenu
{
private Bitmap bmp = null;
public UsrCamera()
{
InitializeComponent();
Asa.FaceControl.Language.SetLanguage(this);
BtnCameraImage.Enabled = Camera.IsConnected();
}
public Asa.FaceControl.FacePanel GetPanel()
{
return facePanel1;
}
public void Save() { }
private void BtnOpenLight_Click(object sender, EventArgs e)
{
BLLCommon.lightSource.TurnOn();
}
private void BtnCloseLight_Click(object sender, EventArgs e)
{
BLLCommon.lightSource.TurnOff();
}
List<BarcodeInfo> barcodeInfos;
private void BtnCameraImage_Click(object sender, EventArgs e)
{
Bitmap[] result = Camera.CaptureAndGetCode(out barcodeInfos);
if (result.Length == 0) return;
bmp = result[0];
LstCode.Items.Clear();
PicShow.CodeCenterClear();
PicShow.Image = bmp;
}
private void BtnLocalImage_Click(object sender, EventArgs e)
{
using OpenFileDialog dlg = new() { Filter = "Image Files|*.jpg;*.jpeg;*.png;*.bmp;*.gif|All Files|*.*" };
if (dlg.ShowDialog() != DialogResult.OK) return;
bmp = ObjConversion.ReadImageFile(dlg.FileName);
LstCode.Items.Clear();
PicShow.CodeCenterClear();
PicShow.Image = bmp;
}
private void BtnScanCode_Click(object sender, EventArgs e)
{
if (bmp == null) return;
List<CameraVisionLib.Model.BarcodeInfo> info = null;
if (Camera.useIDCamera)
{
info = barcodeInfos.ToList();
}
else
info = Camera.GetBarCode(bmp);
LstCode.Items.Clear();
PicShow.CodeCenterClear();
string[] arr = new string[info.Count];
PointF[] lst = new PointF[info.Count];
for (int i = 0; i < info.Count; i++)
{
arr[i] = string.Format("({0}) ", i + 1) + info[i].Text.Replace("\r\n", "");
lst[i] = info[i].Center;
}
List<string> ocrs = new List<string>();
int startidx = info.Count + 1;
if (Config.Func_EnabledOCR)
{
//保存需要识别ocr的区域
bmp?.Save(@"ocrt.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
string[] regOcrCodes = PaddleOCRHelper.StartTest("..\\ocrt.jpg").Split(';');
foreach (var ocr in regOcrCodes)
{
if (string.IsNullOrEmpty(ocr)) continue;
ocrs.Add($"({startidx}) {ocr} <OCR>");
startidx++;
}
}
if (info.Count == 0)
{
string text = Asa.FaceControl.Language.Dialog(Model.LanguageDialogKey.CODE_COUNT);
new Asa.FaceControl.FaceMessageBox("", text, MessageBoxButtons.OK).ShowDialog();
return;
}
LstCode.Items.AddRange(arr);
if (ocrs.Count > 0)
LstCode.Items.AddRange(ocrs.ToArray());
PicShow.AddCodeCenter(lst);
}
private void BtnSaveImage_Click(object sender, EventArgs e)
{
SaveFileDialog dlg = new() { Filter = "JPEG图片|*.jpg|BMP图片|*.bmp|PNG图片|*.png" };
if (dlg.ShowDialog() != DialogResult.OK) return;
switch (dlg.FilterIndex)
{
case 0: bmp.Save(dlg.FileName, System.Drawing.Imaging.ImageFormat.Jpeg); break;
case 1: bmp.Save(dlg.FileName, System.Drawing.Imaging.ImageFormat.Bmp); break;
case 2: bmp.Save(dlg.FileName, System.Drawing.Imaging.ImageFormat.Png); break;
}
string text = Asa.FaceControl.Language.Dialog(LanguageDialogKey.SAVE_SUCCEED);
new Asa.FaceControl.FaceMessageBox("", text, MessageBoxButtons.OK).ShowDialog();
}
}
}