C# HalconDotNet 工业视觉处理

本文档展示了如何在C#环境中集成Halcon组件,进行相机的开启、关闭、实时播放、拍照以及模板匹配等操作。通过调用Halcon接口,实现了图像的抓取、显示和模板匹配功能,可用于工业自动化中的目标检测。

1.引入Halcon组件

2.项目配置文件

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="halcondotnet" publicKeyToken="4973BED59DDBF2B8"/>
        <bindingRedirect oldVersion="12.0.0.0-12.0.65535.65535" newVersion="12.0.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="halcondotnetxl" publicKeyToken="4973BED59DDBF2B8"/>
        <bindingRedirect oldVersion="12.0.0.0-12.0.65535.65535" newVersion="12.0.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="hdevenginedotnet" publicKeyToken="4973BED59DDBF2B8"/>
        <bindingRedirect oldVersion="12.0.0.0-12.0.65535.65535" newVersion="12.0.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="hdevenginedotnetxl" publicKeyToken="4973BED59DDBF2B8"/>
        <bindingRedirect oldVersion="12.0.0.0-12.0.65535.65535" newVersion="12.0.0.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

 

3.页面配置

4.halcon接口调用

    public partial class HDevelopExport
    {
        public int ResultN;
        public double usedTime;
        public double[] Px;
        public double[] Py;
        public double Fx, Fy;
        public double Cr = 9;
        public double Cx, Cy;
        public bool IsStart = false;

        HTuple hv_R;
        List<HTuple> Aa = new List<HTuple>();
        HTuple hv_Angle, hv_Score, hv_Runtime;
        HTuple hv_ModelID, hv_Row, hv_Column;

        HObject ho_Mask;
        HTuple hv_S1, hv_S2;
        HObject ho_Image, ho_Rectangle, ho_ImageReduced;
        public HTuple hv_ExpDefaultWinHandle;
        HWindowControl HWindowControl;

        /// <summary>
        /// 打开相机
        /// </summary>
        public void OpenCamera()
        {
            //hv_ExpDefaultWinHandle = Window;
            HOperatorSet.GenEmptyObj(out ho_Image); // 生ho_Image数据区
            // Grabbing images from a Daheng USB 2.0 camera
            HOperatorSet.CloseAllFramegrabbers();
            HOperatorSet.OpenFramegrabber("DirectShow", 1, 1, 0, 0, 0, 0, "default", 8, "rgb",
                -1, "false", "default", "[0] Integrated Camera", 0, -1, out hv_Angle);
            HOperatorSet.SetFramegrabberParam(hv_Angle, "tilt", -3);
            HOperatorSet.GrabImageStart(hv_Angle, -1);
            //open camera with default settings
        }

        /// <summary>
        /// 关闭相机
        /// </summary>
        public void CloseCamera()
        {
            HOperatorSet.CloseAllFramegrabbers();
        }

        /// <summary>
        /// 实时播放
        /// </summary>
        public void RealTimePlayback()
        {
            IsStart = true;
            //HObject ho_Image = null;

            //HTuple hv_AcqHandle 
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值