因为我使用的相机是1920*1200的

时间:2022-01-12 08:48:58

1.打开Halcon, 使用图像收罗助手获取相机实时图像:

  

因为我使用的相机是1920*1200的

  1.1 获取实时图像:

      

因为我使用的相机是1920*1200的

  1.2 插入收罗实时图像的Halcon代码,并导出:

    

因为我使用的相机是1920*1200的

    

因为我使用的相机是1920*1200的

    Image_acq.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=null; // Local control variables HTuple hv_AcqHandle = null; // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_Image); //Image Acquisition 01: Code generated by Image Acquisition 01 HOperatorSet.OpenFramegrabber("GigEVision", 0, 0, 0, 0, 0, 0, "default", -1, "default", -1, "false", "default", "e0508b2e4c36_DahuaTechnology_A5201MG50", 0, -1, out hv_AcqHandle); HOperatorSet.GrabImageStart(hv_AcqHandle, -1); while ((int)(1) != 0) { ho_Image.Dispose(); HOperatorSet.GrabImageAsync(out ho_Image, hv_AcqHandle, -1); //Image Acquisition 01: Do something } HOperatorSet.CloseFramegrabber(hv_AcqHandle); 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(); } }

2. 在c#项目中画好对应的按钮:

  

因为我使用的相机是1920*1200的

  对收罗/遏制按钮 执行要领进行编程(注意头部添加using HalconDotNet;  用到线程还要添加:using System.Threading;):

  Form1.cs代码:

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; using System.Threading; namespace demo4 { public partial class Form1 : Form { HObject ho_Image = null; HTuple hv_AcqHandle = null; public Form1() { InitializeComponent(); } Thread dispig; //收罗 private void button1_Click(object sender, EventArgs e) { dispig = new Thread(showFrame); dispig.Start(); } //遏制 private void button2_Click(object sender, EventArgs e) { dispig.Abort(); HOperatorSet.CloseFramegrabber(hv_AcqHandle); } void showFrame() { // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_Image); //Image Acquisition 01: Code generated by Image Acquisition 01 HOperatorSet.OpenFramegrabber("GigEVision", 0, 0, 0, 0, 0, 0, "default", -1, "default", -1, "false", "default", "e0508b2e4c36_DahuaTechnology_A5201MG50", 0, -1, out hv_AcqHandle); HOperatorSet.GrabImageStart(hv_AcqHandle, -1); while ((int)(1) != 0) { ho_Image.Dispose(); HOperatorSet.GrabImageAsync(out ho_Image, hv_AcqHandle, -1); //Image Acquisition 01: Do something HOperatorSet.DispObj(ho_Image, hWindowControl1.HalconWindow); } HOperatorSet.CloseFramegrabber(hv_AcqHandle); ho_Image.Dispose(); } } }

  在Debug文件下添加“halcon.dll”文件,把方针平台改成“Any CPU”之后执行,功效还是堕落:

  

因为我使用的相机是1920*1200的