【Halcon视觉】C#与Halcon联合应用2

1.前言

        Halcon功能,展示在桌面上,可应用于工业软件。

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;

namespace WindowsFormsApplication5
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        String path = "";
        HObject ho_Image;
        HObject grayImage;

        //读取图片按钮
        private void button1_Click(object sender, EventArgs e)
        {
           
            OpenFileDialog openFile = new OpenFileDialog();
            if (openFile.ShowDialog() == DialogResult.OK && openFile.FileName != "")
            {
                path = openFile.FileName;
            }
            HOperatorSet.ReadImage(out ho_Image, path);
            hWindowControl1.HalconWindow.DispObj(ho_Image);

        }

        //适应屏幕按钮
        private void button2_Click(object sender, EventArgs e)
        {
            HTuple width, high;
            HOperatorSet.GetImageSize(ho_Image, out width, out high);
            HOperatorSet.SetPart(hWindowControl1.HalconWindow, 0, 0, high - 1, width - 1);
            HOperatorSet.DispObj(ho_Image, hWindowControl1.HalconWindow);
        }

        //图像灰度化
        private void button3_Click(object sender, EventArgs e)
        {
            HOperatorSet.Rgb1ToGray(ho_Image, out grayImage);
            hWindowControl1.HalconWindow.DispObj(grayImage);

        }

       
    }
}

3.效果

【Halcon视觉】C#与Halcon联合应用2_第1张图片

4.结语

        C#与Halcon联合,将图像处理的强大功能应用到Windows桌面软件上,使其在工业领域得到了广泛的应用。 



你可能感兴趣的:(视觉,c#,计算机视觉)