首页

HalconDotNet数字识别 实例源码

c#

2020-9-1

数字识别

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 WindowsFormsApplication11
{
    public partial class Form1 : Form
    {

        private HObject Image;
        HObject ho_Image = null, ho_Image1 = null, ho_Image2 = null;
        HObject ho_Image3 = null, ho_Regions = null, ho_ConnectedRegions = null;
        HObject ho_SelectedRegions = null;

        // Local control variables 

        HTuple hv_AcqHandle = null;
        
        
        public Form1()
        {
            InitializeComponent();
            Image = new HObject();
            System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
        }

        Thread a;
        Thread b;
       
        
        private void button1_Click(object sender, EventArgs e)
        {
            a = new Thread(new ThreadStart(abc));
            a.Start();
        }

        public void abc()
        {

            HOperatorSet.GenEmptyObj(out ho_Image);
            //Image Acquisition 01: Code generated by Image Acquisition 01
            HOperatorSet.OpenFramegrabber("DirectShow", 1, 1, 0, 0, 0, 0, "default", 8, "rgb",
                -1, "false", "default", "[0] USB Camera", 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);
               
            }

        }

        private void button2_Click(object sender, EventArgs e)
        {
            a.Abort();
            HOperatorSet.CloseFramegrabber(hv_AcqHandle);

        }




        private void button3_Click(object sender, EventArgs e)
        {
            b = new Thread(new ThreadStart(abcd));
            b.Start();
        }

        public void abcd()
        {
            //HOperatorSet.OpenFramegrabber("DirectShow", 1, 1, 0, 0, 0, 0, "default", 8, "rgb",
       // -1, "false", "default", "[0] USB Camera", 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

                //灰度化
                ho_Image1.Dispose(); ho_Image2.Dispose(); ho_Image3.Dispose();
                HOperatorSet.Decompose3(ho_Image, out ho_Image1, out ho_Image2, out ho_Image3
                    );
                //阈值化
                ho_Regions.Dispose();
                HOperatorSet.Threshold(ho_Image3, out ho_Regions, 0, 91);
                //联通
                ho_ConnectedRegions.Dispose();
                HOperatorSet.Connection(ho_Regions, out ho_ConnectedRegions);
                //选择区域
                ho_SelectedRegions.Dispose();
                HOperatorSet.SelectShape(ho_ConnectedRegions, out ho_SelectedRegions, "area",
                    "and", 150, 99999);
                //显示选择的区域


                HOperatorSet.DispObj(ho_SelectedRegions, hWindowControl1.HalconWindow);
                
            //}


        }
    }
}

资源下载此资源下载价格为2D币(VIP免费),请先
资源文件列表
WindowsFormsApplication11/WindowsFormsApplication11.sln , 917
WindowsFormsApplication11/WindowsFormsApplication11.suo , 24064
WindowsFormsApplication11/WindowsFormsApplication11/bin/Debug/WindowsFormsApplication11.vshost.exe , 11592
WindowsFormsApplication11/WindowsFormsApplication11/bin/Debug/WindowsFormsApplication11.vshost.exe.manifest , 490
WindowsFormsApplication11/WindowsFormsApplication11/Form1.cs , 3665
WindowsFormsApplication11/WindowsFormsApplication11/Form1.Designer.cs , 4131
WindowsFormsApplication11/WindowsFormsApplication11/Form1.resx , 5817
WindowsFormsApplication11/WindowsFormsApplication11/obj/x86/Debug/DesignTimeResolveAssemblyReferences.cache , 13076
WindowsFormsApplication11/WindowsFormsApplication11/obj/x86/Debug/DesignTimeResolveAssemblyReferencesInput.cache , 6460
WindowsFormsApplication11/WindowsFormsApplication11/Program.cs , 506
WindowsFormsApplication11/WindowsFormsApplication11/Properties/AssemblyInfo.cs , 1400
WindowsFormsApplication11/WindowsFormsApplication11/Properties/Resources.Designer.cs , 2902
WindowsFormsApplication11/WindowsFormsApplication11/Properties/Resources.resx , 5612
WindowsFormsApplication11/WindowsFormsApplication11/Properties/Settings.Designer.cs , 1112
WindowsFormsApplication11/WindowsFormsApplication11/Properties/Settings.settings , 249
WindowsFormsApplication11/WindowsFormsApplication11/WindowsFormsApplication11.csproj , 3863
没有账号? 忘记密码?

社交账号快速登录