halcon-读取表格内容

Posted yqj234

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了halcon-读取表格内容相关的知识,希望对你有一定的参考价值。

//
//  File generated by HDevelop for HALCON/DOTNET (C#) Version 10.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, ho_RegionTable, ho_ConnectedRegionsTable;
    HObject ho_SingleWord=null, ho_Rectangle=null, ho_ImageReduced=null;
    HObject ho_DupImage=null, ho_RegionNumber, ho_ConnectedRegionsNumber;
    HObject ho_SortedRegionsNumber;




    // Local control variables 


    HTuple hv_Width, hv_Height, hv_Number, hv_Index;
    HTuple hv_Row=new HTuple(), hv_Column=new HTuple(), hv_Phi=new HTuple();
    HTuple hv_Length1=new HTuple(), hv_Length2=new HTuple();


    // Initialize local and output iconic variables 
    HOperatorSet.GenEmptyObj(out ho_Image);
    HOperatorSet.GenEmptyObj(out ho_RegionTable);
    HOperatorSet.GenEmptyObj(out ho_ConnectedRegionsTable);
    HOperatorSet.GenEmptyObj(out ho_SingleWord);
    HOperatorSet.GenEmptyObj(out ho_Rectangle);
    HOperatorSet.GenEmptyObj(out ho_ImageReduced);
    HOperatorSet.GenEmptyObj(out ho_DupImage);
    HOperatorSet.GenEmptyObj(out ho_RegionNumber);
    HOperatorSet.GenEmptyObj(out ho_ConnectedRegionsNumber);
    HOperatorSet.GenEmptyObj(out ho_SortedRegionsNumber);


    //dev_close_window(...);
    ho_Image.Dispose();
    HOperatorSet.ReadImage(out ho_Image, "d:/halconimage/table-6.png");
    HOperatorSet.GetImageSize(ho_Image, out hv_Width, out hv_Height);
    //dev_open_window(...);
    HOperatorSet.DispObj(ho_Image, hv_ExpDefaultWinHandle);
    //閫夋嫨琛ㄦ牸
    ho_RegionTable.Dispose();
    HOperatorSet.Threshold(ho_Image, out ho_RegionTable, 100, 216);
    ho_ConnectedRegionsTable.Dispose();
    HOperatorSet.Connection(ho_RegionTable, out ho_ConnectedRegionsTable);
    //select_shape (ConnectedRegionsTable, rectangularityTable, 'rectangularity', 'and', 0, 500)
    HOperatorSet.CountObj(ho_ConnectedRegionsTable, out hv_Number);
    for (hv_Index=1; hv_Index.Continue(hv_Number, 1); hv_Index = hv_Index.TupleAdd(1))
   
      HOperatorSet.ClearWindow(hv_ExpDefaultWinHandle);
      ho_SingleWord.Dispose();
      HOperatorSet.SelectObj(ho_ConnectedRegionsTable, out ho_SingleWord, hv_Index);


      HOperatorSet.SmallestRectangle2(ho_SingleWord, out hv_Row, out hv_Column, out hv_Phi, 
          out hv_Length1, out hv_Length2);
      ho_Rectangle.Dispose();
      HOperatorSet.GenRectangle2(out ho_Rectangle, hv_Row, hv_Column, hv_Phi, hv_Length1, 
          hv_Length2);
      ho_ImageReduced.Dispose();
      HOperatorSet.ReduceDomain(ho_Image, ho_Rectangle, out ho_ImageReduced);
      //dev_get_window(WindowHandle)
      HOperatorSet.DispObj(ho_Image, hv_ExpDefaultWinHandle);
      dev_resize_window_fit_image(ho_Image, 0, 0, -1, -1);
      //dev_open_window(...);
      //dev_get_window(WindowHandle2)
      ho_DupImage.Dispose();
      HOperatorSet.CopyImage(ho_ImageReduced, out ho_DupImage);


      //
      HDevelopStop();
   
    //閫夋嫨鏁板瓧
    HOperatorSet.ClearWindow(hv_ExpDefaultWinHandle);
    ho_RegionNumber.Dispose();
    HOperatorSet.Threshold(ho_Image, out ho_RegionNumber, 0, 99);
    ho_ConnectedRegionsNumber.Dispose();
    HOperatorSet.Connection(ho_RegionNumber, out ho_ConnectedRegionsNumber);
    ho_SortedRegionsNumber.Dispose();
    HOperatorSet.SortRegion(ho_ConnectedRegionsNumber, out ho_SortedRegionsNumber, 
        "upper_left", "true", "column");
    HOperatorSet.CountObj(ho_SortedRegionsNumber, out hv_Number);
    for (hv_Index=1; hv_Index.Continue(hv_Number, 1); hv_Index = hv_Index.TupleAdd(1))
   
      HOperatorSet.ClearWindow(hv_ExpDefaultWinHandle);
      ho_SingleWord.Dispose();
      HOperatorSet.SelectObj(ho_SortedRegionsNumber, out ho_SingleWord, hv_Index);
      HOperatorSet.DispObj(ho_SingleWord, hv_ExpDefaultWinHandle);
      HDevelopStop();
   
    ho_Image.Dispose();
    ho_RegionTable.Dispose();
    ho_ConnectedRegionsTable.Dispose();
    ho_SingleWord.Dispose();
    ho_Rectangle.Dispose();
    ho_ImageReduced.Dispose();
    ho_DupImage.Dispose();
    ho_RegionNumber.Dispose();
    ho_ConnectedRegionsNumber.Dispose();
    ho_SortedRegionsNumber.Dispose();


 


  public void InitHalcon()
 
    // Default settings used in HDevelop 
    HOperatorSet.SetSystem("do_low_error", "false");
 


  public void RunHalcon(HTuple Window)
 
    hv_ExpDefaultWinHandle = Window;
    action();
 




以上是关于halcon-读取表格内容的主要内容,如果未能解决你的问题,请参考以下文章

HALCON - 如何在 halcon 中读取低分辨率 ECC200 数据代码?

Halcon学习笔记

Halcon学习笔记-读取图像的方式

halcon 数字转字符串实现循环读取图片

halcon如何将数据写到excel中

机器视觉 halcon中图像获取