Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
孙克
/
GeneralClassLibrary
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit 2b470fb9
由
LN
编写于
2019-07-30 17:46:09 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
1
1 个父辈
ca0df4ec
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
158 行增加
和
25 行删除
CodeLibraryProject/CodeTest/CodeCreater.cs
CodeLibraryProject/CodeTest/Program.cs
doc/qrcode.cs
CodeLibraryProject/CodeTest/CodeCreater.cs
查看文件 @
2b470fb
...
...
@@ -23,9 +23,9 @@ namespace CodeTest
{
Directory
.
CreateDirectory
(
targetFilePath
);
}
for
(
int
i
=
100000
;
i
<=
100000
+
count
;
i
++)
for
(
int
i
=
100000
;
i
<=
100000
+
count
;
i
++)
{
string
name
=
"pn;"
+
i
.
ToString
().
PadLeft
(
6
,
'0'
)
+
";1000"
;
string
name
=
"pn;
A
"
+
i
.
ToString
().
PadLeft
(
6
,
'0'
)
+
";1000"
;
Bitmap
map
=
ZXingCode
(
name
,
200
,
BarcodeFormat
.
QR_CODE
);
if
(
map
!=
null
)
{
...
...
@@ -83,24 +83,30 @@ namespace CodeTest
// }
// return result;
//}
//public bool DecodeQRCode(Bitmap bmp, out string text)
//{
// DecodingOptions option = new DecodingOptions();
// //option.PossibleFormats = new List<BarcodeFormat>() { BarcodeFormat.QR_CODE, BarcodeFormat.All_1D };
// option.PossibleFormats = new List<BarcodeFormat>() { BarcodeFormat.QR_CODE };
// BarcodeReader br = new BarcodeReader();
// br.Options = option;
// Result rs = br.Decode(bmp);
// if (rs == null)
// {
// text = "";
// return false;
// }
// else
// {
// text = rs.Text;
// return true;
// }
public
static
bool
DecodeQRCode
(
Bitmap
bmp
,
out
string
text
)
{
DecodingOptions
option
=
new
DecodingOptions
();
//option.PossibleFormats = new List<BarcodeFormat>() { BarcodeFormat.QR_CODE, BarcodeFormat.All_1D };
option
.
PossibleFormats
=
new
List
<
BarcodeFormat
>()
{
BarcodeFormat
.
QR_CODE
};
BarcodeReader
br
=
new
BarcodeReader
();
br
.
Options
=
option
;
Result
rs
=
br
.
Decode
(
bmp
);
if
(
rs
==
null
)
{
text
=
""
;
return
false
;
}
else
{
text
=
rs
.
Text
;
return
true
;
}
}
//}
///// <summary>
...
...
@@ -119,5 +125,6 @@ namespace CodeTest
// Bitmap bm = encoder.EncodeImage(text, opt);
// return bm;
//}
}
}
CodeLibraryProject/CodeTest/Program.cs
查看文件 @
2b470fb
...
...
@@ -18,12 +18,17 @@ namespace CodeTest
[
STAThread
]
static
void
Main
()
{
//
CodeCreater.CreateCode(10
0);
Application
.
EnableVisualStyles
();
Application
.
SetCompatibleTextRenderingDefault
(
false
);
HDCodeLearnHelper
.
LoadConfig
(
ConfigAppSettings
.
GetValue
(
Setting_Init
.
CameraName
),
ConfigAppSettings
.
GetValue
(
Setting_Init
.
CodeType
));
Application
.
Run
(
new
FrmCodeDecode
());
//
CodeCreater.CreateCode(1
0);
//
Application.EnableVisualStyles();
//
Application.SetCompatibleTextRenderingDefault(false);
//
HDCodeLearnHelper.LoadConfig(ConfigAppSettings.GetValue(Setting_Init.CameraName), ConfigAppSettings.GetValue(Setting_Init.CodeType));
//
Application.Run(new FrmCodeDecode());
//Application.Run(new FrmTest());
string
filename
=
@"C:/Users/WORK/Desktop/西安二维码/IMG_20190730_165612.jpg"
;
Bitmap
img
=
(
Bitmap
)
Image
.
FromFile
(
filename
).
Clone
();
string
text
;
CodeCreater
.
DecodeQRCode
(
img
,
out
text
);
}
}
...
...
doc/qrcode.cs
0 → 100644
查看文件 @
2b470fb
//
// File generated by HDevelop for HALCON/DOTNET (C#) Version 12.0
//
// This file is intended to be used with the HDevelopTemplate or
// HDevelopTemplateWPF projects located under %HALCONEXAMPLES%\c#
using
System
;
using
System.Windows.Forms
;
using
HalconDotNet
;
public
partial
class
HDevelopExport
{
public
HTuple
hv_ExpDefaultWinHandle
;
public
void
HDevelopStop
()
{
MessageBox
.
Show
(
"Press button to continue"
,
"Program stop"
);
}
// Main procedure
private
void
action
()
{
// Local iconic variables
HObject
ho_Image
=
null
,
ho_SymbolXLDs
=
null
;
// Local control variables
HTuple
hv_code_type
=
null
,
hv_model_path
=
null
;
HTuple
hv_train_first
=
null
,
hv_AcqHandle
=
null
,
hv_DataCodeHandle
=
null
;
HTuple
hv_ResultHandles
=
new
HTuple
(),
hv_DecodedDataStrings
=
new
HTuple
();
HTuple
hv_GenParamNames
=
new
HTuple
(),
hv_ModelBeforeTraining
=
new
HTuple
();
// Initialize local and output iconic variables
HOperatorSet
.
GenEmptyObj
(
out
ho_Image
);
HOperatorSet
.
GenEmptyObj
(
out
ho_SymbolXLDs
);
//Image Acquisition 04: Code generated by Image Acquisition 04
//Image Acquisition 01: Code generated by Image Acquisition 01
hv_code_type
=
"Data Matrix ECC 200"
;
hv_model_path
=
(
"E:/BaiduNetdiskDownload/"
+
hv_code_type
)+
".dcm"
;
hv_train_first
=
1
;
HOperatorSet
.
OpenFramegrabber
(
"GigEVision"
,
0
,
0
,
0
,
0
,
0
,
0
,
"default"
,
-
1
,
"default"
,
-
1
,
"false"
,
"default"
,
"RivetingCode"
,
0
,
-
1
,
out
hv_AcqHandle
);
HOperatorSet
.
GrabImageStart
(
hv_AcqHandle
,
-
1
);
HOperatorSet
.
CreateDataCode2dModel
(
hv_code_type
,
new
HTuple
(),
new
HTuple
(),
out
hv_DataCodeHandle
);
//set_data_code_2d_param (DataCodeHandle, 'strict_model', 'yes')
//set_data_code_2d_param (DataCodeHandle, 'persistence', 0)
//set_data_code_2d_param (DataCodeHandle, 'polarity', 'light_on_dark')
if
((
int
)(
hv_train_first
)
!=
0
)
{
while
((
int
)(
1
)
!=
0
)
{
ho_Image
.
Dispose
();
HOperatorSet
.
GrabImageAsync
(
out
ho_Image
,
hv_AcqHandle
,
-
1
);
//Image Acquisition 04: Do something
//write_image (Image, 'jpeg', 0, 'E:/BaiduNetdiskDownload/fuba2.jpg')
ho_SymbolXLDs
.
Dispose
();
HOperatorSet
.
FindDataCode2d
(
ho_Image
,
out
ho_SymbolXLDs
,
hv_DataCodeHandle
,
"train"
,
"all"
,
out
hv_ResultHandles
,
out
hv_DecodedDataStrings
);
if
((
int
)(
new
HTuple
((
new
HTuple
(
hv_DecodedDataStrings
.
TupleLength
())).
TupleNotEqual
(
0
)))
!=
0
)
{
HOperatorSet
.
QueryDataCode2dParams
(
hv_DataCodeHandle
,
"get_model_params"
,
out
hv_GenParamNames
);
HOperatorSet
.
GetDataCode2dParam
(
hv_DataCodeHandle
,
hv_GenParamNames
,
out
hv_ModelBeforeTraining
);
HDevelopStop
();
}
}
//*参数写入文件
HOperatorSet
.
WriteDataCode2dModel
(
hv_DataCodeHandle
,
hv_model_path
);
HOperatorSet
.
ClearDataCode2dModel
(
hv_DataCodeHandle
);
}
//Read the previously saved data code model
HOperatorSet
.
ReadDataCode2dModel
(
hv_model_path
,
out
hv_DataCodeHandle
);
while
((
int
)(
1
)
!=
0
)
{
ho_Image
.
Dispose
();
HOperatorSet
.
GrabImageAsync
(
out
ho_Image
,
hv_AcqHandle
,
-
1
);
//Image Acquisition 04: Do something
//write_image (Image, 'jpeg', 0, 'E:/BaiduNetdiskDownload/fuba2.jpg')
ho_SymbolXLDs
.
Dispose
();
HOperatorSet
.
FindDataCode2d
(
ho_Image
,
out
ho_SymbolXLDs
,
hv_DataCodeHandle
,
"stop_after_result_num"
,
5
,
out
hv_ResultHandles
,
out
hv_DecodedDataStrings
);
}
HOperatorSet
.
ClearDataCode2dModel
(
hv_DataCodeHandle
);
HOperatorSet
.
CloseFramegrabber
(
hv_AcqHandle
);
ho_Image
.
Dispose
();
ho_SymbolXLDs
.
Dispose
();
}
public
void
InitHalcon
()
{
// Default settings used in HDevelop
HOperatorSet
.
SetSystem
(
"width"
,
512
);
HOperatorSet
.
SetSystem
(
"height"
,
512
);
}
public
void
RunHalcon
(
HTuple
Window
)
{
hv_ExpDefaultWinHandle
=
Window
;
action
();
}
}
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论