Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
孙克
/
ACSingleStore
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit 08538995
由
几米阳光
编写于
2019-01-09 15:19:05 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
1
1 个父辈
c4766ffe
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
10 行增加
和
325 行删除
source/DeviceLibrary/halcon/CodeManager.cs
source/DeviceLibrary/halcon/HDevelopExport.cs
source/DeviceLibrary/halcon/CodeManager.cs
查看文件 @
0853899
...
...
@@ -41,7 +41,7 @@ namespace OnlineStore.DeviceLibrary
string
[]
codeArray
=
codeStr
.
Split
(
spiltChar
);
foreach
(
string
str
in
codeArray
)
{
LogUtil
.
info
(
"加载到二维码类型:"
+
str
.
Trim
());
LogUtil
.
info
(
"加载到
配置
二维码类型:"
+
str
.
Trim
());
codeTypeList
.
Add
(
str
.
Trim
());
}
...
...
@@ -49,6 +49,15 @@ namespace OnlineStore.DeviceLibrary
hikNameList
.
AddRange
(
names
);
names
=
CodeLibrary
.
BaslerCamera
.
Instance
.
CameraName
;
balserNameList
.
AddRange
(
names
);
foreach
(
string
name
in
hikNameList
)
{
LogUtil
.
info
(
"加载到HIK相机:"
+
name
);
}
foreach
(
string
name
in
balserNameList
)
{
LogUtil
.
info
(
"加载到Balser相机:"
+
name
);
}
CodeLibrary
.
HDCodeLearnHelper
.
LoadConfig
(
nameStr
,
codeStr
);
}
...
...
source/DeviceLibrary/halcon/HDevelopExport.cs
deleted
100644 → 0
查看文件 @
c4766ff
using
HalconDotNet
;
using
OnlineStore.Common
;
using
System
;
using
System.Collections.Generic
;
using
System.IO
;
using
System.Linq
;
using
System.Text
;
using
System.Threading
;
using
System.Windows.Forms
;
namespace
OnlineStore.DeviceLibrary
{
public
class
HDevelopExport
{
/// <summary>
/// 摄像机类别,只保存已经打开的摄像机
/// </summary>
public
static
Dictionary
<
string
,
HTuple
>
cameraHtuple
=
new
Dictionary
<
string
,
HTuple
>();
public
static
List
<
string
>
cameraNameList
=
new
List
<
string
>();
public
static
List
<
string
>
codeTypeList
=
new
List
<
string
>();
private
static
char
spiltChar
=
'#'
;
/// <summary>
/// 初始化摄像机名称和二维码类型
/// </summary>
/// <param name="nameStr">摄像机名称,多个用#分割</param>
/// <param name="codeStr">二维码类型,多个用#分割</param>
public
static
void
LoadConfig
(
string
nameStr
,
string
codeStr
)
{
cameraNameList
=
new
List
<
string
>();
codeTypeList
=
new
List
<
string
>();
try
{
string
[]
nameArray
=
nameStr
.
Split
(
spiltChar
);
foreach
(
string
str
in
nameArray
)
{
LogUtil
.
info
(
"加载到摄像机名称:"
+
str
.
Trim
());
cameraNameList
.
Add
(
str
.
Trim
());
}
string
[]
codeArray
=
codeStr
.
Split
(
spiltChar
);
foreach
(
string
str
in
codeArray
)
{
LogUtil
.
info
(
"加载到二维码类型:"
+
str
.
Trim
());
codeTypeList
.
Add
(
str
.
Trim
());
}
}
catch
(
Exception
ex
)
{
LogUtil
.
error
(
"解析摄像机配置出错:"
+
ex
.
ToString
());
}
}
/// <summary>
/// 扫取二维码,会打开摄像机,正常情况下不关闭摄像机
/// </summary>
/// <returns></returns>
public
static
List
<
string
>
CameraScan
()
{
List
<
string
>
allCodeList
=
new
List
<
string
>();
try
{
//HDevelopExport.CloseAllCamera();
//打开所有摄像机
HDevelopExport
.
OpenAllCamera
();
foreach
(
string
cameraName
in
HDevelopExport
.
cameraNameList
)
{
HObject
ho_Image
=
HDevelopExport
.
GrabImage
(
cameraName
);
List
<
string
>
codeList
=
HDevelopExport
.
GetCode
(
ho_Image
);
allCodeList
.
AddRange
(
codeList
);
}
}
catch
(
Exception
ex
)
{
LogUtil
.
error
(
"从摄像机获取二维码出错:"
+
ex
.
ToString
());
LogUtil
.
error
(
"关闭摄像机"
);
HDevelopExport
.
CloseAllCamera
();
}
return
allCodeList
;
}
public
static
List
<
string
>
GetCode
(
HObject
ho_Image
,
string
symbolType
)
{
List
<
string
>
list
=
new
List
<
string
>();
string
[]
array
=
GetQrCode
(
ho_Image
,
symbolType
);
if
(
array
!=
null
)
{
list
.
AddRange
(
array
);
}
return
list
;
}
public
static
List
<
string
>
GetCode
(
HObject
ho_Image
)
{
List
<
string
>
list
=
new
List
<
string
>();
foreach
(
string
codeType
in
codeTypeList
)
{
string
[]
array
=
GetQrCode
(
ho_Image
,
codeType
);
if
(
array
!=
null
)
{
list
.
AddRange
(
array
);
}
}
return
list
;
}
public
static
string
GetCodeParamFilePath
(
string
codePath
)
{
string
appPath
=
Application
.
StartupPath
;
string
path
=
appPath
+
ConfigAppSettings
.
GetValue
(
Setting_Init
.
CodeParamPath
);
string
filePath
=
path
+
codePath
+
".dcm"
;
if
(
File
.
Exists
(
filePath
))
{
return
filePath
;
}
else
{
return
""
;
}
}
// Procedures
//private static HTuple hv_DataCodeHandle = null;
private
static
string
[]
GetQrCode
(
HObject
ho_Image
,
string
symbolType
)
{
try
{
DateTime
date
=
DateTime
.
Now
;
// Local iconic variables
HObject
ho_SymbolXLDs
;
// Local control variables
HTuple
hv_ResultHandles
=
null
;
//HTuple hv_DataCodeHandle = null, hv_ResultHandles = null;
HTuple
hv_DecodedDataStrings
=
null
;
HTuple
hv_Area
=
null
;
HTuple
hv_Row1
=
null
;
HTuple
hv_Column
=
null
;
HTuple
hv_PointOrder
=
null
;
HTuple
hv_DataCodeHandle
=
null
;
// Initialize local and output iconic variables
HOperatorSet
.
GenEmptyObj
(
out
ho_SymbolXLDs
);
//LogUtil.info("GetQrCode:结束HOperatorSet.GenEmptyObj,已耗时:" + (DateTime.Now - date).ToString());
HOperatorSet
.
CreateDataCode2dModel
(
symbolType
,
"default_parameters"
,
"maximum_recognition"
,
out
hv_DataCodeHandle
);
string
hv_model_path
=
GetCodeParamFilePath
(
symbolType
);
if
(!
hv_model_path
.
Equals
(
""
))
{
HOperatorSet
.
ReadDataCode2dModel
(
hv_model_path
,
out
hv_DataCodeHandle
);
}
else
{
if
(
symbolType
.
Equals
(
"Data Matrix ECC 200"
))
{
HOperatorSet
.
SetDataCode2dParam
(
hv_DataCodeHandle
,
"timeout"
,
500
);
HOperatorSet
.
SetDataCode2dParam
(
hv_DataCodeHandle
,
"mirrored"
,
"no"
);
HOperatorSet
.
SetDataCode2dParam
(
hv_DataCodeHandle
,
"contrast_min"
,
50
);
HOperatorSet
.
SetDataCode2dParam
(
hv_DataCodeHandle
,
"symbol_cols_min"
,
40
);
HOperatorSet
.
SetDataCode2dParam
(
hv_DataCodeHandle
,
"symbol_rows_min"
,
40
);
HOperatorSet
.
SetDataCode2dParam
(
hv_DataCodeHandle
,
"symbol_cols_max"
,
40
);
HOperatorSet
.
SetDataCode2dParam
(
hv_DataCodeHandle
,
"symbol_rows_max"
,
40
);
HOperatorSet
.
SetDataCode2dParam
(
hv_DataCodeHandle
,
"symbol_shape"
,
"square"
);
}
else
{
HOperatorSet
.
SetDataCode2dParam
(
hv_DataCodeHandle
,
"timeout"
,
300
);
HOperatorSet
.
SetDataCode2dParam
(
hv_DataCodeHandle
,
"mirrored"
,
"no"
);
HOperatorSet
.
SetDataCode2dParam
(
hv_DataCodeHandle
,
"model_type"
,
2
);
HOperatorSet
.
SetDataCode2dParam
(
hv_DataCodeHandle
,
"module_gap_max"
,
"no"
);
}
}
//LogUtil.info("GetQrCode:结束HOperatorSet.CreateDataCode2dModel,已耗时:" + (DateTime.Now - date).ToString());
ho_SymbolXLDs
.
Dispose
();
LogUtil
.
debug
(
"GetQrCode:结束ho_SymbolXLDs.Dispose,已耗时:"
+
(
DateTime
.
Now
-
date
).
ToString
());
HOperatorSet
.
FindDataCode2d
(
ho_Image
,
out
ho_SymbolXLDs
,
hv_DataCodeHandle
,
"stop_after_result_num"
,
3
,
out
hv_ResultHandles
,
out
hv_DecodedDataStrings
);
LogUtil
.
debug
(
"GetQrCode:结束HOperatorSet.FindDataCode2d,已耗时:"
+
(
DateTime
.
Now
-
date
).
ToString
());
HOperatorSet
.
AreaCenterXld
(
ho_SymbolXLDs
,
out
hv_Area
,
out
hv_Row1
,
out
hv_Column
,
out
hv_PointOrder
);
//LogUtil.info("GetQrCode:结束HOperatorSet.AreaCenterXld,已耗时:" + (DateTime.Now - date).ToString());
HOperatorSet
.
ClearDataCode2dModel
(
hv_DataCodeHandle
);
//LogUtil.info("GetQrCode:结束HOperatorSet.ClearDataCode2dModel,已耗时:" + (DateTime.Now - date).ToString());
string
[]
resultList
=
hv_DecodedDataStrings
.
SArr
;
if
(
resultList
.
Length
>
0
)
{
for
(
int
i
=
0
;
i
<
hv_DecodedDataStrings
.
SArr
.
Length
;
i
++)
{
try
{
int
x
=
(
int
)
Math
.
Round
(
hv_Column
.
DArr
[
i
]);
int
y
=
(
int
)
Math
.
Round
(
hv_Row1
.
DArr
[
i
]);
string
str
=
"="
+
x
+
"x"
+
y
+
"="
+
hv_DecodedDataStrings
.
SArr
[
i
];
hv_DecodedDataStrings
[
i
]
=
str
;
}
catch
(
Exception
ex
)
{
LogUtil
.
error
(
"处理二维码出错:索引="
+
i
+
","
+
resultList
.
ToString
());
}
}
}
LogUtil
.
debug
(
"GetQrCode:结束处理二维码,已耗时:"
+
(
DateTime
.
Now
-
date
).
ToString
());
return
resultList
;
}
catch
(
Exception
ex
)
{
return
new
string
[]
{
};
}
}
public
static
void
OpenAllCamera
()
{
foreach
(
string
camera
in
cameraNameList
)
{
OpenCamera
(
camera
);
}
}
public
static
void
CloseAllCamera
()
{
foreach
(
string
camera
in
cameraNameList
)
{
CloseCamera
(
camera
);
}
}
/// <summary>
/// 截取二维码,不需要位置
/// </summary>
public
static
string
SubStrCode
(
string
str
)
{
string
[]
array
=
str
.
Split
(
'='
);
if
(
array
.
Length
>=
3
)
{
return
array
[
2
];
}
return
""
;
}
public
static
void
OpenCamera
(
string
cameraAddr
)
{
try
{
//Local iconic variables
HTuple
hv_AcqHandle
=
null
;
if
(
cameraHtuple
.
ContainsKey
(
cameraAddr
))
{
return
;
//CloseCamera(cameraAddr);
}
// HOperatorSet.OpenFramegrabber("DirectShow", 1, 1, 0, 0, 0, 0, "default", 8, "rgb",
//-1, "false", "default", "[0] Integrated Camera", 0, -1, out hv_AcqHandle);
HOperatorSet
.
OpenFramegrabber
(
"GigEVision"
,
0
,
0
,
0
,
0
,
0
,
0
,
"default"
,
-
1
,
"default"
,
-
1
,
"false"
,
"default"
,
cameraAddr
,
0
,
-
1
,
out
hv_AcqHandle
);
//003053242c50_Basler_acA250014gm
//HOperatorSet.GrabImageStart(hv_AcqHandle, -1);
cameraHtuple
.
Add
(
cameraAddr
,
hv_AcqHandle
);
// IsOpen = true;
}
catch
(
Exception
ex
)
{
LogUtil
.
error
(
"打开摄像机失败:"
+
ex
.
ToString
()
+
",调用关闭摄像头"
);
CloseCamera
(
cameraAddr
);
}
}
public
static
void
CloseCamera
(
string
cameraStr
)
{
try
{
if
(
cameraHtuple
.
ContainsKey
(
cameraStr
))
{
HTuple
hv_AcqHandle
=
cameraHtuple
[
cameraStr
];
if
(
hv_AcqHandle
!=
null
)
{
HOperatorSet
.
CloseFramegrabber
(
hv_AcqHandle
);
hv_AcqHandle
=
null
;
}
cameraHtuple
.
Remove
(
cameraStr
);
//IsOpen = false;
}
}
catch
(
Exception
ex
)
{
LogUtil
.
error
(
"关闭摄像机失败:"
+
ex
.
ToString
());
}
}
public
static
HObject
GrabImage
(
string
cameraStr
)
{
HObject
ho_Image
=
null
;
try
{
if
(
cameraHtuple
.
ContainsKey
(
cameraStr
))
{
HTuple
hv_AcqHandle
=
cameraHtuple
[
cameraStr
];
HOperatorSet
.
GenEmptyObj
(
out
ho_Image
);
ho_Image
.
Dispose
();
// HOperatorSet.GrabImageAsync(out ho_Image, hv_AcqHandle,-1);
HOperatorSet
.
GrabImage
(
out
ho_Image
,
hv_AcqHandle
);
}
}
catch
(
Exception
ex
)
{
LogUtil
.
error
(
"获取摄像机【"
+
cameraStr
+
"】的图片出错:"
+
ex
.
ToString
());
}
return
ho_Image
;
}
public
static
bool
IsOpen
(
string
cameraStr
)
{
return
cameraHtuple
.
ContainsKey
(
cameraStr
);
}
}
}
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论