Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
李娜
/
AutoCountMachine
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit dc2183db
由
LN
编写于
2020-09-10 18:33:23 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
增加扫码源码
1 个父辈
fa6e6336
显示空白字符变更
内嵌
并排
正在显示
12 个修改的文件
包含
781 行增加
和
324 行删除
RC1266-AutoCountMachine/source/CodeLibrary/CodeLibrary.csproj
RC1266-AutoCountMachine/source/CodeLibrary/CodeResourceControl.cs
RC1266-AutoCountMachine/source/CodeLibrary/FrmCodeDecode.Designer.cs
RC1266-AutoCountMachine/source/CodeLibrary/FrmCodeDecode.cs
RC1266-AutoCountMachine/source/CodeLibrary/FrmCodeLearn.Designer.cs
RC1266-AutoCountMachine/source/CodeLibrary/FrmCodeLearn.cs
RC1266-AutoCountMachine/source/CodeLibrary/HDCodeHelper.cs
RC1266-AutoCountMachine/source/CodeLibrary/HDCodeLearnHelper.cs
RC1266-AutoCountMachine/source/CodeLibrary/ZXingCodeHelper.cs
RC1266-AutoCountMachine/source/CodeLibrary/camera/Basler.cs
RC1266-AutoCountMachine/source/CodeLibrary/camera/Common.cs
RC1266-AutoCountMachine/source/CodeLibrary/camera/HIK.cs
RC1266-AutoCountMachine/source/CodeLibrary/CodeLibrary.csproj
查看文件 @
dc2183d
...
...
@@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CodeLibrary</RootNamespace>
<AssemblyName>CodeLibrary</AssemblyName>
<TargetFrameworkVersion>v4.
0
</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.
5
</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
...
...
@@ -22,6 +22,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
...
...
@@ -30,6 +31,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Basler.Pylon, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e389355f398382ab, processorArchitecture=x86">
...
...
@@ -55,6 +57,9 @@
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="zxing">
<HintPath>..\dll\zxing.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="camera\Basler.cs" />
...
...
@@ -84,6 +89,7 @@
<Compile Include="ImageHelper.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="CodeResourceControl.cs" />
<Compile Include="ZXingCodeHelper.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="FrmBase.resx">
...
...
RC1266-AutoCountMachine/source/CodeLibrary/CodeResourceControl.cs
查看文件 @
dc2183d
...
...
@@ -85,6 +85,10 @@ namespace CodeLibrary
NoIdLog
(
id
,
defaultStr
);
}
}
if
(
strCurLanguage
==
null
)
{
strCurLanguage
=
""
;
}
return
strCurLanguage
;
}
public
static
string
GetString
(
string
id
,
string
defaultStr
,
params
object
[]
param
)
...
...
RC1266-AutoCountMachine/source/CodeLibrary/FrmCodeDecode.Designer.cs
查看文件 @
dc2183d
...
...
@@ -33,8 +33,6 @@
this
.
btnSelImage
=
new
System
.
Windows
.
Forms
.
Button
();
this
.
pictureBox1
=
new
System
.
Windows
.
Forms
.
PictureBox
();
this
.
txtResult
=
new
System
.
Windows
.
Forms
.
TextBox
();
this
.
btnErZhi
=
new
System
.
Windows
.
Forms
.
Button
();
this
.
btnGray
=
new
System
.
Windows
.
Forms
.
Button
();
this
.
hWindowControl1
=
new
HalconDotNet
.
HWindowControl
();
this
.
btnbarCode
=
new
System
.
Windows
.
Forms
.
Button
();
this
.
btnLearn
=
new
System
.
Windows
.
Forms
.
Button
();
...
...
@@ -49,13 +47,12 @@
this
.
label2
=
new
System
.
Windows
.
Forms
.
Label
();
this
.
cmbCodeType
=
new
System
.
Windows
.
Forms
.
ComboBox
();
this
.
label3
=
new
System
.
Windows
.
Forms
.
Label
();
this
.
btnAn
=
new
System
.
Windows
.
Forms
.
Button
();
this
.
chbUseParam
=
new
System
.
Windows
.
Forms
.
CheckBox
();
this
.
txtParamPath
=
new
System
.
Windows
.
Forms
.
TextBox
();
this
.
label4
=
new
System
.
Windows
.
Forms
.
Label
();
this
.
btnLight
=
new
System
.
Windows
.
Forms
.
Button
();
this
.
button1
=
new
System
.
Windows
.
Forms
.
Button
();
this
.
btnScanTest
=
new
System
.
Windows
.
Forms
.
Button
();
this
.
chbZxing
=
new
System
.
Windows
.
Forms
.
CheckBox
();
this
.
label5
=
new
System
.
Windows
.
Forms
.
Label
();
((
System
.
ComponentModel
.
ISupportInitialize
)(
this
.
pictureBox1
)).
BeginInit
();
this
.
SuspendLayout
();
//
...
...
@@ -70,7 +67,7 @@
// btnSelImage
//
this
.
btnSelImage
.
Font
=
new
System
.
Drawing
.
Font
(
"微软雅黑"
,
9F
,
System
.
Drawing
.
FontStyle
.
Regular
,
System
.
Drawing
.
GraphicsUnit
.
Point
,
((
byte
)(
134
)));
this
.
btnSelImage
.
Location
=
new
System
.
Drawing
.
Point
(
10
,
1
2
);
this
.
btnSelImage
.
Location
=
new
System
.
Drawing
.
Point
(
10
,
1
0
);
this
.
btnSelImage
.
Name
=
"btnSelImage"
;
this
.
btnSelImage
.
Size
=
new
System
.
Drawing
.
Size
(
141
,
33
);
this
.
btnSelImage
.
TabIndex
=
1
;
...
...
@@ -99,30 +96,6 @@
this
.
txtResult
.
Size
=
new
System
.
Drawing
.
Size
(
450
,
290
);
this
.
txtResult
.
TabIndex
=
3
;
//
// btnErZhi
//
this
.
btnErZhi
.
Font
=
new
System
.
Drawing
.
Font
(
"微软雅黑"
,
9F
,
System
.
Drawing
.
FontStyle
.
Regular
,
System
.
Drawing
.
GraphicsUnit
.
Point
,
((
byte
)(
134
)));
this
.
btnErZhi
.
Location
=
new
System
.
Drawing
.
Point
(
557
,
12
);
this
.
btnErZhi
.
Name
=
"btnErZhi"
;
this
.
btnErZhi
.
Size
=
new
System
.
Drawing
.
Size
(
59
,
33
);
this
.
btnErZhi
.
TabIndex
=
5
;
this
.
btnErZhi
.
Text
=
"二值化"
;
this
.
btnErZhi
.
UseVisualStyleBackColor
=
true
;
this
.
btnErZhi
.
Visible
=
false
;
this
.
btnErZhi
.
Click
+=
new
System
.
EventHandler
(
this
.
btnErZhi_Click
);
//
// btnGray
//
this
.
btnGray
.
Font
=
new
System
.
Drawing
.
Font
(
"微软雅黑"
,
9F
,
System
.
Drawing
.
FontStyle
.
Regular
,
System
.
Drawing
.
GraphicsUnit
.
Point
,
((
byte
)(
134
)));
this
.
btnGray
.
Location
=
new
System
.
Drawing
.
Point
(
557
,
50
);
this
.
btnGray
.
Name
=
"btnGray"
;
this
.
btnGray
.
Size
=
new
System
.
Drawing
.
Size
(
59
,
33
);
this
.
btnGray
.
TabIndex
=
6
;
this
.
btnGray
.
Text
=
"图像转灰"
;
this
.
btnGray
.
UseVisualStyleBackColor
=
true
;
this
.
btnGray
.
Visible
=
false
;
this
.
btnGray
.
Click
+=
new
System
.
EventHandler
(
this
.
btnGray_Click
);
//
// hWindowControl1
//
this
.
hWindowControl1
.
Anchor
=
((
System
.
Windows
.
Forms
.
AnchorStyles
)((((
System
.
Windows
.
Forms
.
AnchorStyles
.
Top
|
System
.
Windows
.
Forms
.
AnchorStyles
.
Bottom
)
...
...
@@ -140,7 +113,7 @@
// btnbarCode
//
this
.
btnbarCode
.
Font
=
new
System
.
Drawing
.
Font
(
"微软雅黑"
,
9F
,
System
.
Drawing
.
FontStyle
.
Regular
,
System
.
Drawing
.
GraphicsUnit
.
Point
,
((
byte
)(
134
)));
this
.
btnbarCode
.
Location
=
new
System
.
Drawing
.
Point
(
896
,
50
);
this
.
btnbarCode
.
Location
=
new
System
.
Drawing
.
Point
(
896
,
49
);
this
.
btnbarCode
.
Name
=
"btnbarCode"
;
this
.
btnbarCode
.
Size
=
new
System
.
Drawing
.
Size
(
167
,
33
);
this
.
btnbarCode
.
TabIndex
=
9
;
...
...
@@ -152,7 +125,7 @@
//
this
.
btnLearn
.
Anchor
=
((
System
.
Windows
.
Forms
.
AnchorStyles
)((
System
.
Windows
.
Forms
.
AnchorStyles
.
Top
|
System
.
Windows
.
Forms
.
AnchorStyles
.
Right
)));
this
.
btnLearn
.
Font
=
new
System
.
Drawing
.
Font
(
"微软雅黑"
,
9F
,
System
.
Drawing
.
FontStyle
.
Regular
,
System
.
Drawing
.
GraphicsUnit
.
Point
,
((
byte
)(
134
)));
this
.
btnLearn
.
Location
=
new
System
.
Drawing
.
Point
(
1249
,
1
2
);
this
.
btnLearn
.
Location
=
new
System
.
Drawing
.
Point
(
1249
,
1
0
);
this
.
btnLearn
.
Name
=
"btnLearn"
;
this
.
btnLearn
.
Size
=
new
System
.
Drawing
.
Size
(
109
,
33
);
this
.
btnLearn
.
TabIndex
=
10
;
...
...
@@ -163,7 +136,7 @@
// btnDCode
//
this
.
btnDCode
.
Font
=
new
System
.
Drawing
.
Font
(
"微软雅黑"
,
9F
,
System
.
Drawing
.
FontStyle
.
Regular
,
System
.
Drawing
.
GraphicsUnit
.
Point
,
((
byte
)(
134
)));
this
.
btnDCode
.
Location
=
new
System
.
Drawing
.
Point
(
896
,
1
2
);
this
.
btnDCode
.
Location
=
new
System
.
Drawing
.
Point
(
896
,
1
0
);
this
.
btnDCode
.
Name
=
"btnDCode"
;
this
.
btnDCode
.
Size
=
new
System
.
Drawing
.
Size
(
167
,
33
);
this
.
btnDCode
.
TabIndex
=
11
;
...
...
@@ -174,7 +147,7 @@
// btnClearLog
//
this
.
btnClearLog
.
Font
=
new
System
.
Drawing
.
Font
(
"微软雅黑"
,
9F
,
System
.
Drawing
.
FontStyle
.
Regular
,
System
.
Drawing
.
GraphicsUnit
.
Point
,
((
byte
)(
134
)));
this
.
btnClearLog
.
Location
=
new
System
.
Drawing
.
Point
(
711
,
50
);
this
.
btnClearLog
.
Location
=
new
System
.
Drawing
.
Point
(
711
,
49
);
this
.
btnClearLog
.
Name
=
"btnClearLog"
;
this
.
btnClearLog
.
Size
=
new
System
.
Drawing
.
Size
(
116
,
33
);
this
.
btnClearLog
.
TabIndex
=
12
;
...
...
@@ -209,7 +182,7 @@
"18"
,
"19"
,
"20"
});
this
.
cmbCount
.
Location
=
new
System
.
Drawing
.
Point
(
334
,
16
);
this
.
cmbCount
.
Location
=
new
System
.
Drawing
.
Point
(
334
,
53
);
this
.
cmbCount
.
Name
=
"cmbCount"
;
this
.
cmbCount
.
Size
=
new
System
.
Drawing
.
Size
(
66
,
25
);
this
.
cmbCount
.
TabIndex
=
16
;
...
...
@@ -217,7 +190,7 @@
// lblCount
//
this
.
lblCount
.
Font
=
new
System
.
Drawing
.
Font
(
"微软雅黑"
,
9F
,
System
.
Drawing
.
FontStyle
.
Regular
,
System
.
Drawing
.
GraphicsUnit
.
Point
,
((
byte
)(
134
)));
this
.
lblCount
.
Location
=
new
System
.
Drawing
.
Point
(
157
,
20
);
this
.
lblCount
.
Location
=
new
System
.
Drawing
.
Point
(
157
,
57
);
this
.
lblCount
.
Name
=
"lblCount"
;
this
.
lblCount
.
Size
=
new
System
.
Drawing
.
Size
(
171
,
17
);
this
.
lblCount
.
TabIndex
=
15
;
...
...
@@ -227,7 +200,7 @@
// btnCameraImage
//
this
.
btnCameraImage
.
Font
=
new
System
.
Drawing
.
Font
(
"微软雅黑"
,
9F
,
System
.
Drawing
.
FontStyle
.
Regular
,
System
.
Drawing
.
GraphicsUnit
.
Point
,
((
byte
)(
134
)));
this
.
btnCameraImage
.
Location
=
new
System
.
Drawing
.
Point
(
10
,
50
);
this
.
btnCameraImage
.
Location
=
new
System
.
Drawing
.
Point
(
10
,
49
);
this
.
btnCameraImage
.
Name
=
"btnCameraImage"
;
this
.
btnCameraImage
.
Size
=
new
System
.
Drawing
.
Size
(
141
,
33
);
this
.
btnCameraImage
.
TabIndex
=
17
;
...
...
@@ -239,7 +212,7 @@
//
this
.
btnExit
.
Anchor
=
((
System
.
Windows
.
Forms
.
AnchorStyles
)((
System
.
Windows
.
Forms
.
AnchorStyles
.
Top
|
System
.
Windows
.
Forms
.
AnchorStyles
.
Right
)));
this
.
btnExit
.
Font
=
new
System
.
Drawing
.
Font
(
"微软雅黑"
,
9F
,
System
.
Drawing
.
FontStyle
.
Regular
,
System
.
Drawing
.
GraphicsUnit
.
Point
,
((
byte
)(
134
)));
this
.
btnExit
.
Location
=
new
System
.
Drawing
.
Point
(
1249
,
50
);
this
.
btnExit
.
Location
=
new
System
.
Drawing
.
Point
(
1249
,
49
);
this
.
btnExit
.
Name
=
"btnExit"
;
this
.
btnExit
.
Size
=
new
System
.
Drawing
.
Size
(
109
,
33
);
this
.
btnExit
.
TabIndex
=
18
;
...
...
@@ -263,7 +236,7 @@
this
.
cmbCamera
.
DropDownStyle
=
System
.
Windows
.
Forms
.
ComboBoxStyle
.
DropDownList
;
this
.
cmbCamera
.
Font
=
new
System
.
Drawing
.
Font
(
"微软雅黑"
,
9F
,
System
.
Drawing
.
FontStyle
.
Regular
,
System
.
Drawing
.
GraphicsUnit
.
Point
,
((
byte
)(
134
)));
this
.
cmbCamera
.
FormattingEnabled
=
true
;
this
.
cmbCamera
.
Location
=
new
System
.
Drawing
.
Point
(
334
,
5
4
);
this
.
cmbCamera
.
Location
=
new
System
.
Drawing
.
Point
(
334
,
1
4
);
this
.
cmbCamera
.
Name
=
"cmbCamera"
;
this
.
cmbCamera
.
Size
=
new
System
.
Drawing
.
Size
(
326
,
25
);
this
.
cmbCamera
.
TabIndex
=
21
;
...
...
@@ -271,7 +244,7 @@
// label2
//
this
.
label2
.
Font
=
new
System
.
Drawing
.
Font
(
"微软雅黑"
,
9F
,
System
.
Drawing
.
FontStyle
.
Regular
,
System
.
Drawing
.
GraphicsUnit
.
Point
,
((
byte
)(
134
)));
this
.
label2
.
Location
=
new
System
.
Drawing
.
Point
(
157
,
5
8
);
this
.
label2
.
Location
=
new
System
.
Drawing
.
Point
(
157
,
1
8
);
this
.
label2
.
Name
=
"label2"
;
this
.
label2
.
Size
=
new
System
.
Drawing
.
Size
(
171
,
17
);
this
.
label2
.
TabIndex
=
20
;
...
...
@@ -283,7 +256,7 @@
this
.
cmbCodeType
.
DropDownStyle
=
System
.
Windows
.
Forms
.
ComboBoxStyle
.
DropDownList
;
this
.
cmbCodeType
.
Font
=
new
System
.
Drawing
.
Font
(
"微软雅黑"
,
9F
,
System
.
Drawing
.
FontStyle
.
Regular
,
System
.
Drawing
.
GraphicsUnit
.
Point
,
((
byte
)(
134
)));
this
.
cmbCodeType
.
FormattingEnabled
=
true
;
this
.
cmbCodeType
.
Location
=
new
System
.
Drawing
.
Point
(
506
,
16
);
this
.
cmbCodeType
.
Location
=
new
System
.
Drawing
.
Point
(
506
,
53
);
this
.
cmbCodeType
.
Name
=
"cmbCodeType"
;
this
.
cmbCodeType
.
Size
=
new
System
.
Drawing
.
Size
(
154
,
25
);
this
.
cmbCodeType
.
TabIndex
=
23
;
...
...
@@ -292,32 +265,20 @@
// label3
//
this
.
label3
.
Font
=
new
System
.
Drawing
.
Font
(
"微软雅黑"
,
9F
,
System
.
Drawing
.
FontStyle
.
Regular
,
System
.
Drawing
.
GraphicsUnit
.
Point
,
((
byte
)(
134
)));
this
.
label3
.
Location
=
new
System
.
Drawing
.
Point
(
378
,
20
);
this
.
label3
.
Location
=
new
System
.
Drawing
.
Point
(
378
,
57
);
this
.
label3
.
Name
=
"label3"
;
this
.
label3
.
Size
=
new
System
.
Drawing
.
Size
(
122
,
17
);
this
.
label3
.
TabIndex
=
22
;
this
.
label3
.
Text
=
"条码类型:"
;
this
.
label3
.
TextAlign
=
System
.
Drawing
.
ContentAlignment
.
MiddleRight
;
//
// btnAn
//
this
.
btnAn
.
Font
=
new
System
.
Drawing
.
Font
(
"微软雅黑"
,
9F
,
System
.
Drawing
.
FontStyle
.
Regular
,
System
.
Drawing
.
GraphicsUnit
.
Point
,
((
byte
)(
134
)));
this
.
btnAn
.
Location
=
new
System
.
Drawing
.
Point
(
645
,
50
);
this
.
btnAn
.
Name
=
"btnAn"
;
this
.
btnAn
.
Size
=
new
System
.
Drawing
.
Size
(
59
,
33
);
this
.
btnAn
.
TabIndex
=
25
;
this
.
btnAn
.
Text
=
"变暗"
;
this
.
btnAn
.
UseVisualStyleBackColor
=
true
;
this
.
btnAn
.
Visible
=
false
;
this
.
btnAn
.
Click
+=
new
System
.
EventHandler
(
this
.
btnAn_Click
);
//
// chbUseParam
//
this
.
chbUseParam
.
AutoSize
=
true
;
this
.
chbUseParam
.
Checked
=
true
;
this
.
chbUseParam
.
CheckState
=
System
.
Windows
.
Forms
.
CheckState
.
Checked
;
this
.
chbUseParam
.
Font
=
new
System
.
Drawing
.
Font
(
"微软雅黑"
,
9F
,
System
.
Drawing
.
FontStyle
.
Regular
,
System
.
Drawing
.
GraphicsUnit
.
Point
,
((
byte
)(
134
)));
this
.
chbUseParam
.
Location
=
new
System
.
Drawing
.
Point
(
711
,
1
8
);
this
.
chbUseParam
.
Location
=
new
System
.
Drawing
.
Point
(
711
,
1
6
);
this
.
chbUseParam
.
Name
=
"chbUseParam"
;
this
.
chbUseParam
.
Size
=
new
System
.
Drawing
.
Size
(
75
,
21
);
this
.
chbUseParam
.
TabIndex
=
26
;
...
...
@@ -344,34 +305,10 @@
this
.
label4
.
Text
=
"参数路径"
;
this
.
label4
.
TextAlign
=
System
.
Drawing
.
ContentAlignment
.
MiddleRight
;
//
// btnLight
//
this
.
btnLight
.
Font
=
new
System
.
Drawing
.
Font
(
"微软雅黑"
,
9F
,
System
.
Drawing
.
FontStyle
.
Regular
,
System
.
Drawing
.
GraphicsUnit
.
Point
,
((
byte
)(
134
)));
this
.
btnLight
.
Location
=
new
System
.
Drawing
.
Point
(
645
,
12
);
this
.
btnLight
.
Name
=
"btnLight"
;
this
.
btnLight
.
Size
=
new
System
.
Drawing
.
Size
(
59
,
33
);
this
.
btnLight
.
TabIndex
=
24
;
this
.
btnLight
.
Text
=
"提亮"
;
this
.
btnLight
.
UseVisualStyleBackColor
=
true
;
this
.
btnLight
.
Visible
=
false
;
this
.
btnLight
.
Click
+=
new
System
.
EventHandler
(
this
.
btnLigth_Click
);
//
// button1
//
this
.
button1
.
Font
=
new
System
.
Drawing
.
Font
(
"微软雅黑"
,
9F
,
System
.
Drawing
.
FontStyle
.
Regular
,
System
.
Drawing
.
GraphicsUnit
.
Point
,
((
byte
)(
134
)));
this
.
button1
.
Location
=
new
System
.
Drawing
.
Point
(
723
,
12
);
this
.
button1
.
Name
=
"button1"
;
this
.
button1
.
Size
=
new
System
.
Drawing
.
Size
(
167
,
33
);
this
.
button1
.
TabIndex
=
29
;
this
.
button1
.
Text
=
"循环测试"
;
this
.
button1
.
UseVisualStyleBackColor
=
true
;
this
.
button1
.
Visible
=
false
;
this
.
button1
.
Click
+=
new
System
.
EventHandler
(
this
.
button1_Click
);
//
// btnScanTest
//
this
.
btnScanTest
.
Font
=
new
System
.
Drawing
.
Font
(
"微软雅黑"
,
9F
,
System
.
Drawing
.
FontStyle
.
Regular
,
System
.
Drawing
.
GraphicsUnit
.
Point
,
((
byte
)(
134
)));
this
.
btnScanTest
.
Location
=
new
System
.
Drawing
.
Point
(
1069
,
1
2
);
this
.
btnScanTest
.
Location
=
new
System
.
Drawing
.
Point
(
1069
,
1
0
);
this
.
btnScanTest
.
Name
=
"btnScanTest"
;
this
.
btnScanTest
.
Size
=
new
System
.
Drawing
.
Size
(
167
,
33
);
this
.
btnScanTest
.
TabIndex
=
30
;
...
...
@@ -379,18 +316,36 @@
this
.
btnScanTest
.
UseVisualStyleBackColor
=
true
;
this
.
btnScanTest
.
Click
+=
new
System
.
EventHandler
(
this
.
btnScanTest_Click
);
//
// chbZxing
//
this
.
chbZxing
.
AutoSize
=
true
;
this
.
chbZxing
.
Font
=
new
System
.
Drawing
.
Font
(
"微软雅黑"
,
9F
,
System
.
Drawing
.
FontStyle
.
Regular
,
System
.
Drawing
.
GraphicsUnit
.
Point
,
((
byte
)(
134
)));
this
.
chbZxing
.
Location
=
new
System
.
Drawing
.
Point
(
820
,
16
);
this
.
chbZxing
.
Name
=
"chbZxing"
;
this
.
chbZxing
.
Size
=
new
System
.
Drawing
.
Size
(
60
,
21
);
this
.
chbZxing
.
TabIndex
=
31
;
this
.
chbZxing
.
Text
=
"ZXing"
;
this
.
chbZxing
.
UseVisualStyleBackColor
=
true
;
//
// label5
//
this
.
label5
.
AutoSize
=
true
;
this
.
label5
.
Location
=
new
System
.
Drawing
.
Point
(
1083
,
57
);
this
.
label5
.
Name
=
"label5"
;
this
.
label5
.
Size
=
new
System
.
Drawing
.
Size
(
0
,
12
);
this
.
label5
.
TabIndex
=
32
;
//
// FrmCodeDecode
//
this
.
AutoScaleDimensions
=
new
System
.
Drawing
.
SizeF
(
6F
,
12F
);
this
.
AutoScaleMode
=
System
.
Windows
.
Forms
.
AutoScaleMode
.
Font
;
this
.
ClientSize
=
new
System
.
Drawing
.
Size
(
1375
,
729
);
this
.
Controls
.
Add
(
this
.
label5
);
this
.
Controls
.
Add
(
this
.
chbZxing
);
this
.
Controls
.
Add
(
this
.
btnScanTest
);
this
.
Controls
.
Add
(
this
.
button1
);
this
.
Controls
.
Add
(
this
.
txtParamPath
);
this
.
Controls
.
Add
(
this
.
label4
);
this
.
Controls
.
Add
(
this
.
chbUseParam
);
this
.
Controls
.
Add
(
this
.
btnAn
);
this
.
Controls
.
Add
(
this
.
btnLight
);
this
.
Controls
.
Add
(
this
.
cmbCodeType
);
this
.
Controls
.
Add
(
this
.
cmbCamera
);
this
.
Controls
.
Add
(
this
.
label2
);
...
...
@@ -403,8 +358,6 @@
this
.
Controls
.
Add
(
this
.
btnLearn
);
this
.
Controls
.
Add
(
this
.
btnbarCode
);
this
.
Controls
.
Add
(
this
.
hWindowControl1
);
this
.
Controls
.
Add
(
this
.
btnGray
);
this
.
Controls
.
Add
(
this
.
btnErZhi
);
this
.
Controls
.
Add
(
this
.
txtResult
);
this
.
Controls
.
Add
(
this
.
pictureBox1
);
this
.
Controls
.
Add
(
this
.
btnSelImage
);
...
...
@@ -430,8 +383,6 @@
private
System
.
Windows
.
Forms
.
Button
btnSelImage
;
private
System
.
Windows
.
Forms
.
PictureBox
pictureBox1
;
private
System
.
Windows
.
Forms
.
TextBox
txtResult
;
private
System
.
Windows
.
Forms
.
Button
btnErZhi
;
private
System
.
Windows
.
Forms
.
Button
btnGray
;
private
HalconDotNet
.
HWindowControl
hWindowControl1
;
private
System
.
Windows
.
Forms
.
Button
btnbarCode
;
private
System
.
Windows
.
Forms
.
Button
btnLearn
;
...
...
@@ -446,13 +397,12 @@
private
System
.
Windows
.
Forms
.
Label
label2
;
private
System
.
Windows
.
Forms
.
ComboBox
cmbCodeType
;
private
System
.
Windows
.
Forms
.
Label
label3
;
private
System
.
Windows
.
Forms
.
Button
btnAn
;
private
System
.
Windows
.
Forms
.
CheckBox
chbUseParam
;
private
System
.
Windows
.
Forms
.
TextBox
txtParamPath
;
private
System
.
Windows
.
Forms
.
Label
label4
;
private
System
.
Windows
.
Forms
.
Button
btnLight
;
private
System
.
Windows
.
Forms
.
Button
button1
;
private
System
.
Windows
.
Forms
.
Button
btnScanTest
;
private
System
.
Windows
.
Forms
.
CheckBox
chbZxing
;
private
System
.
Windows
.
Forms
.
Label
label5
;
}
}
RC1266-AutoCountMachine/source/CodeLibrary/FrmCodeDecode.cs
查看文件 @
dc2183d
...
...
@@ -14,6 +14,7 @@ using System.Text;
using
System.Threading.Tasks
;
using
System.Windows.Forms
;
using
System.IO
;
using
System.Threading
;
namespace
CodeLibrary
{
...
...
@@ -64,6 +65,12 @@ namespace CodeLibrary
pictureBox1
.
Image
.
Dispose
();
pictureBox1
.
Image
=
null
;
}
if
(
HDCodeLearnHelper
.
DefaultImage
!=
null
)
{
HDCodeLearnHelper
.
DefaultImage
.
Dispose
();
HDCodeLearnHelper
.
DefaultImage
=
null
;
}
}
catch
(
Exception
ex
)
{
...
...
@@ -72,8 +79,6 @@ namespace CodeLibrary
}
private
void
LoadCamera
()
{
// string[] camerName = BaslerCamera.Instance.CameraName;
// baslerNameList.AddRange(camerName);
cmbCamera
.
Items
.
Clear
();
Camera
.
Type
=
CameraType
.
HIK
;
Camera
.
_cam
.
Load
();
...
...
@@ -82,12 +87,6 @@ namespace CodeLibrary
cmbCamera
.
Items
.
Add
(
str
);
}
//camerName = HIKCamera.Instance.CameraName;
//hikNameList.AddRange(camerName);
//foreach (string str in camerName)
//{
// cmbCamera.Items.Add(str);
//}
if
(
cmbCamera
.
Items
.
Count
>
0
)
{
cmbCamera
.
SelectedIndex
=
0
;
...
...
@@ -97,7 +96,7 @@ namespace CodeLibrary
{
System
.
Windows
.
Forms
.
OpenFileDialog
openDialog
=
new
System
.
Windows
.
Forms
.
OpenFileDialog
();
openDialog
.
Title
=
selImage
;
openDialog
.
Filter
=
"(*.jpg;*.png;*.bmp
)|*.jpg;*.png;*.bmp
"
;
openDialog
.
Filter
=
"(*.jpg;*.png;*.bmp
;*.hobj)|*.jpg;*.png;*.bmp;*.hobj
"
;
// openDialog.Filter = "All Supported Images (*.bmp;*.dib;*.rle;*.gif;*.jpg;*.png)|*.bmp;*.dib;*.rle;*.gif;*.jpg;*.png|Bitmaps (*.bmp;*.dib;*.rle)|*.bmp;*.dib;*.rle|Graphics Interchange Format (*.gif)|*.gif|Joint Photographic Experts (*.jpg)|*.jpg|Portable Network Graphics (*.png)|*.png|All Files (*.*)|*.*";
//openDialog.DefaultExt = "png";
System
.
Windows
.
Forms
.
DialogResult
result
=
openDialog
.
ShowDialog
();
...
...
@@ -112,9 +111,33 @@ namespace CodeLibrary
MessageBox
.
Show
(
imageIsNull
);
}
ClearPicImg
();
if
(
openDialog
.
FileName
.
EndsWith
(
".hobj"
))
{
HObject
hObject
=
null
;
HOperatorSet
.
GenEmptyObj
(
out
hObject
);
hObject
.
ReadObject
(
openDialog
.
FileName
);
if
(
hObject
!=
null
)
{
HDCodeLearnHelper
.
DefaultImage
=
hObject
;
ShowImage
(
hObject
);
}
else
{
MessageBox
.
Show
(
"读取文件失败:"
+
openDialog
.
FileName
);
}
}
else
{
//读取图片内容
Image
img
=
(
Image
)
Image
.
FromFile
(
filename
).
Clone
();
pictureBox1
.
Image
=
img
;
Bitmap
bitmap
=
new
Bitmap
(
pictureBox1
.
Image
);
HObject
hoimg
;
HDCodeHelper
.
Bitmap2HObjectBpp24
(
bitmap
,
out
hoimg
);
HDCodeLearnHelper
.
DefaultImage
=
hoimg
;
ShowImage
(
hoimg
);
}
}
private
void
btnErZhi_Click
(
object
sender
,
EventArgs
e
)
...
...
@@ -149,6 +172,7 @@ namespace CodeLibrary
foreach
(
CodeInfo
code
in
list
)
{
txtResult
.
Text
+=
"\r\n"
+
""
+
code
.
CodeType
+
" (X:"
+
code
.
X
+
",Y:"
+
code
.
Y
+
") "
+
code
.
CodeStr
;
txtResult
.
Text
+=
"\r\n"
+
""
+
code
.
CodeType
+
" (X:"
+
code
.
X
+
",Y:"
+
code
.
Y
+
") "
+
code
.
GetCodeStr
();
}
}
else
...
...
@@ -159,7 +183,7 @@ namespace CodeLibrary
private
void
btnbarCode_Click
(
object
sender
,
EventArgs
e
)
{
if
(
pictureBox1
.
Image
==
null
)
if
(
HDCodeLearnHelper
.
Default
Image
==
null
)
{
MessageBox
.
Show
(
selImage
,
title
,
MessageBoxButtons
.
OK
,
MessageBoxIcon
.
Error
);
return
;
...
...
@@ -168,14 +192,20 @@ namespace CodeLibrary
txtResult
.
Text
=
""
;
stopwatch
.
Restart
();
HDCodeHelper
.
HalconWindow
=
this
.
hWindowControl1
.
HalconWindow
;
if
(
chbZxing
.
Checked
)
{
if
(
pictureBox1
.
Image
==
null
)
{
MessageBox
.
Show
(
selImage
,
title
,
MessageBoxButtons
.
OK
,
MessageBoxIcon
.
Error
);
return
;
}
Bitmap
map
=
new
Bitmap
(
pictureBox1
.
Image
);
//if (chbZxing.Checked)
//{
// zxingDecode(map, "barcode");
//}
//else
zxingDecode
(
map
,
"barcode"
);
}
else
{
List
<
CodeInfo
>
result
=
HDCodeHelper
.
DecodeBarCode
(
map
);
List
<
CodeInfo
>
result
=
HDCodeHelper
.
DecodeBarCode
(
HDCodeLearnHelper
.
DefaultImage
);
ShowCode
(
result
);
txtResult
.
Text
+=
"\r\n elapsed time:"
+
stopwatch
.
Elapsed
.
ToString
();
}
...
...
@@ -199,65 +229,63 @@ namespace CodeLibrary
private
void
btnDCode_Click
(
object
sender
,
EventArgs
e
)
{
if
(
pictureBox1
.
Image
==
null
)
{
MessageBox
.
Show
(
selImage
,
title
,
MessageBoxButtons
.
OK
,
MessageBoxIcon
.
Error
);
return
;
}
int
count
=
cmbCount
.
SelectedIndex
;
txtResult
.
Text
=
""
;
stopwatch
.
Restart
();
Bitmap
map
=
new
Bitmap
(
pictureBox1
.
Image
);
HObject
ho_image
=
HDCodeHelper
.
Bitmap2HObjectBpp24
(
map
);
//
Bitmap map = new Bitmap(pictureBox1.Image);
//
HObject ho_image = HDCodeHelper.Bitmap2HObjectBpp24(map);
txtResult
.
Text
+=
"\r\n elapsed time:"
+
stopwatch
.
Elapsed
.
ToString
();
hWindowControl1
.
HalconWindow
.
SetPart
(
0
,
0
,
map
.
Height
,
map
.
Width
);
HOperatorSet
.
DispObj
(
ho_image
,
hWindowControl1
.
HalconWindow
);
ShowImage
(
ho_image
);
//
hWindowControl1.HalconWindow.SetPart(0, 0, map.Height, map.Width);
//
HOperatorSet.DispObj(ho_image, hWindowControl1.HalconWindow);
//
ShowImage(ho_image);
HDCodeHelper
.
HalconWindow
=
this
.
hWindowControl1
.
HalconWindow
;
string
codeParamPath
=
HDCodeHelper
.
GetCodeParamFilePath
(
cmbCodeType
.
Text
);
if
(
chbUseParam
.
Checked
.
Equals
(
false
))
{
codeParamPath
=
""
;
}
//if (chbZxing.Checked)
//{
// zxingDecode(map, cmbCodeType.Text);
//}
//else
if
(
chbZxing
.
Checked
)
{
if
(
pictureBox1
.
Image
==
null
)
{
MessageBox
.
Show
(
selImage
,
title
,
MessageBoxButtons
.
OK
,
MessageBoxIcon
.
Error
);
return
;
}
Bitmap
map
=
new
Bitmap
(
pictureBox1
.
Image
);
zxingDecode
(
map
,
cmbCodeType
.
Text
);
}
else
{
if
(
HDCodeLearnHelper
.
DefaultImage
==
null
)
{
MessageBox
.
Show
(
selImage
,
title
,
MessageBoxButtons
.
OK
,
MessageBoxIcon
.
Error
);
return
;
}
List
<
CodeInfo
>
codeList
=
new
List
<
CodeInfo
>();
if
(
cmbCodeType
.
Text
.
ToLower
().
Equals
(
"barcode"
))
{
codeList
=
HDCodeHelper
.
DecodeBarCode
(
ho_i
mage
);
codeList
=
HDCodeHelper
.
DecodeBarCode
(
HDCodeLearnHelper
.
DefaultI
mage
);
}
else
{
codeList
=
HDCodeHelper
.
DecodeCode
(
ho_i
mage
,
count
,
codeParamPath
,
cmbCodeType
.
Text
);
codeList
=
HDCodeHelper
.
DecodeCode
(
HDCodeLearnHelper
.
DefaultI
mage
,
count
,
codeParamPath
,
cmbCodeType
.
Text
);
}
//if (codeList.Count <= 0)
//{
// zxingDecode(map, cmbCodeType.Text);
//}
//else
{
ShowCode
(
codeList
);
txtResult
.
Text
+=
"\r\n elapsed time:"
+
stopwatch
.
Elapsed
.
ToString
();
}
}
}
private
void
zxingDecode
(
Bitmap
map
,
string
type
)
{
//
List<string> results = ZXingCodeHelper.DeCodes(map, type);
List
<
string
>
results
=
ZXingCodeHelper
.
DeCodes
(
map
,
type
);
//
txtResult.Text = " zxing decode:";
//
foreach (string code in results)
//
{
//
txtResult.Text += "\r\n" + "\r\n" + code;
//
}
//
txtResult.Text += "\r\n \r\n elapsed time:" + stopwatch.Elapsed.ToString();
txtResult
.
Text
=
" zxing decode:"
;
foreach
(
string
code
in
results
)
{
txtResult
.
Text
+=
"\r\n"
+
"\r\n"
+
code
;
}
txtResult
.
Text
+=
"\r\n \r\n elapsed time:"
+
stopwatch
.
Elapsed
.
ToString
();
}
private
void
btnClearLog_Click
(
object
sender
,
EventArgs
e
)
...
...
@@ -265,7 +293,7 @@ namespace CodeLibrary
HDLogUtil
.
ClearLog
();
txtResult
.
Text
=
""
;
}
private
Bitmap
GetCameraBitmap
()
private
HObject
GetCameraBitmap
()
{
try
{
...
...
@@ -276,27 +304,12 @@ namespace CodeLibrary
MessageBox
.
Show
(
selCamera
);
return
null
;
}
//if (baslerNameList.Contains(camerName))
//{
// BaslerCamera.Instance.Open(camerName);
// BaslerCamera.Instance.GrabOne();
// Bitmap bitmap = BaslerCamera.Instance.Image;
// BaslerCamera.Instance.Close();
// return bitmap;
//}
//else
//{
// HIKCamera.Instance.Open(camerName);
// HIKCamera.Instance.GrabOne();
// Bitmap bitmap = HIKCamera.Instance.Image;
// HIKCamera.Instance.Close();
// return bitmap;
//}
Bitmap
map
=
Camera
.
_cam
.
GrabOneImage
(
camerName
);
if
(
map
==
null
)
HObject
map
;
map
=
Camera
.
_cam
.
CaptureOnImage
(
camerName
);
if
(
map
==
null
)
{
Camera
.
_cam
.
Close
(
camerName
);
map
=
Camera
.
_cam
.
GrabOneImage
(
camerName
);
map
=
Camera
.
_cam
.
CaptureOnImage
(
camerName
);
}
return
map
;
}
...
...
@@ -310,14 +323,38 @@ namespace CodeLibrary
{
try
{
Bitmap
bitmap
=
GetCameraBitmap
();
if
(!
chbZxing
.
Checked
)
{
HObject
bitmap
=
GetCameraBitmap
();
if
(
bitmap
!=
null
)
{
HDLogUtil
.
info
(
"从相机【"
+
cmbCamera
.
Text
+
"】获取到一张图片"
);
ClearPicImg
();
pictureBox1
.
Image
=
(
Image
)
bitmap
.
Clone
();
//
pictureBox1.Image = (Image)bitmap.Clone();
//HObject hoImage = HDCodeHelper.Bitmap2HObjectBpp24(bitmap);
//HDCodeLearnHelper.DefaultImage = hoImage;
HDCodeLearnHelper
.
DefaultImage
=
bitmap
;
ShowImage
(
bitmap
);
}
}
else
{
int
index
=
cmbCamera
.
SelectedIndex
;
string
camerName
=
cmbCamera
.
Text
;
if
(
index
<
0
)
{
MessageBox
.
Show
(
selCamera
);
return
;
}
Bitmap
bitmap
=
Camera
.
_cam
.
GrabOneImage
(
camerName
);
if
(
bitmap
!=
null
)
{
HDLogUtil
.
info
(
"从相机【"
+
cmbCamera
.
Text
+
"】获取到一张图片"
);
ClearPicImg
();
pictureBox1
.
Image
=
(
Image
)
bitmap
.
Clone
();
////HObject hoImage = HDCodeHelper.Bitmap2HObjectBpp24(bitmap);
//HDCodeLearnHelper.DefaultImage = bitmap;
//ShowImage(bitmap);
}
}
}
catch
(
Exception
ex
)
...
...
@@ -396,7 +433,8 @@ namespace CodeLibrary
stopwatch
.
Restart
();
testCount
++;
Bitmap
map
=
new
Bitmap
(
pictureBox1
.
Image
);
HObject
ho_image
=
HDCodeHelper
.
Bitmap2HObjectBpp24
(
map
);
HObject
ho_image
;
HDCodeHelper
.
Bitmap2HObjectBpp24
(
map
,
out
ho_image
);
txtResult
.
Text
+=
"\r\n elapsed time:"
+
stopwatch
.
Elapsed
.
ToString
();
hWindowControl1
.
HalconWindow
.
SetPart
(
0
,
0
,
map
.
Height
,
map
.
Width
);
...
...
@@ -433,73 +471,101 @@ namespace CodeLibrary
Camera
.
_cam
.
CloseAll
();
}
//private void btnScanTest_Click(object sender, EventArgs e)
//{
// Image img = (Image)Image.FromFile(@"E:\GigE-MV-CE200-10GC (00E06252332)\16-05-15-984.bmp").Clone();
// using (Bitmap bitmap = new Bitmap(img))
// //using (Bitmap bitmap = GetCameraBitmap())
// {
// if (bitmap != null)
// {
// System.Threading.Thread.Sleep(1);
// //转换托盘大概100-150ms,不打印日志
// HalconDotNet.HObject ho_Image = HDCodeHelper.Bitmap2HObjectBpp24(bitmap);
// // LogUtil.info(" 相机【" + cameraName + "】转换图片完成,开始扫码");
// List<CodeInfo> cc = new List<CodeInfo>();
// string str = "";
// List<string> codeTypeList = new List<string>(HDCodeLearnHelper.codeTypeList);
// string r = "";
// int count = cmbCount.SelectedIndex;
// foreach (string codeType in codeTypeList)
// {
// //判断是否是一维码
// if (codeType.ToLower().Equals("barcode"))
// {
// cc = HDCodeHelper.DecodeBarCode(ho_Image);
// }
// else
// {
// string codeParamPath = HDCodeHelper.GetCodeParamFilePath(codeType);
// cc = HDCodeHelper.DecodeCode(ho_Image, count, codeParamPath, codeType);
// }
// foreach (CodeInfo c in cc)
// {
// r += (c.CodeStr) + "##";
// }
// }
// MessageBox.Show(r);
// // ShowCode(cc);
// ho_Image.Dispose();
// bitmap.Dispose();
// }
// }
//}
private
void
btnScanTest_Click
(
object
sender
,
EventArgs
e
)
{
//using (Bitmap bitmap = GetCameraBitmap())
//{
// if (bitmap != null)
// { int index = cmbCamera.SelectedIndex;
this
.
Enabled
=
false
;
this
.
Cursor
=
Cursors
.
WaitCursor
;
Task
.
Factory
.
StartNew
(
delegate
{
//ScanTest();
ScanDemo
(
100
);
});
}
private
void
ScanTest
()
{
for
(
int
index
=
1
;
index
<=
200
;
index
++)
{
try
{
label5
.
Text
=
"扫码测试_"
+
index
;
int
name
=
(
index
%
3
)
+
1
;
string
filename
=
@"F:\test\" + name + "
.
hobj
";
if
(!
File
.
Exists
(
filename
))
{
continue
;
}
ClearPicImg
();
if
(
filename
.
EndsWith
(
".hobj"
))
{
HObject
hObject
=
null
;
HOperatorSet
.
GenEmptyObj
(
out
hObject
);
hObject
.
ReadObject
(
filename
);
if
(
hObject
!=
null
)
{
HDCodeLearnHelper
.
DefaultImage
=
hObject
;
ShowImage
(
hObject
);
}
else
{
MessageBox
.
Show
(
"读取文件失败:"
+
filename
);
}
}
else
{
//读取图片内容
Image
img
=
(
Image
)
Image
.
FromFile
(
filename
).
Clone
();
pictureBox1
.
Image
=
img
;
Bitmap
bitmap
=
new
Bitmap
(
pictureBox1
.
Image
);
HObject
hoimg
;
HDCodeHelper
.
Bitmap2HObjectBpp24
(
bitmap
,
out
hoimg
);
HDCodeLearnHelper
.
DefaultImage
=
hoimg
;
ShowImage
(
hoimg
);
}
btnDCode_Click
(
null
,
null
);
Thread
.
Sleep
(
100
);
}
catch
(
Exception
ex
)
{
HDLogUtil
.
error
(
"ScanTest["
+
index
+
"]出错:"
+
ex
.
ToString
());
}
}
this
.
Enabled
=
true
;
this
.
Cursor
=
Cursors
.
Default
;
}
private
void
ScanDemo
(
int
whileCount
=
1
)
{
string
camerName
=
cmbCamera
.
Text
;
if
(
cmbCamera
.
SelectedIndex
<
0
)
{
MessageBox
.
Show
(
selCamera
);
//MessageBox.Show(selCamera);
txtResult
.
Text
=
selCamera
;
return
;
}
HDLogUtil
.
info
(
"获取图片完成,开始转换图片,并扫码"
);
//System.Threading.Thread.Sleep(1);
////转换托盘大概100-150ms,不打印日志
//Bitmap bit = new Bitmap(bitmap);
//HalconDotNet.HObject ho_Image = HDCodeHelper.Bitmap2HObjectBpp24(bit);
HObject
ho_Image
=
Camera
.
_cam
.
CaptureOnImage
(
camerName
);
HDLogUtil
.
info
(
" 相机【"
+
camerName
+
"】转换图片完成,开始扫码"
);
List
<
CodeInfo
>
cc
=
new
List
<
CodeInfo
>();
string
str
=
""
;
List
<
string
>
codeTypeList
=
new
List
<
string
>(
HDCodeLearnHelper
.
codeTypeList
);
string
r
=
""
;
int
count
=
cmbCount
.
SelectedIndex
;
List
<
string
>
codeTypeList
=
new
List
<
string
>(
HDCodeLearnHelper
.
codeTypeList
);
Task
task
=
null
;
for
(
int
index
=
1
;
index
<=
whileCount
;
index
++)
{
//task = Task.Factory.StartNew(delegate {
label5
.
Text
=
"扫码测试_"
+
index
;
HObject
ho_Image
=
null
;
try
{
ho_Image
=
Camera
.
_cam
.
CaptureOnImage
(
camerName
);
if
(
ho_Image
!=
null
)
{
//ClearPicImg();
// ShowImage(ho_Image);
HDLogUtil
.
info
(
" 相机【"
+
camerName
+
"】获取图片完成,开始扫码"
);
List
<
CodeInfo
>
cc
=
new
List
<
CodeInfo
>();
string
r
=
"ScanDemo["
+
index
+
"]\r\n"
;
foreach
(
string
codeType
in
codeTypeList
)
{
//判断是否是一维码
...
...
@@ -512,20 +578,41 @@ namespace CodeLibrary
string
codeParamPath
=
HDCodeHelper
.
GetCodeParamFilePath
(
codeType
);
cc
=
HDCodeHelper
.
DecodeCode
(
ho_Image
,
count
,
codeParamPath
,
codeType
);
}
foreach
(
CodeInfo
c
in
cc
)
{
r
+=
(
c
.
CodeStr
)
+
"##"
;
}
}
MessageBox
.
Show
(
r
);
// ShowCode(cc);
//MessageBox.Show(r);
txtResult
.
Text
=
r
;
}
}
catch
(
Exception
ex
)
{
HDLogUtil
.
error
(
"ScanDemo["
+
index
+
"]出错:"
+
ex
.
ToString
());
}
finally
{
if
(
ho_Image
!=
null
)
{
ho_Image
.
Dispose
();
//bitmap.Dispose();
// }
//}
ho_Image
=
null
;
}
}
//});
//task.Wait();
//GC.Collect();
//Thread.Sleep(100);
//task.Dispose();
Thread
.
Sleep
(
5
);
}
this
.
Enabled
=
true
;
this
.
Cursor
=
Cursors
.
Default
;
}
private
void
btnCopyN_Click
(
object
sender
,
EventArgs
e
)
{
string
text
=
cmbCamera
.
Text
;
...
...
RC1266-AutoCountMachine/source/CodeLibrary/FrmCodeLearn.Designer.cs
查看文件 @
dc2183d
...
...
@@ -66,9 +66,9 @@
//
this
.
btnStop
.
Anchor
=
((
System
.
Windows
.
Forms
.
AnchorStyles
)((
System
.
Windows
.
Forms
.
AnchorStyles
.
Top
|
System
.
Windows
.
Forms
.
AnchorStyles
.
Right
)));
this
.
btnStop
.
Font
=
new
System
.
Drawing
.
Font
(
"微软雅黑"
,
9F
,
System
.
Drawing
.
FontStyle
.
Regular
,
System
.
Drawing
.
GraphicsUnit
.
Point
,
((
byte
)(
134
)));
this
.
btnStop
.
Location
=
new
System
.
Drawing
.
Point
(
949
,
51
);
this
.
btnStop
.
Location
=
new
System
.
Drawing
.
Point
(
949
,
49
);
this
.
btnStop
.
Name
=
"btnStop"
;
this
.
btnStop
.
Size
=
new
System
.
Drawing
.
Size
(
144
,
3
5
);
this
.
btnStop
.
Size
=
new
System
.
Drawing
.
Size
(
144
,
3
2
);
this
.
btnStop
.
TabIndex
=
3
;
this
.
btnStop
.
Text
=
"结束学习"
;
this
.
btnStop
.
UseVisualStyleBackColor
=
true
;
...
...
@@ -78,9 +78,9 @@
//
this
.
btnOpen
.
Anchor
=
((
System
.
Windows
.
Forms
.
AnchorStyles
)((
System
.
Windows
.
Forms
.
AnchorStyles
.
Top
|
System
.
Windows
.
Forms
.
AnchorStyles
.
Right
)));
this
.
btnOpen
.
Font
=
new
System
.
Drawing
.
Font
(
"微软雅黑"
,
9F
,
System
.
Drawing
.
FontStyle
.
Regular
,
System
.
Drawing
.
GraphicsUnit
.
Point
,
((
byte
)(
134
)));
this
.
btnOpen
.
Location
=
new
System
.
Drawing
.
Point
(
949
,
1
3
);
this
.
btnOpen
.
Location
=
new
System
.
Drawing
.
Point
(
949
,
1
2
);
this
.
btnOpen
.
Name
=
"btnOpen"
;
this
.
btnOpen
.
Size
=
new
System
.
Drawing
.
Size
(
144
,
3
5
);
this
.
btnOpen
.
Size
=
new
System
.
Drawing
.
Size
(
144
,
3
2
);
this
.
btnOpen
.
TabIndex
=
1
;
this
.
btnOpen
.
Text
=
"开始学习"
;
this
.
btnOpen
.
UseVisualStyleBackColor
=
true
;
...
...
@@ -104,9 +104,9 @@
//
this
.
btnExit
.
Anchor
=
((
System
.
Windows
.
Forms
.
AnchorStyles
)((
System
.
Windows
.
Forms
.
AnchorStyles
.
Top
|
System
.
Windows
.
Forms
.
AnchorStyles
.
Right
)));
this
.
btnExit
.
Font
=
new
System
.
Drawing
.
Font
(
"微软雅黑"
,
9F
,
System
.
Drawing
.
FontStyle
.
Regular
,
System
.
Drawing
.
GraphicsUnit
.
Point
,
((
byte
)(
134
)));
this
.
btnExit
.
Location
=
new
System
.
Drawing
.
Point
(
1096
,
51
);
this
.
btnExit
.
Location
=
new
System
.
Drawing
.
Point
(
1096
,
49
);
this
.
btnExit
.
Name
=
"btnExit"
;
this
.
btnExit
.
Size
=
new
System
.
Drawing
.
Size
(
110
,
3
5
);
this
.
btnExit
.
Size
=
new
System
.
Drawing
.
Size
(
110
,
3
2
);
this
.
btnExit
.
TabIndex
=
6
;
this
.
btnExit
.
Text
=
"退出"
;
this
.
btnExit
.
UseVisualStyleBackColor
=
true
;
...
...
@@ -115,7 +115,7 @@
// label1
//
this
.
label1
.
Font
=
new
System
.
Drawing
.
Font
(
"微软雅黑"
,
9F
,
System
.
Drawing
.
FontStyle
.
Regular
,
System
.
Drawing
.
GraphicsUnit
.
Point
,
((
byte
)(
134
)));
this
.
label1
.
Location
=
new
System
.
Drawing
.
Point
(
3
,
1
9
);
this
.
label1
.
Location
=
new
System
.
Drawing
.
Point
(
3
,
1
8
);
this
.
label1
.
Name
=
"label1"
;
this
.
label1
.
Size
=
new
System
.
Drawing
.
Size
(
110
,
20
);
this
.
label1
.
TabIndex
=
7
;
...
...
@@ -138,16 +138,16 @@
this
.
cmbCodeType
.
DropDownStyle
=
System
.
Windows
.
Forms
.
ComboBoxStyle
.
DropDownList
;
this
.
cmbCodeType
.
Font
=
new
System
.
Drawing
.
Font
(
"微软雅黑"
,
9F
,
System
.
Drawing
.
FontStyle
.
Regular
,
System
.
Drawing
.
GraphicsUnit
.
Point
,
((
byte
)(
134
)));
this
.
cmbCodeType
.
FormattingEnabled
=
true
;
this
.
cmbCodeType
.
Location
=
new
System
.
Drawing
.
Point
(
1
31
,
53
);
this
.
cmbCodeType
.
Location
=
new
System
.
Drawing
.
Point
(
1
17
,
53
);
this
.
cmbCodeType
.
Name
=
"cmbCodeType"
;
this
.
cmbCodeType
.
Size
=
new
System
.
Drawing
.
Size
(
1
86
,
25
);
this
.
cmbCodeType
.
Size
=
new
System
.
Drawing
.
Size
(
1
63
,
25
);
this
.
cmbCodeType
.
TabIndex
=
10
;
this
.
cmbCodeType
.
SelectedIndexChanged
+=
new
System
.
EventHandler
(
this
.
cmbCodeType_SelectedIndexChanged
);
//
// label2
//
this
.
label2
.
Font
=
new
System
.
Drawing
.
Font
(
"微软雅黑"
,
9F
,
System
.
Drawing
.
FontStyle
.
Regular
,
System
.
Drawing
.
GraphicsUnit
.
Point
,
((
byte
)(
134
)));
this
.
label2
.
Location
=
new
System
.
Drawing
.
Point
(
3
,
5
7
);
this
.
label2
.
Location
=
new
System
.
Drawing
.
Point
(
3
,
5
5
);
this
.
label2
.
Name
=
"label2"
;
this
.
label2
.
Size
=
new
System
.
Drawing
.
Size
(
110
,
20
);
this
.
label2
.
TabIndex
=
9
;
...
...
@@ -177,7 +177,7 @@
// lblCount
//
this
.
lblCount
.
Font
=
new
System
.
Drawing
.
Font
(
"微软雅黑"
,
9F
,
System
.
Drawing
.
FontStyle
.
Regular
,
System
.
Drawing
.
GraphicsUnit
.
Point
,
((
byte
)(
134
)));
this
.
lblCount
.
Location
=
new
System
.
Drawing
.
Point
(
323
,
58
);
this
.
lblCount
.
Location
=
new
System
.
Drawing
.
Point
(
286
,
55
);
this
.
lblCount
.
Name
=
"lblCount"
;
this
.
lblCount
.
Size
=
new
System
.
Drawing
.
Size
(
112
,
20
);
this
.
lblCount
.
TabIndex
=
13
;
...
...
@@ -210,7 +210,7 @@
"18"
,
"19"
,
"20"
});
this
.
cmbCount
.
Location
=
new
System
.
Drawing
.
Point
(
4
41
,
54
);
this
.
cmbCount
.
Location
=
new
System
.
Drawing
.
Point
(
4
04
,
53
);
this
.
cmbCount
.
Name
=
"cmbCount"
;
this
.
cmbCount
.
Size
=
new
System
.
Drawing
.
Size
(
64
,
25
);
this
.
cmbCount
.
TabIndex
=
14
;
...
...
@@ -228,9 +228,9 @@
//
this
.
btnClearLog
.
Anchor
=
((
System
.
Windows
.
Forms
.
AnchorStyles
)((
System
.
Windows
.
Forms
.
AnchorStyles
.
Top
|
System
.
Windows
.
Forms
.
AnchorStyles
.
Right
)));
this
.
btnClearLog
.
Font
=
new
System
.
Drawing
.
Font
(
"微软雅黑"
,
9F
,
System
.
Drawing
.
FontStyle
.
Regular
,
System
.
Drawing
.
GraphicsUnit
.
Point
,
((
byte
)(
134
)));
this
.
btnClearLog
.
Location
=
new
System
.
Drawing
.
Point
(
1096
,
1
3
);
this
.
btnClearLog
.
Location
=
new
System
.
Drawing
.
Point
(
1096
,
1
2
);
this
.
btnClearLog
.
Name
=
"btnClearLog"
;
this
.
btnClearLog
.
Size
=
new
System
.
Drawing
.
Size
(
110
,
3
5
);
this
.
btnClearLog
.
Size
=
new
System
.
Drawing
.
Size
(
110
,
3
2
);
this
.
btnClearLog
.
TabIndex
=
16
;
this
.
btnClearLog
.
Text
=
"清理日志"
;
this
.
btnClearLog
.
UseVisualStyleBackColor
=
true
;
...
...
@@ -242,7 +242,7 @@
this
.
chbTest
.
Checked
=
true
;
this
.
chbTest
.
CheckState
=
System
.
Windows
.
Forms
.
CheckState
.
Checked
;
this
.
chbTest
.
Font
=
new
System
.
Drawing
.
Font
(
"微软雅黑"
,
9F
,
System
.
Drawing
.
FontStyle
.
Regular
,
System
.
Drawing
.
GraphicsUnit
.
Point
,
((
byte
)(
134
)));
this
.
chbTest
.
Location
=
new
System
.
Drawing
.
Point
(
53
1
,
56
);
this
.
chbTest
.
Location
=
new
System
.
Drawing
.
Point
(
53
2
,
55
);
this
.
chbTest
.
Name
=
"chbTest"
;
this
.
chbTest
.
Size
=
new
System
.
Drawing
.
Size
(
147
,
21
);
this
.
chbTest
.
TabIndex
=
17
;
...
...
@@ -253,7 +253,7 @@
// btnSelImage
//
this
.
btnSelImage
.
Font
=
new
System
.
Drawing
.
Font
(
"微软雅黑"
,
9F
,
System
.
Drawing
.
FontStyle
.
Regular
,
System
.
Drawing
.
GraphicsUnit
.
Point
,
((
byte
)(
134
)));
this
.
btnSelImage
.
Location
=
new
System
.
Drawing
.
Point
(
783
,
1
5
);
this
.
btnSelImage
.
Location
=
new
System
.
Drawing
.
Point
(
783
,
1
2
);
this
.
btnSelImage
.
Name
=
"btnSelImage"
;
this
.
btnSelImage
.
Size
=
new
System
.
Drawing
.
Size
(
160
,
32
);
this
.
btnSelImage
.
TabIndex
=
19
;
...
...
@@ -286,7 +286,7 @@
//
this
.
chbUseCamera
.
AutoSize
=
true
;
this
.
chbUseCamera
.
Font
=
new
System
.
Drawing
.
Font
(
"微软雅黑"
,
9F
,
System
.
Drawing
.
FontStyle
.
Regular
,
System
.
Drawing
.
GraphicsUnit
.
Point
,
((
byte
)(
134
)));
this
.
chbUseCamera
.
Location
=
new
System
.
Drawing
.
Point
(
53
1
,
18
);
this
.
chbUseCamera
.
Location
=
new
System
.
Drawing
.
Point
(
53
2
,
18
);
this
.
chbUseCamera
.
Name
=
"chbUseCamera"
;
this
.
chbUseCamera
.
Size
=
new
System
.
Drawing
.
Size
(
123
,
21
);
this
.
chbUseCamera
.
TabIndex
=
21
;
...
...
@@ -297,7 +297,7 @@
// btnDelOld
//
this
.
btnDelOld
.
Font
=
new
System
.
Drawing
.
Font
(
"微软雅黑"
,
9F
,
System
.
Drawing
.
FontStyle
.
Regular
,
System
.
Drawing
.
GraphicsUnit
.
Point
,
((
byte
)(
134
)));
this
.
btnDelOld
.
Location
=
new
System
.
Drawing
.
Point
(
783
,
53
);
this
.
btnDelOld
.
Location
=
new
System
.
Drawing
.
Point
(
783
,
49
);
this
.
btnDelOld
.
Name
=
"btnDelOld"
;
this
.
btnDelOld
.
Size
=
new
System
.
Drawing
.
Size
(
160
,
32
);
this
.
btnDelOld
.
TabIndex
=
22
;
...
...
@@ -320,12 +320,13 @@
//
this
.
chbHalcon
.
AutoSize
=
true
;
this
.
chbHalcon
.
Font
=
new
System
.
Drawing
.
Font
(
"微软雅黑"
,
9F
,
System
.
Drawing
.
FontStyle
.
Regular
,
System
.
Drawing
.
GraphicsUnit
.
Point
,
((
byte
)(
134
)));
this
.
chbHalcon
.
Location
=
new
System
.
Drawing
.
Point
(
3
44
,
19
);
this
.
chbHalcon
.
Location
=
new
System
.
Drawing
.
Point
(
3
74
,
18
);
this
.
chbHalcon
.
Name
=
"chbHalcon"
;
this
.
chbHalcon
.
Size
=
new
System
.
Drawing
.
Size
(
115
,
21
);
this
.
chbHalcon
.
TabIndex
=
24
;
this
.
chbHalcon
.
Text
=
"Halcon获取图片"
;
this
.
chbHalcon
.
UseVisualStyleBackColor
=
true
;
this
.
chbHalcon
.
Visible
=
false
;
this
.
chbHalcon
.
CheckedChanged
+=
new
System
.
EventHandler
(
this
.
chbHalcon_CheckedChanged
);
//
// cmbCamera
...
...
@@ -333,9 +334,9 @@
this
.
cmbCamera
.
DropDownStyle
=
System
.
Windows
.
Forms
.
ComboBoxStyle
.
DropDownList
;
this
.
cmbCamera
.
Font
=
new
System
.
Drawing
.
Font
(
"微软雅黑"
,
9F
,
System
.
Drawing
.
FontStyle
.
Regular
,
System
.
Drawing
.
GraphicsUnit
.
Point
,
((
byte
)(
134
)));
this
.
cmbCamera
.
FormattingEnabled
=
true
;
this
.
cmbCamera
.
Location
=
new
System
.
Drawing
.
Point
(
1
31
,
17
);
this
.
cmbCamera
.
Location
=
new
System
.
Drawing
.
Point
(
1
17
,
16
);
this
.
cmbCamera
.
Name
=
"cmbCamera"
;
this
.
cmbCamera
.
Size
=
new
System
.
Drawing
.
Size
(
186
,
25
);
this
.
cmbCamera
.
Size
=
new
System
.
Drawing
.
Size
(
351
,
25
);
this
.
cmbCamera
.
TabIndex
=
25
;
//
// FrmCodeLearn
...
...
RC1266-AutoCountMachine/source/CodeLibrary/FrmCodeLearn.cs
查看文件 @
dc2183d
...
...
@@ -27,9 +27,10 @@ namespace CodeLibrary
private
string
title
=
CodeResourceControl
.
GetString
(
CodeResourceControl
.
title
,
"提示"
);
private
string
imageIsNull
=
CodeResourceControl
.
GetString
(
CodeResourceControl
.
imageIsNull
,
"获取二维码图片为空"
);
private
string
sureDelete
=
CodeResourceControl
.
GetString
(
CodeResourceControl
.
sureDelete
,
"确定删除文件:"
);
private
Bitmap
GetCameraBitmap
()
private
HObject
GetCameraImg
()
{
Bitmap
bitmap
=
null
;
HObject
ho_image
=
null
;
//Bitmap bitmap = null;
int
index
=
cmbCamera
.
SelectedIndex
;
string
camerName
=
cmbCamera
.
Text
;
if
(
index
<
0
)
...
...
@@ -37,22 +38,8 @@ namespace CodeLibrary
MessageBox
.
Show
(
selCamera
);
return
null
;
}
//if (baslerNameList.Contains(camerName))
//{
// BaslerCamera.Instance.Open(camerName);
// BaslerCamera.Instance.GrabOne();
// bitmap = BaslerCamera.Instance.Image;
// BaslerCamera.Instance.Close();
//}
//else
//{
// HIKCamera.Instance.Open(camerName);
// HIKCamera.Instance.GrabOne();
// bitmap = HIKCamera.Instance.Image;
// HIKCamera.Instance.Close();
//}
bitmap
=
Camera
.
_cam
.
GrabOneImage
(
camerName
);
return
bitmap
;
ho_image
=
Camera
.
_cam
.
CaptureOnImage
(
camerName
);
return
ho_image
;
}
private
void
btnOpen_Click
(
object
sender
,
EventArgs
e
)
{
...
...
@@ -73,14 +60,16 @@ namespace CodeLibrary
}
else
{
Bitmap
bitmap
=
GetCameraBitmap
();
if
(
bitmap
!=
null
)
// Bitmap bitmap = GetCameraBitmap();
HObject
ho_Image
=
GetCameraImg
();
if
(
ho_Image
!=
null
)
{
HDLogUtil
.
info
(
"从相机【"
+
cmbCamera
.
Text
+
"】获取到一张图片"
);
ClearPicImg
();
pictureBox1
.
Image
=
(
Image
)
bitmap
.
Clone
();
HObject
hoImage
=
HDCodeHelper
.
Bitmap2HObjectBpp24
(
bitmap
);
HDCodeLearnHelper
.
DefaultImage
=
hoImage
;
//pictureBox1.Image = (Image)bitmap.Clone();
//HObject hoImage = HDCodeHelper.Bitmap2HObjectBpp24(bitmap);
HDCodeLearnHelper
.
DefaultImage
=
ho_Image
;
ShowImage
(
ho_Image
);
}
else
{
...
...
@@ -97,8 +86,10 @@ namespace CodeLibrary
return
;
}
Bitmap
bitmap
=
new
Bitmap
(
pictureBox1
.
Image
);
HObject
Image
=
HDCodeHelper
.
Bitmap2HObjectBpp24
(
bitmap
);
HObject
Image
;
HDCodeHelper
.
Bitmap2HObjectBpp24
(
bitmap
,
out
Image
);
HDCodeLearnHelper
.
DefaultImage
=
Image
;
ShowImage
(
Image
);
}
Task
.
Factory
.
StartNew
(
delegate
()
{
...
...
@@ -108,20 +99,11 @@ namespace CodeLibrary
}
private
void
LoadCamera
()
{
//string[] camerName = BaslerCamera.Instance.CameraName;
//baslerNameList.AddRange(camerName);
cmbCamera
.
Items
.
Clear
();
foreach
(
string
str
in
Camera
.
_cam
.
Name
)
{
cmbCamera
.
Items
.
Add
(
str
);
}
//camerName = HIKCamera.Instance.CameraName;
//hikNameList.AddRange(camerName);
//foreach (string str in camerName)
//{
// cmbCamera.Items.Add(str);
//}
if
(
cmbCamera
.
Items
.
Count
>
0
)
{
cmbCamera
.
SelectedIndex
=
0
;
...
...
@@ -306,5 +288,15 @@ namespace CodeLibrary
cmbCamera
.
Visible
=
true
;
}
}
public
void
ShowImage
(
HObject
ho_Image
)
{
HTuple
width
,
height
;
HOperatorSet
.
GetImageSize
(
ho_Image
,
out
width
,
out
height
);
int
dWidth
=
(
int
)
width
.
D
;
int
dHeight
=
(
int
)
height
.
D
;
this
.
hWindowControl1
.
HalconWindow
.
SetPart
(
0
,
0
,
dHeight
,
dWidth
);
HOperatorSet
.
DispObj
(
ho_Image
,
hWindowControl1
.
HalconWindow
);
}
}
}
RC1266-AutoCountMachine/source/CodeLibrary/HDCodeHelper.cs
查看文件 @
dc2183d
...
...
@@ -5,7 +5,9 @@ using System.Drawing;
using
System.Drawing.Imaging
;
using
System.IO
;
using
System.Linq
;
using
System.Runtime.ExceptionServices
;
using
System.Text
;
using
System.Text.RegularExpressions
;
using
System.Threading.Tasks
;
using
System.Windows.Forms
;
namespace
CodeLibrary
...
...
@@ -41,19 +43,20 @@ namespace CodeLibrary
}
return
DecodeCode
(
ho_Image
,
codeCount
,
codeParamPath
,
paramType
);
}
/// <summary>
/// 根据图片解析二维码
/// </summary>
/// <param name="map">图片对象</param>
/// <param name="codeCount">二维码数量</param>
/// <param name="codeParamPath">二维码参数路径,""表示不使用参数</param>
/// <param name="paramType">二维码类型,不传类型默认Data Matrix ECC 200</param>
/// <returns>解析到的二维码</returns>
public
static
List
<
CodeInfo
>
DecodeCode
(
Bitmap
map
,
int
codeCount
,
string
codeParamPath
,
params
string
[]
paramType
)
{
HObject
ho_image
=
Bitmap2HObjectBpp24
(
map
);
return
DecodeCode
(
ho_image
,
codeCount
,
codeParamPath
,
paramType
);
}
///// <summary>
///// 根据图片解析二维码
///// </summary>
///// <param name="map">图片对象</param>
///// <param name="codeCount">二维码数量</param>
///// <param name="codeParamPath">二维码参数路径,""表示不使用参数</param>
///// <param name="paramType">二维码类型,不传类型默认Data Matrix ECC 200</param>
///// <returns>解析到的二维码</returns>
//public static List<CodeInfo> DecodeCode(Bitmap map, int codeCount, string codeParamPath, params string[] paramType)
//{
// HObject ho_image;
// Bitmap2HObjectBpp24(map,out ho_image);
// return DecodeCode(ho_image, codeCount, codeParamPath, paramType);
//}
/// <summary>
/// 根据图片解析二维码
/// </summary>
...
...
@@ -78,9 +81,9 @@ namespace CodeLibrary
}
return
codeList
;
}
public
static
List
<
CodeInfo
>
DecodeCode
(
HObject
ho_Image
,
string
symbolType
,
string
hv_model_path
,
int
codeCount
,
int
timeOut
=
20
00
)
public
static
List
<
CodeInfo
>
DecodeCode
(
HObject
ho_Image
,
string
symbolType
,
string
hv_model_path
,
int
codeCount
,
int
timeOut
=
15
00
)
{
HDLogUtil
.
info
(
" DecodeCode["
+
symbolType
+
"]["
+
hv_model_path
+
"]["
+
codeCount
+
"] 开始"
);
HDLogUtil
.
debug
(
" DecodeCode["
+
symbolType
+
"]["
+
hv_model_path
+
"]["
+
codeCount
+
"] 开始"
);
List
<
CodeInfo
>
codeList
=
new
List
<
CodeInfo
>();
try
{
...
...
@@ -121,6 +124,8 @@ namespace CodeLibrary
ShowImage
(
HalconWindow
,
ho_Image
,
ho_SymbolXLDs
);
}
HOperatorSet
.
ClearDataCode2dModel
(
hv_DataCodeHandle
);
//HOperatorSet.ClearObj
if
(
hv_DecodedDataStrings
.
Length
>
0
)
{
...
...
@@ -141,13 +146,48 @@ namespace CodeLibrary
}
}
}
HDLogUtil
.
info
(
" DecodeCode["
+
symbolType
+
"]["
+
hv_model_path
+
"]["
+
codeCount
+
"] 结束,返回数量:"
+
codeList
.
Count
);
HDLogUtil
.
debug
(
" DecodeCode["
+
symbolType
+
"]["
+
hv_model_path
+
"]["
+
codeCount
+
"] 结束,返回数量:"
+
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
;
}
catch
(
Exception
ex
)
{
HDLogUtil
.
error
(
"DecodeCode出错:"
+
ex
.
ToString
());
HDLogUtil
.
info
(
" DecodeCode["
+
symbolType
+
"]["
+
hv_model_path
+
"]["
+
codeCount
+
"] 结束,返回数量:"
+
codeList
.
Count
);
HDLogUtil
.
debug
(
" DecodeCode["
+
symbolType
+
"]["
+
hv_model_path
+
"]["
+
codeCount
+
"] 结束,返回数量:"
+
codeList
.
Count
);
return
codeList
;
}
...
...
@@ -191,9 +231,9 @@ namespace CodeLibrary
/// <summary>
/// 将BitMap转换为HObject对象
/// </summary>
public
static
HObject
Bitmap2HObjectBpp24
(
Bitmap
bmp
)
public
static
bool
Bitmap2HObjectBpp24
(
Bitmap
bmp
,
out
HObject
ho_Image
)
{
HObject
ho_Image
=
null
;
ho_Image
=
null
;
try
{
HOperatorSet
.
GenEmptyObj
(
out
ho_Image
);
...
...
@@ -204,13 +244,14 @@ namespace CodeLibrary
HOperatorSet
.
GenImageInterleaved
(
out
ho_Image
,
srcBmpData
.
Scan0
,
"bgrx"
,
bmp
.
Width
,
bmp
.
Height
,
0
,
"byte"
,
0
,
0
,
0
,
0
,
-
1
,
0
);
bmp
.
UnlockBits
(
srcBmpData
);
return
true
;
}
catch
(
Exception
ex
)
{
HDLogUtil
.
error
(
"将BitMap转换为HObject对象出错:"
+
ex
.
ToString
());
ho_Image
=
null
;
}
return
ho_Image
;
return
false
;
}
internal
static
string
GetCodeParamFilePath
(
string
codeType
)
...
...
@@ -236,11 +277,12 @@ namespace CodeLibrary
HOperatorSet
.
ReadImage
(
out
ho_Image
,
filePath
);
return
DecodeBarCode
(
ho_Image
);
}
public
static
List
<
CodeInfo
>
DecodeBarCode
(
Bitmap
bitmap
)
{
HObject
ho_image
=
Bitmap2HObjectBpp24
(
bitmap
);
return
DecodeBarCode
(
ho_image
);
}
//public static List<CodeInfo> DecodeBarCode(Bitmap bitmap)
//{
// HObject ho_image;
// Bitmap2HObjectBpp24(bitmap,out ho_image);
// return DecodeBarCode(ho_image);
//}
public
static
List
<
CodeInfo
>
DecodeBarCode
(
HObject
ho_Image
)
{
...
...
@@ -300,13 +342,226 @@ namespace CodeLibrary
}
}
HOperatorSet
.
ClearBarCodeModel
(
hv_BarCodeHandle
);
if
(
hv_Area
!=
null
)
{
hv_Area
.
UnPinTuple
();
}
if
(
hv_Row1
!=
null
)
{
hv_Row1
.
UnPinTuple
();
}
if
(
hv_Column
!=
null
)
{
hv_Column
.
UnPinTuple
();
}
if
(
hv_Orientation
!=
null
)
{
hv_Orientation
.
UnPinTuple
();
}
if
(
ho_GrayImage
!=
null
)
{
ho_GrayImage
.
Dispose
();
ho_GrayImage
=
null
;
}
if
(
ho_SymbolRegions
!=
null
)
{
ho_SymbolRegions
.
Dispose
();
ho_SymbolRegions
=
null
;
}
return
codeList
;
}
catch
(
Exception
ex
)
{
return
codeList
;
}
}
public
static
void
CloseCamera
(
string
cameraName
)
{
Camera
.
_cam
.
Close
(
cameraName
);
}
public
static
void
CloseAllCamera
()
{
Camera
.
_cam
.
CloseAll
();
}
private
static
int
ScanCount
=
0
;
[
HandleProcessCorruptedStateExceptions
]
public
static
List
<
string
>
CameraScan
(
string
deviceName
,
List
<
string
>
codeTypeList
,
int
codeCount
,
params
string
[]
cameraList
)
{
List
<
string
>
codeList
=
new
List
<
string
>();
if
(
cameraList
==
null
||
cameraList
.
Length
<=
0
)
{
return
codeList
;
}
try
{
foreach
(
string
cameraName
in
cameraList
)
{
if
(
cameraName
.
Trim
().
Equals
(
""
))
{
continue
;
}
ScanCount
++;
DateTime
startTime
=
DateTime
.
Now
;
if
(
deviceName
!=
""
)
{
HDLogUtil
.
debug
(
deviceName
+
" 【"
+
cameraName
+
"】开始取图片"
);
}
HalconDotNet
.
HObject
ho_Image
=
null
;
bool
findRightCode
=
false
;
try
{
ho_Image
=
Camera
.
_cam
.
CaptureOnImage
(
cameraName
);
if
(
ho_Image
==
null
)
{
HDLogUtil
.
error
(
deviceName
+
" 【"
+
cameraName
+
"】取图片失败["
+
Camera
.
_cam
.
ErrInfo
+
"],关闭相机"
);
CloseCamera
(
cameraName
);
continue
;
}
HDLogUtil
.
debug
(
deviceName
+
" 【"
+
cameraName
+
"】取图片完成,开始扫码"
);
List
<
CodeInfo
>
cc
=
new
List
<
CodeInfo
>();
string
r
=
""
;
foreach
(
string
codeType
in
codeTypeList
)
{
//判断是否是一维码
if
(
codeType
.
ToLower
().
Equals
(
"barcode"
))
{
cc
=
HDCodeHelper
.
DecodeBarCode
(
ho_Image
);
}
else
{
cc
=
HDCodeHelper
.
DecodeCode
(
ho_Image
,
codeType
,
GetCodeParamFilePath
(
codeType
),
codeCount
,
1500
);
}
foreach
(
CodeInfo
c
in
cc
)
{
string
str
=
ReplaceCode
(
c
.
CodeStr
);
if
(!
codeList
.
Contains
(
str
))
{
codeList
.
Add
(
str
);
r
=
r
+
"##"
+
str
;
if
(!
findRightCode
)
{
findRightCode
=
HasRightCode
(
str
);
}
}
}
}
//if (!findRightCode)
//{
// SaveImageToFile(deviceName, cameraName, ho_Image);
//}
if
(
deviceName
!=
""
||
r
!=
""
)
{
HDLogUtil
.
info
(
deviceName
+
" 【"
+
cameraName
+
"】扫码完成【"
+
GetSpanStr
(
DateTime
.
Now
-
startTime
)
+
"】["
+
findRightCode
+
"]"
+
ScanCount
+
" :"
+
r
);
}
}
catch
(
AccessViolationException
e
)
{
HDLogUtil
.
error
(
deviceName
+
" 扫码出现AccessViolationException异常,关闭相机【"
+
cameraName
+
"】:"
+
e
.
ToString
());
Camera
.
_cam
.
Close
(
cameraName
);
// GC.Collect();
}
catch
(
Exception
ex
)
{
HDLogUtil
.
error
(
deviceName
+
" 扫码出错:"
+
ex
.
ToString
());
}
finally
{
if
(
ho_Image
!=
null
)
{
ho_Image
.
Dispose
();
}
//int value = ScanCount % 30;
//if (value.Equals(0))
//{
// GC.Collect();
// GC.WaitForPendingFinalizers();
//}
}
}
}
catch
(
AccessViolationException
e
)
{
HDLogUtil
.
error
(
deviceName
+
" 扫码出现AccessViolationException异常,关闭所有相机:"
+
e
.
ToString
());
Camera
.
_cam
.
CloseAll
();
//GC.Collect();
}
catch
(
Exception
ex
)
{
HDLogUtil
.
error
(
deviceName
+
" 扫码出错:"
+
ex
.
ToString
());
}
return
codeList
;
}
private
static
string
GetSpanStr
(
TimeSpan
span
)
{
//return Convert.ToDateTime(span.ToString()).ToString("HH:mm:ss");
string
seconds
=
Math
.
Round
(
span
.
TotalSeconds
%
60
,
1
).
ToString
();
if
(
seconds
.
IndexOf
(
"."
)
>=
0
)
{
seconds
=
seconds
.
ToString
().
PadLeft
(
4
,
'0'
);
}
else
{
seconds
=
seconds
.
ToString
().
PadLeft
(
2
,
'0'
);
}
return
span
.
Hours
.
ToString
().
PadLeft
(
2
,
'0'
)
+
":"
+
span
.
Minutes
.
ToString
().
PadLeft
(
2
,
'0'
)
+
":"
+
seconds
;
}
private
static
string
ReplaceCode
(
string
message
)
{
message
=
message
.
Trim
();
message
=
message
.
Replace
(
"\r"
,
""
);
message
=
message
.
Replace
(
"\n"
,
""
);
char
a
=
(
char
)
02
;
message
=
message
.
Replace
(
a
.
ToString
(),
""
);
message
=
message
.
Trim
();
System
.
Text
.
ASCIIEncoding
asciiEncoding
=
new
System
.
Text
.
ASCIIEncoding
();
byte
[]
bytes
=
asciiEncoding
.
GetBytes
(
message
);
List
<
byte
>
newBytes
=
new
List
<
byte
>();
foreach
(
byte
by
in
bytes
)
{
int
value
=
(
int
)
by
;
if
(
value
.
Equals
(
24
)
||
value
.
Equals
(
30
)
||
value
.
Equals
(
29
)
||
value
.
Equals
(
4
))
{
continue
;
}
if
(!
value
.
Equals
(
24
))
{
newBytes
.
Add
(
by
);
}
}
message
=
asciiEncoding
.
GetString
(
newBytes
.
ToArray
());
return
message
;
}
private
static
bool
HasRightCode
(
params
string
[]
codes
)
{
//分号分割后长度=4,L,E,B,R
try
{
foreach
(
string
code
in
codes
)
{
string
[]
strarray
=
code
.
Split
(
';'
);
if
(
strarray
.
Length
==
4
)
{
if
(
strarray
[
0
].
StartsWith
(
"L"
)
&&
strarray
[
1
].
StartsWith
(
"E"
)
&&
strarray
[
2
].
StartsWith
(
"B"
))
{
return
true
;
}
}
}
}
catch
(
Exception
ex
)
{
}
return
false
;
}
}
...
...
@@ -332,5 +587,41 @@ public class CodeInfo
this
.
X
=
x
;
this
.
Y
=
y
;
}
public
string
GetCodeStr
()
{
return
Gb2312Correct
(
CodeStr
);
}
/// <summary>
/// 判断字符串中是否包含中文
/// </summary>
/// <param name="str">需要判断的字符串</param>
/// <returns>判断结果</returns>
public
static
bool
HasChinese
(
string
str
)
{
return
Regex
.
IsMatch
(
str
,
@"[\u4e00-\u9fa5]"
);
}
/// <summary>
/// utf8文字用gb2312格式显示时候乱码,需要转换为gb2312
/// </summary>
/// <param name="text"></param>
/// <returns></returns>
public
static
string
Gb2312Correct
(
string
text
)
{
if
(
HasChinese
(
text
)
==
false
)
{
return
text
;
}
//声明字符集
System
.
Text
.
Encoding
utf8
,
gb2312
;
//utf8
utf8
=
System
.
Text
.
Encoding
.
GetEncoding
(
"utf-8"
);
//gb2312
gb2312
=
System
.
Text
.
Encoding
.
GetEncoding
(
"gb2312"
);
byte
[]
gb
;
gb
=
utf8
.
GetBytes
(
text
);
gb
=
System
.
Text
.
Encoding
.
Convert
(
utf8
,
gb2312
,
gb
);
//返回转换后的字符
return
gb2312
.
GetString
(
gb
);
}
}
}
RC1266-AutoCountMachine/source/CodeLibrary/HDCodeLearnHelper.cs
查看文件 @
dc2183d
...
...
@@ -219,7 +219,7 @@ namespace CodeLibrary
CodeResultAdd
(
hv_DecodedDataStrings
,
codeType
,
"学习"
);
}
ShowImage
(
hv_ExpDefaultWinHandle
,
ho_Image
,
ho_SymbolXLDs
);
ho_Image
.
Dispose
();
}
if
(
findCode
.
Count
>=
codeCount
||
stopWatch
.
ElapsedMilliseconds
>
timeOutMs
)
{
...
...
@@ -251,6 +251,7 @@ namespace CodeLibrary
{
CodeResultAdd
(
hv_DecodedDataStrings
,
codeType
,
"识别"
);
}
ho_Image
.
Dispose
();
}
if
(
findCode
.
Count
>=
codeCount
||
stopWatch
.
ElapsedMilliseconds
>
timeOutMs
)
{
...
...
@@ -264,7 +265,40 @@ namespace CodeLibrary
CloseCamera
(
cameraName
);
ho_SymbolXLDs
.
Dispose
();
StopLearn
();
if
(
hv_code_type
!=
null
)
{
hv_code_type
.
UnPinTuple
();
}
if
(
hv_model_path
!=
null
)
{
hv_model_path
.
UnPinTuple
();
}
if
(
hv_train_first
!=
null
)
{
hv_train_first
.
UnPinTuple
();
}
if
(
hv_ResultHandles
!=
null
)
{
hv_ResultHandles
.
UnPinTuple
();
}
if
(
hv_DataCodeHandle
!=
null
)
{
hv_DataCodeHandle
.
UnPinTuple
();
}
if
(
hv_DecodedDataStrings
!=
null
)
{
hv_DecodedDataStrings
.
UnPinTuple
();
}
if
(
hv_GenParamNames
!=
null
)
{
hv_GenParamNames
.
UnPinTuple
();
}
if
(
hv_ModelBeforeTraining
!=
null
)
{
hv_ModelBeforeTraining
.
UnPinTuple
();
}
return
true
;
}
catch
(
Exception
ex
)
...
...
RC1266-AutoCountMachine/source/CodeLibrary/ZXingCodeHelper.cs
查看文件 @
dc2183d
...
...
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using
System.Drawing
;
using
System.Linq
;
using
System.Text
;
using
System.Text.RegularExpressions
;
using
System.Threading.Tasks
;
using
ZXing
;
using
ZXing.Common
;
...
...
@@ -202,5 +203,8 @@ namespace CodeLibrary
}
}
}
}
RC1266-AutoCountMachine/source/CodeLibrary/camera/Basler.cs
查看文件 @
dc2183d
...
...
@@ -4,6 +4,7 @@ using System.Drawing;
using
System.Drawing.Imaging
;
using
System.Collections.Generic
;
using
HalconDotNet
;
using
System.Runtime.InteropServices
;
namespace
CodeLibrary
{
...
...
@@ -227,9 +228,65 @@ namespace CodeLibrary
}
return
null
;
}
public
override
HObject
CaptureOnImage
(
string
name
)
public
override
HObject
CaptureOnImage
(
string
name
)
{
return
null
;
HObject
hoImage
=
null
;
int
index
=
cameraName
.
FindIndex
(
s
=>
s
==
name
);
if
(
index
==
-
1
)
{
_errInfo
=
name
+
"Not find"
;
return
hoImage
;
}
if
(
cameraCurr
[
index
]
!=
null
)
{
}
else
{
Open
(
index
);
}
try
{
if
(
cameraCurr
[
index
]
!=
null
)
{
cameraCurr
[
index
].
Parameters
[
PLCamera
.
AcquisitionMode
].
SetValue
(
PLCamera
.
AcquisitionMode
.
SingleFrame
);
//cameraCur.StreamGrabber.Start();
//IGrabResult grabResult = cameraCur.StreamGrabber.RetrieveResult(5000, TimeoutHandling.ThrowException);
IGrabResult
grabResult
=
cameraCurr
[
index
].
StreamGrabber
.
GrabOne
(
5000
);
if
(!
grabResult
.
IsValid
||
!
grabResult
.
GrabSucceeded
)
{
_errInfo
=
grabResult
.
ErrorDescription
;
return
hoImage
;
}
//相机像素数据
byte
[]
buffer
=
grabResult
.
PixelData
as
byte
[];
//锁定像素数据
GCHandle
hand
=
GCHandle
.
Alloc
(
buffer
,
GCHandleType
.
Pinned
);
//获取像素数据的指针
IntPtr
pr
=
hand
.
AddrOfPinnedObject
();
//HalconDotNet.HObject image;
//转成灰度图HOjbect
HalconDotNet
.
HOperatorSet
.
GenImage1
(
out
hoImage
,
new
HalconDotNet
.
HTuple
(
"byte"
),
grabResult
.
Width
,
grabResult
.
Height
,
pr
);
//释放内存
if
(
hand
.
IsAllocated
)
hand
.
Free
();
_errInfo
=
"OK"
;
return
hoImage
;
}
}
catch
(
Exception
ex
)
{
_errInfo
=
ex
.
Message
;
return
hoImage
;
}
finally
{
// cameraCurr[index].MV_CC_StopGrabbing_NET();
}
return
hoImage
;
}
}
...
...
RC1266-AutoCountMachine/source/CodeLibrary/camera/Common.cs
查看文件 @
dc2183d
...
...
@@ -112,7 +112,7 @@ namespace CodeLibrary
// public abstract bool GrabContinuous(int index);
// public abstract void GrabStop(int index);
public
abstract
Bitmap
GrabOneImage
(
string
name
);
public
abstract
HObject
CaptureOnImage
(
string
name
);
public
abstract
HObject
CaptureOnImage
(
string
name
);
}
}
RC1266-AutoCountMachine/source/CodeLibrary/camera/HIK.cs
查看文件 @
dc2183d
...
...
@@ -110,6 +110,7 @@ namespace CodeLibrary
if
(
rtn
!=
MyCamera
.
MV_OK
)
{
_errInfo
=
"Load failed"
;
HDLogUtil
.
error
(
" Load camera error : "
+
_errInfo
);
return
false
;
}
...
...
@@ -123,12 +124,14 @@ namespace CodeLibrary
IntPtr
buffer
=
Marshal
.
UnsafeAddrOfPinnedArrayElement
(
device
.
SpecialInfo
.
stGigEInfo
,
0
);
MyCamera
.
MV_GIGE_DEVICE_INFO
gigeInfo
=
(
MyCamera
.
MV_GIGE_DEVICE_INFO
)
Marshal
.
PtrToStructure
(
buffer
,
typeof
(
MyCamera
.
MV_GIGE_DEVICE_INFO
));
s
=
"GigE:"
+
gigeInfo
.
chModelName
+
" ("
+
gigeInfo
.
chSerialNumber
+
")"
;
//Marshal.FreeHGlobal(buffer);
}
else
if
(
device
.
nTLayerType
==
MyCamera
.
MV_USB_DEVICE
)
{
IntPtr
buffer
=
Marshal
.
UnsafeAddrOfPinnedArrayElement
(
device
.
SpecialInfo
.
stUsb3VInfo
,
0
);
MyCamera
.
MV_USB3_DEVICE_INFO
usbInfo
=
(
MyCamera
.
MV_USB3_DEVICE_INFO
)
Marshal
.
PtrToStructure
(
buffer
,
typeof
(
MyCamera
.
MV_USB3_DEVICE_INFO
));
s
=
"USB:"
+
usbInfo
.
chModelName
+
" ("
+
usbInfo
.
chSerialNumber
+
")"
;
//Marshal.FreeHGlobal(buffer);
}
cameraName
.
Add
(
s
);
}
...
...
@@ -155,6 +158,7 @@ namespace CodeLibrary
if
(
index
<
0
||
index
>=
_count
)
{
_errInfo
=
"Not find"
;
HDLogUtil
.
error
(
"open camera "
+
index
+
" error : "
+
_errInfo
);
return
false
;
}
if
(
cameraCurr
[
index
]
!=
null
)
Close
(
index
);
...
...
@@ -171,6 +175,7 @@ namespace CodeLibrary
{
cameraCurr
[
index
].
MV_CC_DestroyDevice_NET
();
_errInfo
=
"Can not open"
;
HDLogUtil
.
error
(
"open camera "
+
index
+
" error : "
+
_errInfo
);
return
false
;
}
...
...
@@ -189,6 +194,7 @@ namespace CodeLibrary
_isOpen
[
index
]
=
true
;
_errInfo
=
"OK"
;
HDLogUtil
.
info
(
"open camera "
+
index
+
_errInfo
);
return
true
;
}
catch
(
Exception
ex
)
...
...
@@ -204,7 +210,7 @@ namespace CodeLibrary
int
n
=
cameraName
.
FindIndex
(
s
=>
s
==
name
);
if
(
n
==
-
1
)
{
_errInfo
=
name
+
"Not find"
;
_errInfo
=
name
+
"
Not find"
;
return
false
;
}
else
...
...
@@ -215,7 +221,8 @@ namespace CodeLibrary
int
n
=
cameraName
.
FindIndex
(
s
=>
s
==
name
);
if
(
n
==
-
1
)
{
_errInfo
=
name
+
"Not find"
;
_errInfo
=
name
+
" Not find"
;
HDLogUtil
.
error
(
"GrabOneImage ["
+
name
+
"] error : "
+
_errInfo
);
return
null
;
}
if
(
cameraCurr
[
n
]
!=
null
)
...
...
@@ -335,66 +342,90 @@ namespace CodeLibrary
return
_image
;
}
}
public
override
HObject
CaptureOnImage
(
string
name
)
public
override
HObject
CaptureOnImage
(
string
name
)
{
HObject
hoImage
=
null
;
int
index
=
cameraName
.
FindIndex
(
s
=>
s
==
name
);
if
(
index
==
-
1
)
{
_errInfo
=
name
+
"Not find"
;
return
null
;
HDLogUtil
.
error
(
"CaptureOnImage ["
+
name
+
"] error : "
+
_errInfo
);
return
hoImage
;
}
if
(
cameraCurr
[
index
]
!=
null
)
{
}
else
{
HDLogUtil
.
info
(
"CaptureOnImage ["
+
name
+
"] 先打开相机 "
);
Open
(
name
);
}
MyCamera
.
MV_FRAME_OUT
FrameInfo
=
new
MyCamera
.
MV_FRAME_OUT
();
try
{
int
rtn
=
cameraCurr
[
index
].
MV_CC_StartGrabbing_NET
();
if
(
rtn
!=
MyCamera
.
MV_OK
)
{
_errInfo
=
"Can not grab one : "
+
rtn
;
return
null
;
HDLogUtil
.
error
(
"CaptureOnImage ["
+
name
+
"] error : "
+
_errInfo
);
return
hoImage
;
}
MyCamera
.
MV_FRAME_OUT
FrameInfo
=
new
MyCamera
.
MV_FRAME_OUT
();
int
nRet
=
cameraCurr
[
index
].
MV_CC_GetImageBuffer_NET
(
ref
FrameInfo
,
1000
);
// ch:获取一帧图像 | en:Get one image
if
(
MyCamera
.
MV_OK
==
nRet
)
{
Console
.
WriteLine
(
"Get Image Buffer:"
+
"Width["
+
Convert
.
ToString
(
FrameInfo
.
stFrameInfo
.
nWidth
)
+
"] , Height["
+
Convert
.
ToString
(
FrameInfo
.
stFrameInfo
.
nHeight
)
HDLogUtil
.
debug
(
"Get Image Buffer:"
+
"Width["
+
Convert
.
ToString
(
FrameInfo
.
stFrameInfo
.
nWidth
)
+
"] , Height["
+
Convert
.
ToString
(
FrameInfo
.
stFrameInfo
.
nHeight
)
+
"] , FrameNum["
+
Convert
.
ToString
(
FrameInfo
.
stFrameInfo
.
nFrameNum
)
+
"]"
);
HObject
ho_Imagetemp
;
HOperatorSet
.
GenImage1
(
out
ho_Imagetemp
,
"byte"
,
FrameInfo
.
stFrameInfo
.
nWidth
,
FrameInfo
.
stFrameInfo
.
nHeight
,
FrameInfo
.
pBufAddr
);
HOperatorSet
.
GenImage1
(
out
hoImage
,
"byte"
,
FrameInfo
.
stFrameInfo
.
nWidth
,
FrameInfo
.
stFrameInfo
.
nHeight
,
FrameInfo
.
pBufAddr
);
//HOperatorSet.GenImage1Extern(out hoImage, "byte", FrameInfo.stFrameInfo.nWidth, FrameInfo.stFrameInfo.nHeight, FrameInfo.pBufAddr, Marshal.GetFunctionPointerForDelegate(callback));
if
(
FrameInfo
.
pBufAddr
!=
IntPtr
.
Zero
)
{
nRet
=
cameraCurr
[
index
].
MV_CC_FreeImageBuffer_NET
(
ref
FrameInfo
);
if
(
nRet
!=
MyCamera
.
MV_OK
)
{
Console
.
WriteLine
(
"Free Image Buffer fail:{0:x8}"
,
nRet
);
HDLogUtil
.
error
(
" ["
+
name
+
"] Free Image Buffer fail:"
+
nRet
);
}
}
return
ho_Imagetemp
;
//return ho_Imagetemp;
return
hoImage
;
}
else
{
Console
.
WriteLine
(
"No data:{0:x8}"
,
nRet
);
HDLogUtil
.
error
(
" ["
+
name
+
"] MV_CC_GetImageBuffer_NET No data: "
+
nRet
);
}
}
catch
(
Exception
ex
)
{
_errInfo
=
ex
.
Message
;
return
null
;
return
hoImage
;
}
finally
{
cameraCurr
[
index
].
MV_CC_StopGrabbing_NET
();
try
{
cameraCurr
[
index
].
MV_CC_FreeImageBuffer_NET
(
ref
FrameInfo
);
}
return
null
;
catch
(
Exception
ex
)
{
HDLogUtil
.
error
(
" ["
+
name
+
"] MV_CC_FreeImageBuffer_NET 出错:"
+
ex
.
ToString
());
}
}
return
hoImage
;
}
HalconDotNet
.
HalconAPI
.
HClearProcCallBack
callback
=
__OnFreeCallBack
;
private
static
void
__OnFreeCallBack
(
IntPtr
pImg
)
{
Marshal
.
FreeHGlobal
(
pImg
);
}
}
...
...
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论