Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
孙克
/
GeneralClassLibrary
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit 2235d361
由
LN
编写于
2021-11-12 09:55:35 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
增加服务器扫码测试功能
1 个父辈
bfc963e0
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
210 行增加
和
32 行删除
CodeLibraryProject/CodeLibrary/CodeLibrary.csproj
CodeLibraryProject/CodeLibrary/FrmCodeDecode.Designer.cs
CodeLibraryProject/CodeLibrary/FrmCodeDecode.cs
CodeLibraryProject/CodeLibrary/HDCodeHelper.cs
CodeLibraryProject/CodeLibrary/HDRemoteDecodeHelper.cs
CodeLibraryProject/CodeTest/Program.cs
CodeLibraryProject/CodeLibrary/CodeLibrary.csproj
查看文件 @
2235d36
...
@@ -92,6 +92,7 @@
...
@@ -92,6 +92,7 @@
<Compile Include="ImageHelper.cs" />
<Compile Include="ImageHelper.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="CodeResourceControl.cs" />
<Compile Include="CodeResourceControl.cs" />
<Compile Include="HDRemoteDecodeHelper.cs" />
<Compile Include="ZXingCodeHelper.cs" />
<Compile Include="ZXingCodeHelper.cs" />
</ItemGroup>
</ItemGroup>
<ItemGroup>
<ItemGroup>
...
...
CodeLibraryProject/CodeLibrary/FrmCodeDecode.Designer.cs
查看文件 @
2235d36
...
@@ -53,7 +53,7 @@
...
@@ -53,7 +53,7 @@
this
.
btnScanTest
=
new
System
.
Windows
.
Forms
.
Button
();
this
.
btnScanTest
=
new
System
.
Windows
.
Forms
.
Button
();
this
.
chbEyem
=
new
System
.
Windows
.
Forms
.
CheckBox
();
this
.
chbEyem
=
new
System
.
Windows
.
Forms
.
CheckBox
();
this
.
label5
=
new
System
.
Windows
.
Forms
.
Label
();
this
.
label5
=
new
System
.
Windows
.
Forms
.
Label
();
this
.
b
utton1
=
new
System
.
Windows
.
Forms
.
Button
();
this
.
b
tnServerTest
=
new
System
.
Windows
.
Forms
.
Button
();
((
System
.
ComponentModel
.
ISupportInitialize
)(
this
.
pictureBox1
)).
BeginInit
();
((
System
.
ComponentModel
.
ISupportInitialize
)(
this
.
pictureBox1
)).
BeginInit
();
this
.
SuspendLayout
();
this
.
SuspendLayout
();
//
//
...
@@ -339,24 +339,23 @@
...
@@ -339,24 +339,23 @@
this
.
label5
.
Size
=
new
System
.
Drawing
.
Size
(
0
,
12
);
this
.
label5
.
Size
=
new
System
.
Drawing
.
Size
(
0
,
12
);
this
.
label5
.
TabIndex
=
32
;
this
.
label5
.
TabIndex
=
32
;
//
//
// b
utton1
// b
tnServerTest
//
//
this
.
button1
.
Font
=
new
System
.
Drawing
.
Font
(
"微软雅黑"
,
9F
,
System
.
Drawing
.
FontStyle
.
Regular
,
System
.
Drawing
.
GraphicsUnit
.
Point
,
((
byte
)(
134
)));
this
.
btnServerTest
.
Font
=
new
System
.
Drawing
.
Font
(
"微软雅黑"
,
9F
,
System
.
Drawing
.
FontStyle
.
Regular
,
System
.
Drawing
.
GraphicsUnit
.
Point
,
((
byte
)(
134
)));
this
.
button1
.
Location
=
new
System
.
Drawing
.
Point
(
1069
,
49
);
this
.
btnServerTest
.
Location
=
new
System
.
Drawing
.
Point
(
1069
,
49
);
this
.
button1
.
Name
=
"button1"
;
this
.
btnServerTest
.
Name
=
"btnServerTest"
;
this
.
button1
.
Size
=
new
System
.
Drawing
.
Size
(
167
,
33
);
this
.
btnServerTest
.
Size
=
new
System
.
Drawing
.
Size
(
167
,
33
);
this
.
button1
.
TabIndex
=
33
;
this
.
btnServerTest
.
TabIndex
=
33
;
this
.
button1
.
Text
=
"模型解码测试"
;
this
.
btnServerTest
.
Text
=
"服务器扫码测试"
;
this
.
button1
.
UseVisualStyleBackColor
=
true
;
this
.
btnServerTest
.
UseVisualStyleBackColor
=
true
;
this
.
button1
.
Visible
=
false
;
this
.
btnServerTest
.
Click
+=
new
System
.
EventHandler
(
this
.
btnServerTest_Click
);
this
.
button1
.
Click
+=
new
System
.
EventHandler
(
this
.
button1_Click_1
);
//
//
// FrmCodeDecode
// FrmCodeDecode
//
//
this
.
AutoScaleDimensions
=
new
System
.
Drawing
.
SizeF
(
6F
,
12F
);
this
.
AutoScaleDimensions
=
new
System
.
Drawing
.
SizeF
(
6F
,
12F
);
this
.
AutoScaleMode
=
System
.
Windows
.
Forms
.
AutoScaleMode
.
Font
;
this
.
AutoScaleMode
=
System
.
Windows
.
Forms
.
AutoScaleMode
.
Font
;
this
.
ClientSize
=
new
System
.
Drawing
.
Size
(
1375
,
729
);
this
.
ClientSize
=
new
System
.
Drawing
.
Size
(
1375
,
729
);
this
.
Controls
.
Add
(
this
.
b
utton1
);
this
.
Controls
.
Add
(
this
.
b
tnServerTest
);
this
.
Controls
.
Add
(
this
.
label5
);
this
.
Controls
.
Add
(
this
.
label5
);
this
.
Controls
.
Add
(
this
.
chbEyem
);
this
.
Controls
.
Add
(
this
.
chbEyem
);
this
.
Controls
.
Add
(
this
.
btnScanTest
);
this
.
Controls
.
Add
(
this
.
btnScanTest
);
...
@@ -420,7 +419,7 @@
...
@@ -420,7 +419,7 @@
private
System
.
Windows
.
Forms
.
Button
btnScanTest
;
private
System
.
Windows
.
Forms
.
Button
btnScanTest
;
private
System
.
Windows
.
Forms
.
CheckBox
chbEyem
;
private
System
.
Windows
.
Forms
.
CheckBox
chbEyem
;
private
System
.
Windows
.
Forms
.
Label
label5
;
private
System
.
Windows
.
Forms
.
Label
label5
;
private
System
.
Windows
.
Forms
.
Button
b
utton1
;
private
System
.
Windows
.
Forms
.
Button
b
tnServerTest
;
}
}
}
}
CodeLibraryProject/CodeLibrary/FrmCodeDecode.cs
查看文件 @
2235d36
...
@@ -25,12 +25,15 @@ namespace CodeLibrary
...
@@ -25,12 +25,15 @@ namespace CodeLibrary
// private List<string> baslerNameList = new List<string>();
// private List<string> baslerNameList = new List<string>();
// private List<string> hikNameList = new List<string>();
// private List<string> hikNameList = new List<string>();
public
FrmCodeDecode
(
bool
eyemSel
=
true
,
bool
eyemShow
=
true
)
public
FrmCodeDecode
(
bool
eyemSel
=
true
,
bool
eyemShow
=
true
,
bool
serverTest
=
false
)
{
{
InitializeComponent
();
InitializeComponent
();
chbEyem
.
Checked
=
eyemSel
;
chbEyem
.
Checked
=
eyemSel
;
chbEyem
.
Visible
=
eyemShow
;
chbEyem
.
Visible
=
eyemShow
;
btnScanTest
.
Visible
=
eyemShow
;
btnScanTest
.
Visible
=
eyemShow
;
btnServerTest
.
Visible
=
serverTest
;
}
}
private
string
selCamera
=
CodeResourceControl
.
GetString
(
CodeResourceControl
.
selCamera
,
"请先选择相机"
);
private
string
selCamera
=
CodeResourceControl
.
GetString
(
CodeResourceControl
.
selCamera
,
"请先选择相机"
);
private
string
selImage
=
CodeResourceControl
.
GetString
(
CodeResourceControl
.
selImage
,
"请先选择图片"
);
private
string
selImage
=
CodeResourceControl
.
GetString
(
CodeResourceControl
.
selImage
,
"请先选择图片"
);
...
@@ -529,24 +532,40 @@ namespace CodeLibrary
...
@@ -529,24 +532,40 @@ namespace CodeLibrary
}
}
}
}
}
}
private
void
button1_Click_1
(
object
sender
,
EventArgs
e
)
private
void
newScan
(
HObject
ho_Image
)
{
{
int
count
=
cmbCount
.
SelectedIndex
;
try
txtResult
.
Text
=
""
;
{
txtResult
.
Text
=
""
;
stopwatch
.
Restart
();
List
<
CodeInfo
>
cc
=
new
List
<
CodeInfo
>();
stopwatch
.
Restart
();
HDRemoteDecodeHelper
.
RemoteDecodeParam
remoteDecodeParam
=
new
HDRemoteDecodeHelper
.
RemoteDecodeParam
{
string
fname1
=
(
@"G:\img\入料T1-10-37-33-154.bmp"
);
codeTypeList
=
HDCodeLearnHelper
.
codeTypeList
.
ToArray
(),
Task
task1
=
DTest
(
fname1
);
codeCount
=
3
,
Thread
.
Sleep
(
2
);
timeout
=
3000
string
fname2
=
(
@"G:\img\入料T1-10-36-11-530.bmp"
);
};
Task
task2
=
DTest
(
fname2
);
cc
=
HDRemoteDecodeHelper
.
DecodeRequest
(
ho_Image
,
remoteDecodeParam
);
Thread
.
Sleep
(
2
);
if
(
cc
!=
null
)
string
fname3
=
(
@"G:\img\入料T1-10-37-53-865.bmp"
);
{
Task
task3
=
DTest
(
fname3
);
ShowCode
(
cc
,
stopwatch
);
Task
.
WaitAll
(
task1
,
task2
,
task3
);
}
txtResult
.
Text
+=
"\r\n taskEnd:"
+
stopwatch
.
Elapsed
.
ToString
();
}
catch
(
Exception
ex
)
{
HDLogUtil
.
error
(
" RemoteDecodeHelper扫码出错:"
+
ex
.
ToString
());
}
}
private
void
btnServerTest_Click
(
object
sender
,
EventArgs
e
)
{
if
(
HDCodeLearnHelper
.
DefaultImage
==
null
)
{
return
;
}
newScan
(
HDCodeLearnHelper
.
DefaultImage
);
}
}
private
Task
DTest
(
string
fname
)
private
Task
DTest
(
string
fname
)
{
{
...
...
CodeLibraryProject/CodeLibrary/HDCodeHelper.cs
查看文件 @
2235d36
...
@@ -423,7 +423,7 @@ namespace CodeLibrary
...
@@ -423,7 +423,7 @@ namespace CodeLibrary
}
}
[
Serializable
]
public
class
CodeInfo
public
class
CodeInfo
{
{
public
string
CodeStr
=
""
;
public
string
CodeStr
=
""
;
...
@@ -431,6 +431,10 @@ public class CodeInfo
...
@@ -431,6 +431,10 @@ public class CodeInfo
public
int
Y
=
0
;
public
int
Y
=
0
;
public
string
CodeType
;
public
string
CodeType
;
public
double
Orientation
=
0
;
public
double
Orientation
=
0
;
public
CodeInfo
()
{
}
public
CodeInfo
(
string
codeStr
,
int
x
,
int
y
)
public
CodeInfo
(
string
codeStr
,
int
x
,
int
y
)
{
{
this
.
CodeStr
=
codeStr
;
this
.
CodeStr
=
codeStr
;
...
...
CodeLibraryProject/CodeLibrary/HDRemoteDecodeHelper.cs
0 → 100644
查看文件 @
2235d36
using
CodeLibrary
;
using
HalconDotNet
;
using
System
;
using
System.Collections.Generic
;
using
System.Diagnostics
;
using
System.Drawing
;
using
System.IO
;
using
System.Linq
;
using
System.Net
;
using
System.Runtime.Serialization.Formatters.Binary
;
using
System.Text
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
System.Xml
;
using
System.Xml.Serialization
;
public
class
HDRemoteDecodeHelper
{
static
int
webclienttimeout
=
30
*
1000
;
static
Process
p
=
new
Process
();
const
string
serverhost
=
"http://127.0.0.1:58137/"
;
public
static
List
<
CodeInfo
>
DecodeRequest
(
HObject
hoimg
,
RemoteDecodeParam
remoteDecodeParam
)
{
byte
[]
requestdata
;
lock
(
hoimg
)
{
using
(
MemoryStream
mStream
=
new
MemoryStream
())
{
hoimg
.
Serialize
(
mStream
);
requestdata
=
mStream
.
ToArray
();
mStream
.
Close
();
}
}
return
DecodeRequest
(
requestdata
,
remoteDecodeParam
,
true
);
}
public
static
List
<
CodeInfo
>
DecodeRequest
(
Bitmap
bitmap
,
RemoteDecodeParam
remoteDecodeParam
)
{
byte
[]
requestdata
;
lock
(
bitmap
)
{
using
(
MemoryStream
mStream
=
new
MemoryStream
())
{
BinaryFormatter
bf
=
new
BinaryFormatter
();
bf
.
Serialize
(
mStream
,
bitmap
);
requestdata
=
mStream
.
ToArray
();
mStream
.
Close
();
}
}
return
DecodeRequest
(
requestdata
,
remoteDecodeParam
);
}
static
List
<
CodeInfo
>
DecodeRequest
(
byte
[]
requestdata
,
RemoteDecodeParam
remoteDecodeParam
,
bool
isHObject
=
false
)
{
CheckAndRunServer
();
string
param
;
using
(
MemoryStream
mStreamparam
=
new
MemoryStream
())
{
XmlSerializer
xf
=
new
XmlSerializer
(
typeof
(
RemoteDecodeParam
));
xf
.
Serialize
(
mStreamparam
,
remoteDecodeParam
);
param
=
base64UrlEncode
(
mStreamparam
.
ToArray
());
mStreamparam
.
Close
();
}
string
url
=
serverhost
+
"ProcessBitmap?param="
;
if
(
isHObject
)
url
=
serverhost
+
"Process?param="
;
byte
[]
resp
;
try
{
MyWebClient
webClient
=
new
MyWebClient
(
webclienttimeout
);
resp
=
webClient
.
UploadData
(
url
+
param
,
requestdata
);
webClient
.
Dispose
();
}
catch
(
WebException
we
)
{
return
null
;
}
catch
{
return
null
;
}
var
ss
=
Encoding
.
UTF8
.
GetString
(
resp
).
Trim
().
Trim
(
'"'
);
var
bb
=
Convert
.
FromBase64String
(
ss
);
List
<
CodeInfo
>
codeInfos
;
using
(
MemoryStream
mStreamResult
=
new
MemoryStream
(
bb
))
{
XmlSerializer
xff
=
new
XmlSerializer
(
typeof
(
List
<
CodeInfo
>));
codeInfos
=
(
List
<
CodeInfo
>)
xff
.
Deserialize
(
mStreamResult
);
}
return
codeInfos
;
}
/// <summary>
/// 在url中传递base64字符串需要替换加号等符号
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
static
string
base64UrlEncode
(
byte
[]
input
)
{
return
Convert
.
ToBase64String
(
input
).
Replace
(
'+'
,
'-'
).
Replace
(
'/'
,
'_'
);
}
/// <summary>
/// 检查并自动启动服务器
/// </summary>
static
void
CheckAndRunServer
()
{
lock
(
p
)
{
var
pss
=
Process
.
GetProcessesByName
(
"ScanCodeServer"
);
if
(
pss
.
Length
>
0
)
return
;
var
f
=
"ScanCodeServer\\ScanCodeServer.exe"
;
if
(!
File
.
Exists
(
f
))
throw
new
Exception
(
"找不到扫码服务器文件"
);
p
.
StartInfo
=
new
ProcessStartInfo
(
f
);
p
.
Start
();
int
checkcount
=
5
;
while
(
checkcount
>
0
)
{
checkcount
--;
Thread
.
Sleep
(
500
);
MyWebClient
webClient
=
new
MyWebClient
(
webclienttimeout
);
var
s
=
webClient
.
DownloadString
(
serverhost
+
"alive"
);
if
(
s
.
Trim
()
==
"\"1\""
)
return
;
}
throw
new
Exception
(
"扫码服务器打开失败"
);
}
}
[
Serializable
]
public
struct
RemoteDecodeParam
{
public
string
[]
codeTypeList
;
public
int
codeCount
;
public
int
timeout
;
}
public
class
MyWebClient
:
WebClient
{
private
int
_timeout
;
public
MyWebClient
(
int
timeout
)
{
this
.
_timeout
=
timeout
;
}
protected
override
WebRequest
GetWebRequest
(
Uri
address
)
{
var
result
=
base
.
GetWebRequest
(
address
);
result
.
Timeout
=
this
.
_timeout
;
return
result
;
}
}
}
CodeLibraryProject/CodeTest/Program.cs
查看文件 @
2235d36
...
@@ -30,7 +30,7 @@ namespace CodeTest
...
@@ -30,7 +30,7 @@ namespace CodeTest
private
static
string
CodeResourceControl_GetLanguageEvent
()
private
static
string
CodeResourceControl_GetLanguageEvent
()
{
{
return
CodeResourceControl
.
English
;
return
CodeResourceControl
.
China
;
}
}
}
}
}
}
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论