using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using HalconDotNet;
namespace readimage
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
HObject ho_Image162804194, ho_GrayImage, ho_Regions;
HTuple hv_WindowHandle = new HTuple();
private void Form1_Load(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
HOperatorSet.OpenWindow(0, 0, hWindowControl1.Width, hWindowControl1.Height, hWindowControl1.HalconWindow, "", "", out hv_WindowHandle);
HDevWindowStack.Push(hv_WindowHandle);
ho_GrayImage.Dispose();
HOperatorSet.Rgb1ToGray(ho_Image162804194, out ho_GrayImage);
ho_Regions.Dispose();
HOperatorSet.Threshold(ho_GrayImage, out ho_Regions, 158, 255);
if (HDevWindowStack.IsOpen())
{
HOperatorSet.DispObj(ho_Regions, HDevWindowStack.GetActive());
}
}
private void button1_Click(object sender, EventArgs e)
{
string ImagePath;
openFileDialog1.Filter = "JPEG文件|*.jpg|BMP文件|*.bmp*|PNG文件|*.png*";
openFileDialog1.RestoreDirectory = true;
HOperatorSet.GenEmptyObj(out ho_Image162804194);
HOperatorSet.GenEmptyObj(out ho_GrayImage);
HOperatorSet.GenEmptyObj(out ho_Regions);
ho_Image162804194.Dispose();
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
ImagePath = openFileDialog1.FileName;
HOperatorSet.ReadImage(out ho_Image162804194, ImagePath); //图片名称
}
}
}
}