using System;
using System.Threading;
using System.Windows.Forms;
using HalconDotNet;
namespace CSharp_Theard
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
// Local iconic variables
HObject ho_Image, ho_SymbolXLDs = null;
// Local control variables
HTuple hv_DataCodeHandle = null, hv_AcqHandle = null;
HTuple hv_Width = null, hv_Height = null, hv_WindowHandle = new HTuple();
HTuple hv_ResultHandles = new HTuple(), hv_DecodedDataStrings = new HTuple();
private void Button1_Click(object sender, EventArgs e)
{
// Initialize local and output iconic variables
HOperatorSet.GenEmptyObj(out ho_Image);
HOperatorSet.GenEmptyObj(out ho_SymbolXLDs);
State();
}
private void State()
{
Thread t = new Thread(new ThreadStart(this.DoSomething));
t.Start();
}
private void DoSomething()
{
HOperatorSet.SetSystem("filename_encoding", "utf8");
//dev_close_window(...);
HOperatorSet.CreateDataCode2dModel("QR Code", new HTuple(), new HTuple(), out hv_DataCodeHandle);
//Image Acquisition 01: Code generated by Image Acquisition 01
HOperatorSet.OpenFramegrabber("DirectShow", 1, 1, 0, 0, 0, 0, "default", 8,
"rgb", -1, "false", "default", "[1] XW500", 0, -1, out hv_AcqHandle);
ho_Image.Dispose();
HOperatorSet.GrabImage(out ho_Image, hv_AcqHandle);
HOperatorSet.GetImageSize(ho_Image, out hv_Width, out hv_Height);
//dev_open_window(...);
HOperatorSet.DispObj(ho_Image, hWindowControl1.HalconWindow);
while ((int)(1) != 0)
{
ho_Image.Dispose();
HOperatorSet.GrabImage(out ho_Image, hv_AcqHandle);
//Image Acquisition 01: Do something
ho_SymbolXLDs.Dispose();
HOperatorSet.FindDataCode2d(ho_Image, out ho_SymbolXLDs, hv_DataCodeHandle,
new HTuple(), new HTuple(), out hv_ResultHandles, out hv_DecodedDataStrings);
MessageBox.Show(hv_DecodedDataStrings);
}
需要识别的二维码

C#的识别结果

Halcon程序
set_system ('filename_encoding', 'utf8')
dev_close_window ()
create_data_code_2d_model ('QR Code', [], [], DataCodeHandle)
* Image Acquisition 01: Code generated by Image Acquisition 01
open_framegrabber ('DirectShow', 1, 1, 0, 0, 0, 0, 'default', 8, 'rgb', -1, 'false', 'default', '[1] XW500', 0, -1, AcqHandle)
grab_image (Image, AcqHandle)
get_image_size (Image, Width, Height)
dev_open_window (0, 0, Width/3, Height/3, 'black', WindowHandle)
dev_display (Image)
while (true)
grab_image (Image, AcqHandle)
* Image Acquisition 01: Do something
find_data_code_2d (Image, SymbolXLDs, DataCodeHandle, [], [], ResultHandles, DecodedDataStrings)
disp_message (WindowHandle, DecodedDataStrings, 'window', 12, 12, 'black', 'true')
endwhile
close_framegrabber (AcqHandle)
Halcon的识别结果
'PN:PESDU0511P1 Package:DFN1006-2\tQty:10000pcs Date code:2051 Lot No:PNS20200903001B02'
想问各位大佬们,为什么会出现这样的问题呀,该如何解决呢?
万分感谢!!!
