源码为超人视觉联合C#启蒙班中的示例代码
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 test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
HObject ho_Image4, ho_GrayImage, ho_Regions;
HTuple hv_WindowHandle = new HTuple();
private void button1_Click(object sender, EventArgs e)
{
string ImagePath;
openFileDialog1.Filter = "JPEG文件|*.jpg*|BMP文件|*.bmp*";
openFileDialog1.RestoreDirectory = true;
HOperatorSet.GenEmptyObj(out ho_Image4);
HOperatorSet.GenEmptyObj(out ho_GrayImage);
HOperatorSet.GenEmptyObj(out ho_Regions);
ho_Image4.Dispose();
if(openFileDialog1.ShowDialog()==DialogResult.OK)
{
ImagePath = openFileDialog1.FileName;
HOperatorSet.ReadImage(out ho_Image4, ImagePath);
}
}
private void button2_Click(object sender, EventArgs e)
{
HOperatorSet.OpenWindow(0, 0, hWindowControl1.Width, hWindowControl1.Height,hWindowControl1.HalconWindow, "visible", "", out hv_WindowHandle);
HDevWindowStack.Push(hv_WindowHandle);
ho_GrayImage.Dispose();
HOperatorSet.Rgb1ToGray(ho_Image4, out ho_GrayImage);
ho_Regions.Dispose();
HOperatorSet.Threshold(ho_GrayImage, out ho_Regions, 208, 255);
if (HDevWindowStack.IsOpen())
{
HOperatorSet.DispObj(ho_Regions, HDevWindowStack.GetActive());
}
}
}
}
窗体如下:
实际运行时出现以下异常:“HalconDotNet.HOperatorException”类型的未经处理的异常在 halcondotnet.dll 中发生
解决方法:将目标框架改为.NetFramework 4
更改框架后运行良好:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)