VS2010 C# Halcon12 联合编程,读取图片

2021-05-01 18:26

阅读:539

标签:复制   temp   目录   头部   int   local   generic   model   this   

1.首先配置好VS2010:

  添加目录“HALCON-12.0\bin\dotnet35\halcondotnet.dll” 

 

  技术分享

  添加后工具栏中多出HWindowControl工具:技术分享

 

2.写好Halcon程序并导出:

技术分享

导出:

技术分享

 

 其中halcon_test.cs代码如下:

//
//  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 HalconDotNet;

public partial class HDevelopExport
{
  public HTuple hv_ExpDefaultWinHandle;

  // Main procedure 
  private void action()
  {


    // Local iconic variables 

    HObject ho_Image;

    // Local control variables 

    HTuple hv_Width = null, hv_Height = null, hv_WindowHandle = new HTuple();
    // Initialize local and output iconic variables 
    HOperatorSet.GenEmptyObj(out ho_Image);
    //dev_close_window(...);
    ho_Image.Dispose();
    HOperatorSet.ReadImage(out ho_Image, "C:/Users/Administrator/Desktop/车牌.jpg");
    HOperatorSet.GetImageSize(ho_Image, out hv_Width, out hv_Height);
    //dev_open_window(...);
    HOperatorSet.DispImage(ho_Image, hv_ExpDefaultWinHandle);




    ho_Image.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();
  }

}

 

 3.在VS项目中:

  3.1把导出的cs文件复制到program.cs文件中:

    

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

using HalconDotNet; //引用HalconDotNet

namespace demo3
{

    public partial class HDevelopExport
    {
        public HTuple hv_ExpDefaultWinHandle;

        // Main procedure 
        private void action()
        {


            // Local iconic variables 

            HObject ho_Image;

            // Local control variables 

            HTuple hv_Width = null, hv_Height = null, hv_WindowHandle = new HTuple();
            // Initialize local and output iconic variables 
            HOperatorSet.GenEmptyObj(out ho_Image);
            //dev_close_window(...);
            ho_Image.Dispose();
            HOperatorSet.ReadImage(out ho_Image, "C:/Users/Administrator/Desktop/车牌.jpg");
            HOperatorSet.GetImageSize(ho_Image, out hv_Width, out hv_Height);
            //dev_open_window(...);
            HOperatorSet.DispImage(ho_Image, hv_ExpDefaultWinHandle);




            ho_Image.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();
        }

    }
    static class Program
    {
        /// 
        /// 应用程序的主入口点。
        /// 
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
}

   3.2在Form1.cs[设计]中画好HWindowControl和按钮:

    技术分享

    双击"start"按钮并编写相应的程序(不要忘记在头部添加 using HalconDotNet;):

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using HalconDotNet;
namespace demo3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            HDevelopExport HD = new HDevelopExport();
            HD.RunHalcon(hWindowControl1.HalconWindow);
        }
    }
}

 

   4.运行发现出错:

    在Program.cs文件中:

技术分享

 

       4.1添加“HALCON-12.0\bin\x64-win64”下的halcon.dll到项目Debug文件夹下再次运行,发现出现如下错:

      技术分享

        4.2 更新 “生成配置”,将目标平台改成:“Any CPU”并运行:

        技术分享

  5.大功告成!

技术分享

 

 

 

        

 

VS2010 C# Halcon12 联合编程,读取图片

标签:复制   temp   目录   头部   int   local   generic   model   this   

原文地址:http://www.cnblogs.com/samshen1991/p/7783398.html


评论


亲,登录后才可以留言!