C#与Halcon联合编程实现鼠标对区域的选择
在视觉检测项目中,有时可能需要选择某一个已经提取出区域,查看其面积、圆度等参数。在HDevelop中已经提供了这个功能,只需鼠标点击即可选择相应的区域,但是在C#与Halcon联合编程时,调用的hWindowControl这个控件没有提供现成的区域选择功能。由于当前项目中需要用到区域选择功能,所以对这个功能进行了开发验证,下面的实现的效果图,包括显示区域的两种风格。
引用halcon库、添加相关控件等不做过多介绍。
下面贴出所有代码,代码中注释详细,无需过多介绍。
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;
using System.IO;
namespace SelectRegion
{
public partial class Form1 : Form
{
private HWindow hWindow = null;//窗口变量
private HImage image = null;//图像变量
private HRegion allRegions = null;//提取区域变量
private HRegion selectRegions = null;//选择的区域变量
private int index = 0;//选择区域的显示样