qrcode.cs 3.9 KB
//
//  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();
  }

}