• 大小: 386KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-13
  • 语言: C#
  • 标签: C#  Halcon  视觉  

资源简介

C#联合Halcon调用笔记本实时采集,单帧采集。 里面有调用Halcon的简单方法,开线程实时采集图像。

资源截图

代码片段和文件信息

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.Tasks;

namespace HalconAcqTest
{
    public partial class FrmMain : Form
    {
        #region 参数设置
        public Hobject ho_Image;
        public HTuple hv_AcqHandle;
        public bool IsStart;
        #endregion

        #region 窗体事件
        public FrmMain()
        {
            InitializeComponent();
            CameraIni();
        }

        private void FrmMain_FormClosing(object sender FormClosingEventArgs e)
        {
            hv_AcqHandle.Dispose();
        }

        private void CameraIni()
        {
            hv_AcqHandle = new HTuple();
            HOperatorSet.GenEmptyObj(out ho_Image);
            hv_AcqHandle.Dispose();
            IsStart = false;
        }
        #endregion
        #region 窗体点击事件
        private void btnStartCamera_Click(object sender EventArgs e)
        {
            try
            {
                HOperatorSet.Openframegrabber(“DirectShow“ 1 1 0 0 0 0 “default“ 8 “rgb“
                                -1 “false“ “default“ “[0] Integrated Webcam“ 0 -1 out hv_AcqHandle);
                HOperatorSet.GrabImageStart(hv_AcqHandle -1);
            }
            catch (Exception ex)
            {

            }
        }

        private void btnOnce_Click(object sender EventArgs e)
        {
            try
            {
                ho_Image.Dispose();
                System.Threading.Thread.Sleep(50);
                HOperatorSet.GrabImageAsync(out ho_Image hv_AcqHandle -1);
                System.Threading.Thread.Sleep(50);
                HOperatorSet.DispObj(ho_Image hWindowControl1.HalconWindow);
            }
            catch (Exception ex)
            {

            }
        }
        
        private void btnContinuation_Click(object sender EventArgs e)
        {
            IsStart = true;
            Task task = new Task(() =>
            {
                while (IsStart)
                {
                    ho_Image.Dispose();
                    HOperatorSet.GrabImageAsync(out ho_Image hv_AcqHandle -1);
                    HOperatorSet.DispObj(ho_Image hWindowControl1.HalconWindow);
                }
            });
            task.Start();
        }

        private void btnCloseCamera_Click(object sender EventArgs e)
        {
            try
            {
                IsStart = false;
                HOperatorSet.Closeframegrabber(hv_AcqHandle);
                ho_Image.Dispose();
            }
            catch (Exception)
            {

            }
        }
        #endregion

    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2020-05-15 17:03  HalconAcqTest\
     目录           0  2020-05-15 17:05  HalconAcqTest\HalconAcqTest\
     文件        6695  2020-05-15 17:01  HalconAcqTest\HalconAcqTest\FrmMain.Designer.cs
     文件        2893  2020-05-15 17:02  HalconAcqTest\HalconAcqTest\FrmMain.cs
     文件        6022  2020-05-15 17:01  HalconAcqTest\HalconAcqTest\FrmMain.resx
     文件        5164  2020-05-15 17:05  HalconAcqTest\HalconAcqTest\HalconAcqTest.csproj
     文件         496  2020-05-15 16:52  HalconAcqTest\HalconAcqTest\Program.cs
     目录           0  2020-05-15 16:52  HalconAcqTest\HalconAcqTest\Properties\
     文件        1358  2020-05-15 16:52  HalconAcqTest\HalconAcqTest\Properties\AssemblyInfo.cs
     文件        2866  2020-05-15 17:05  HalconAcqTest\HalconAcqTest\Properties\Resources.Designer.cs
     文件        5612  2020-05-15 16:52  HalconAcqTest\HalconAcqTest\Properties\Resources.resx
     文件        1113  2020-05-15 17:05  HalconAcqTest\HalconAcqTest\Properties\Settings.Designer.cs
     文件         249  2020-05-15 16:52  HalconAcqTest\HalconAcqTest\Properties\Settings.settings
     文件         144  2020-05-15 17:05  HalconAcqTest\HalconAcqTest\app.config
     目录           0  2020-05-15 17:03  HalconAcqTest\HalconAcqTest\obj\
     目录           0  2020-05-15 17:03  HalconAcqTest\HalconAcqTest\obj\x64\
     目录           0  2020-05-15 17:05  HalconAcqTest\HalconAcqTest\obj\x64\Debug\
     文件        6726  2020-05-15 17:05  HalconAcqTest\HalconAcqTest\obj\x64\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     文件         180  2020-05-15 17:05  HalconAcqTest\HalconAcqTest\obj\x64\Debug\HalconAcqTest.FrmMain.resources
     文件         180  2020-05-15 17:05  HalconAcqTest\HalconAcqTest\obj\x64\Debug\HalconAcqTest.Properties.Resources.resources
     文件        1079  2020-05-15 17:05  HalconAcqTest\HalconAcqTest\obj\x64\Debug\HalconAcqTest.csproj.FileListAbsolute.txt
     文件         977  2020-05-15 17:03  HalconAcqTest\HalconAcqTest\obj\x64\Debug\HalconAcqTest.csproj.GenerateResource.Cache
     文件       23417  2020-05-15 17:05  HalconAcqTest\HalconAcqTest\obj\x64\Debug\HalconAcqTest.csprojResolveAssemblyReference.cache
     文件       10752  2020-05-15 17:05  HalconAcqTest\HalconAcqTest\obj\x64\Debug\HalconAcqTest.exe
     文件       24064  2020-05-15 17:05  HalconAcqTest\HalconAcqTest\obj\x64\Debug\HalconAcqTest.pdb
     目录           0  2020-05-15 17:05  HalconAcqTest\HalconAcqTest\obj\x64\Debug\TempPE\
     文件        4608  2020-05-15 17:05  HalconAcqTest\HalconAcqTest\obj\x64\Debug\TempPE\Properties.Resources.Designer.cs.dll
     目录           0  2020-05-15 16:52  HalconAcqTest\HalconAcqTest\obj\x86\
     目录           0  2020-05-15 17:02  HalconAcqTest\HalconAcqTest\obj\x86\Debug\
     文件       15180  2020-05-15 16:56  HalconAcqTest\HalconAcqTest\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
     文件        6884  2020-05-15 16:56  HalconAcqTest\HalconAcqTest\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
............此处省略17个文件信息

评论

共有 条评论