Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
刘韬
/
HalconScanCodeServer
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit 2fd3840f
由
刘韬
编写于
2025-07-09 09:37:25 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
添加支持单线程模式
1 个父辈
5856db66
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
81 行增加
和
74 行删除
ScanCodeServer/Form1.cs
ScanCodeServer/HDCodeHelper.cs
ScanCodeServer/ScanCodeServer.csproj
ScanCodeServer/Setting.cs
ScanCodeServer/WebWork.cs
ScanCodeServer/Form1.cs
查看文件 @
2fd3840
...
@@ -145,16 +145,21 @@ namespace ScanCodeServer
...
@@ -145,16 +145,21 @@ namespace ScanCodeServer
{
{
file
=
openFileDialog
.
FileName
;
file
=
openFileDialog
.
FileName
;
}
}
//for (int i = 0; i < 100; i++)
Bitmap
bitmap
=
new
Bitmap
(
file
);
{
WebWork
webWork
=
new
WebWork
();
Bitmap
bitmap
=
new
Bitmap
(
file
);
var
b
=
HDCodeHelper
.
Bitmap2HObjectBpp24
(
bitmap
,
out
HObject
ho_Image
);
WebWork
webWork
=
new
WebWork
();
//bitmap.Dispose();
var
b
=
HDCodeHelper
.
Bitmap2HObjectBpp24
(
bitmap
,
out
HObject
ho_Image
);
RemoteDecodeParam
remoteDecodeParam
=
new
RemoteDecodeParam
();
//bitmap.Dispose();
remoteDecodeParam
.
codeTypeList
=
new
string
[]
{
"barcode"
,
"Data Matrix ECC 200"
,
"QR Code"
,
"PDF417"
,
"eyem"
};
RemoteDecodeParam
remoteDecodeParam
=
new
RemoteDecodeParam
();
remoteDecodeParam
.
codeCount
=
3
;
remoteDecodeParam
.
codeTypeList
=
new
string
[]
{
"barcode"
,
"Data Matrix ECC 200"
,
"QR Code"
,
"PDF417"
};
remoteDecodeParam
.
timeout
=
3000
;
remoteDecodeParam
.
codeCount
=
3
;
webWork
.
Process
(
ho_Image
,
bitmap
,
remoteDecodeParam
);
remoteDecodeParam
.
timeout
=
3000
;
webWork
.
Process
(
ho_Image
,
bitmap
,
remoteDecodeParam
);
ho_Image
.
Dispose
();
bitmap
.
Dispose
();
}
//GC.Collect();
}
}
private
void
参数
ToolStripMenuItem_Click
(
object
sender
,
EventArgs
e
)
private
void
参数
ToolStripMenuItem_Click
(
object
sender
,
EventArgs
e
)
...
...
ScanCodeServer/HDCodeHelper.cs
查看文件 @
2fd3840
...
@@ -9,11 +9,7 @@ using System.Linq;
...
@@ -9,11 +9,7 @@ using System.Linq;
using
System.Runtime.InteropServices
;
using
System.Runtime.InteropServices
;
using
System.Runtime.Serialization
;
using
System.Runtime.Serialization
;
using
System.Text
;
using
System.Text
;
using
System.Text.RegularExpressions
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
System.Windows.Forms
;
using
static
ScanCodeServer
.
EyemDecode2
;
using
static
System
.
Net
.
Mime
.
MediaTypeNames
;
namespace
ScanCodeServer
namespace
ScanCodeServer
{
{
...
@@ -87,27 +83,41 @@ namespace ScanCodeServer
...
@@ -87,27 +83,41 @@ namespace ScanCodeServer
return
codeList
;
return
codeList
;
}
}
static
Dictionary
<
string
,
HTuple
>
twoModuleCache
=
new
Dictionary
<
string
,
HTuple
>();
public
static
List
<
CodeInfo
>
DecodeCode
(
HObject
ho_Image
,
string
symbolType
,
string
hv_model_path
,
int
codeCount
,
int
timeOut
=
1500
)
public
static
List
<
CodeInfo
>
DecodeCode
(
HObject
ho_Image
,
string
symbolType
,
string
hv_model_path
,
int
codeCount
,
int
timeOut
=
1500
)
{
{
Common
.
log
.
Info
(
"开始 DecodeCode["
+
symbolType
+
"]["
+
codeCount
+
"]["
+
hv_model_path
+
"]"
);
Common
.
log
.
Info
(
"开始 DecodeCode["
+
symbolType
+
"]["
+
codeCount
+
"]["
+
hv_model_path
+
"]"
);
Stopwatch
sw
=
new
Stopwatch
();
Stopwatch
sw
=
new
Stopwatch
();
sw
.
Start
();
sw
.
Start
();
List
<
CodeInfo
>
codeList
=
new
List
<
CodeInfo
>();
List
<
CodeInfo
>
codeList
=
new
List
<
CodeInfo
>();
HTuple
hv_Area
=
null
;
HTuple
hv_Row1
=
null
;
HTuple
hv_Column
=
null
;
HTuple
hv_PointOrder
=
null
;
HObject
ho_SymbolXLDs
=
null
;
HTuple
hv_ResultHandles
=
null
;
HTuple
hv_DecodedDataStrings
=
null
;
HTuple
hv_DataCodeHandle
=
null
;
try
try
{
{
HOperatorSet
.
SetSystem
(
"filename_encoding"
,
"utf8"
);
HOperatorSet
.
SetSystem
(
"filename_encoding"
,
"utf8"
);
HTuple
hv_Area
=
null
;
HTuple
hv_Row1
=
null
;
HTuple
hv_Column
=
null
;
HTuple
hv_PointOrder
=
null
;
HObject
ho_SymbolXLDs
;
HTuple
hv_ResultHandles
=
null
;
HTuple
hv_DecodedDataStrings
=
null
;
HTuple
hv_DataCodeHandle
=
null
;
HOperatorSet
.
GenEmptyObj
(
out
ho_SymbolXLDs
);
HOperatorSet
.
GenEmptyObj
(
out
ho_SymbolXLDs
);
HOperatorSet
.
CreateDataCode2dModel
(
symbolType
,
"default_parameters"
,
Setting
.
HOperatorSet_ModelParameter
.
Val
.
ToString
(),
out
hv_DataCodeHandle
);
lock
(
twoModuleCache
)
HOperatorSet
.
SetDataCode2dParam
(
hv_DataCodeHandle
,
"string_encoding"
,
"utf8"
);
{
if
(!
twoModuleCache
.
ContainsKey
(
symbolType
))
{
HOperatorSet
.
CreateDataCode2dModel
(
symbolType
,
"default_parameters"
,
Setting
.
HOperatorSet_ModelParameter
.
Val
.
ToString
(),
out
hv_DataCodeHandle
);
HOperatorSet
.
SetDataCode2dParam
(
hv_DataCodeHandle
,
"string_encoding"
,
"utf8"
);
twoModuleCache
.
Add
(
symbolType
,
hv_DataCodeHandle
);
}
else
{
hv_DataCodeHandle
=
twoModuleCache
[
symbolType
];
}
}
//string hv_model_path = GetCodeParamFilePath(symbolType);
//string hv_model_path = GetCodeParamFilePath(symbolType);
if
(!
hv_model_path
.
Equals
(
""
)
&&
File
.
Exists
(
hv_model_path
))
if
(!
hv_model_path
.
Equals
(
""
)
&&
File
.
Exists
(
hv_model_path
))
{
{
...
@@ -133,8 +143,8 @@ namespace ScanCodeServer
...
@@ -133,8 +143,8 @@ namespace ScanCodeServer
{
{
ShowImage
(
HalconWindow
,
ho_Image
,
ho_SymbolXLDs
);
ShowImage
(
HalconWindow
,
ho_Image
,
ho_SymbolXLDs
);
}
}
HOperatorSet
.
ClearDataCode2dModel
(
hv_DataCodeHandle
);
//
HOperatorSet.ClearDataCode2dModel(hv_DataCodeHandle);
//HOperatorSet.ClearAllDataCode2dModels();
//HOperatorSet.ClearAllDataCode2dModels();
//HOperatorSet.ClearDistanceTransformXld(ho_SymbolXLDs);
//HOperatorSet.ClearDistanceTransformXld(ho_SymbolXLDs);
if
(
hv_DecodedDataStrings
.
Length
>
0
)
if
(
hv_DecodedDataStrings
.
Length
>
0
)
...
@@ -147,7 +157,7 @@ namespace ScanCodeServer
...
@@ -147,7 +157,7 @@ namespace ScanCodeServer
int
x
=
(
int
)
Math
.
Round
(
hv_Column
.
DArr
[
i
]);
int
x
=
(
int
)
Math
.
Round
(
hv_Column
.
DArr
[
i
]);
int
y
=
(
int
)
Math
.
Round
(
hv_Row1
.
DArr
[
i
]);
int
y
=
(
int
)
Math
.
Round
(
hv_Row1
.
DArr
[
i
]);
string
str
=
hv_DecodedDataStrings
.
SArr
[
i
];
string
str
=
hv_DecodedDataStrings
.
SArr
[
i
];
//str = SpecialCharReplace(str);
//str = SpecialCharReplace(str);
//var isv = IsStringValid(str);
//var isv = IsStringValid(str);
CodeInfo
code
=
new
CodeInfo
(
str
,
x
,
y
);
CodeInfo
code
=
new
CodeInfo
(
str
,
x
,
y
);
...
@@ -160,52 +170,35 @@ namespace ScanCodeServer
...
@@ -160,52 +170,35 @@ namespace ScanCodeServer
}
}
}
}
sw
.
Stop
();
sw
.
Stop
();
Common
.
log
.
Info
(
"结束 DecodeCode["
+
symbolType
+
"]["
+
codeCount
+
"]["
+
(
sw
.
ElapsedMilliseconds
/
1000f
).
ToString
(
"0.00"
)+
"]返回数量:"
+
codeList
.
Count
);
Common
.
log
.
Info
(
"结束 DecodeCode["
+
symbolType
+
"]["
+
codeCount
+
"]["
+
(
sw
.
ElapsedMilliseconds
/
1000f
).
ToString
(
"0.00"
)
+
"]返回数量:"
+
codeList
.
Count
);
if
(
hv_Area
!=
null
)
{
hv_Area
.
UnpinTuple
();
}
if
(
hv_Row1
!=
null
)
{
hv_Row1
.
UnpinTuple
();
}
if
(
hv_Column
!=
null
)
{
hv_Column
.
UnpinTuple
();
}
if
(
hv_PointOrder
!=
null
)
{
hv_PointOrder
.
UnpinTuple
();
}
if
(
hv_ResultHandles
!=
null
)
{
hv_ResultHandles
.
UnpinTuple
();
}
if
(
hv_DecodedDataStrings
!=
null
)
{
hv_DecodedDataStrings
.
UnpinTuple
();
}
if
(
hv_DataCodeHandle
!=
null
)
{
hv_DataCodeHandle
.
UnpinTuple
();
}
if
(
ho_SymbolXLDs
!=
null
)
{
ho_SymbolXLDs
.
Dispose
();
ho_SymbolXLDs
=
null
;
}
return
codeList
;
return
codeList
;
}
}
catch
(
Exception
ex
)
catch
(
Exception
ex
)
{
{
Common
.
log
.
Error
(
"DecodeCode出错:"
+
ex
.
ToString
());
//Common.log.Error($
"DecodeCode出错:" + ex.ToString());
Console
.
WriteLine
(
"DecodeCode出错:"
+
ex
.
ToString
());
//Console.WriteLine($
"DecodeCode出错:" + ex.ToString());
Common
.
log
.
Info
(
" DecodeCode["
+
symbolType
+
"]["
+
hv_model_path
+
"]["
+
codeCount
+
"] 结束,返回数量:"
+
codeList
.
Count
);
Common
.
log
.
Info
(
$
" DecodeCode出错["
+
symbolType
+
"]"
+
ex
.
ToString
()
);
return
codeList
;
return
codeList
;
}
}
finally
{
hv_Area
?.
UnpinTuple
();
hv_Area
?.
Dispose
();
hv_Row1
?.
UnpinTuple
();
hv_Row1
?.
Dispose
();
hv_Column
?.
UnpinTuple
();
hv_Column
?.
Dispose
();
hv_PointOrder
?.
UnpinTuple
();
hv_PointOrder
?.
Dispose
();
hv_ResultHandles
?.
UnpinTuple
();
hv_ResultHandles
?.
Dispose
();
hv_DecodedDataStrings
?.
UnpinTuple
();
hv_DecodedDataStrings
?.
Dispose
();
//hv_DataCodeHandle?.UnpinTuple();
//hv_DataCodeHandle?.Dispose();
ho_SymbolXLDs
?.
Dispose
();
}
}
}
...
@@ -338,8 +331,8 @@ namespace ScanCodeServer
...
@@ -338,8 +331,8 @@ namespace ScanCodeServer
internal
static
string
GetCodeParamFilePath
(
string
codeType
)
internal
static
string
GetCodeParamFilePath
(
string
codeType
)
{
{
string
appPath
=
Path
.
Combine
(
System
.
Windows
.
Forms
.
Application
.
StartupPath
,
"..\\"
);
string
appPath
=
Path
.
Combine
(
System
.
Windows
.
Forms
.
Application
.
StartupPath
,
"..\\"
);
if
(!
Directory
.
Exists
(
Path
.
Combine
(
appPath
,
CodeParamPath
)))
if
(!
Directory
.
Exists
(
Path
.
Combine
(
appPath
,
CodeParamPath
)))
{
{
appPath
=
System
.
Windows
.
Forms
.
Application
.
StartupPath
;
appPath
=
System
.
Windows
.
Forms
.
Application
.
StartupPath
;
}
}
...
...
ScanCodeServer/ScanCodeServer.csproj
查看文件 @
2fd3840
...
@@ -111,8 +111,12 @@
...
@@ -111,8 +111,12 @@
<None Include="App.config" />
<None Include="App.config" />
</ItemGroup>
</ItemGroup>
<ItemGroup>
<ItemGroup>
<Content Include="halcon20\halcon.dll" />
<Content Include="halcon20\halcon.dll">
<Content Include="halcon20\halcondotnet.dll" />
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="halcon20\halcondotnet.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PropertyGroup>
...
...
ScanCodeServer/Setting.cs
查看文件 @
2fd3840
...
@@ -30,6 +30,9 @@ namespace ScanCodeServer
...
@@ -30,6 +30,9 @@ namespace ScanCodeServer
[
MyConfigComment
(
"进程优先级"
)]
[
MyConfigComment
(
"进程优先级"
)]
public
static
MyConfig
<
ModelParameter
>
HOperatorSet_ModelParameter
=
ModelParameter
.
standard_recognition
;
public
static
MyConfig
<
ModelParameter
>
HOperatorSet_ModelParameter
=
ModelParameter
.
standard_recognition
;
[
MyConfigComment
(
"是否异步扫码"
)]
public
static
MyConfig
<
bool
>
App_AsyncScan
=
true
;
}
}
public
enum
ModelParameter
public
enum
ModelParameter
{
{
...
...
ScanCodeServer/WebWork.cs
查看文件 @
2fd3840
...
@@ -122,15 +122,17 @@ namespace ScanCodeServer
...
@@ -122,15 +122,17 @@ namespace ScanCodeServer
}
}
});
});
t
[
ti
].
ConfigureAwait
(
false
);
if
(!
Setting
.
App_AsyncScan
)
t
[
ti
].
Wait
(
timeout
+
1000
*
5
);
ti
++;
ti
++;
}
}
var
r
=
Task
.
WaitAll
(
t
,
timeout
+
1000
*
5
);
var
r
=
Task
.
WaitAll
(
t
,
timeout
+
1000
*
5
);
sw
.
Stop
();
sw
.
Stop
();
ho_Image
.
Dispose
();
ho_Image
?.
Dispose
();
if
(
bitmap
!=
null
)
bitmap
?.
Dispose
();
bitmap
.
Dispose
();
Common
.
log
.
Info
(
$
"结束扫码:task finish:{r},
codeCount
:{sw.ElapsedMilliseconds/1000f:0.00}"
);
Common
.
log
.
Info
(
$
"结束扫码:task finish:{r},
time
:{sw.ElapsedMilliseconds/1000f:0.00}"
);
using
(
MemoryStream
respStream
=
new
MemoryStream
())
using
(
MemoryStream
respStream
=
new
MemoryStream
())
{
{
...
...
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论