基本信息
源码名称:HalconDotNet数字识别 实例源码
源码大小:0.03M
文件格式:.zip
开发语言:C#
更新时间:2020-05-11
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 2 元 
   源码介绍
数字识别

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);
                
            //}


        }
    }
}