Commit 2b470fb9 LN

1

1 个父辈 ca0df4ec
......@@ -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;
//}
}
}
......@@ -18,12 +18,17 @@ namespace CodeTest
[STAThread]
static void Main()
{
//CodeCreater.CreateCode(100);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
HDCodeLearnHelper.LoadConfig(ConfigAppSettings.GetValue(Setting_Init.CameraName), ConfigAppSettings.GetValue(Setting_Init.CodeType));
Application.Run(new FrmCodeDecode());
// CodeCreater.CreateCode(10);
//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);
}
}
......
//
// 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!