目录
C#配置halcon
将halcon中的两个文件放在程序的debug目录下

在程序员引用中,选择引用,引用halcondotnet.dll文件

在命名空间中写下using HalconDotNet

在项目选项中选择属性,取消掉首选32为生成

再再工具箱中右键,选择项,添加引入的 HalconDotNet,获得halcon窗口控件。关于配置,可以参考视频
https://www.bilibili.com/video/BV1FE411E7HK?share_source=copy_web
程序代码
界面布局如下

完整代码乳如下,注有详细的解释。使用的是笔记本的摄像头
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using HalconDotNet;
namespace 人脸匹配
{
public partial class Form1 : Form
{
//定义halconq窗口的句柄
HTuple WindowHandle = null;
//定义宽高变量
HTuple width = null, height = null;
HObject ho_Image, ho_SymbolXLDs;
HObject ho_Rectangle, ho_ImageReduced;
HObject ho_RegionAffineTrans = null;
// Local control variables
HTuple hv_Row1 = null, hv_Column1 = null, hv_Row2 = null;
HTuple hv_Column2 = null, hv_Area = null, hv_Row = null;
HTuple hv_Column = null, hv_Phi = null, hv_ModelID = null;
HTuple hv_Row11 = new HTuple(), hv_Column11 = new HTuple();
HTuple hv_Angle = new HTuple(), hv_Score = new HTuple();
HTuple hv_HomMat2D = new HTuple();
// halcon相机句柄
HTuple hv_AcqHandle;
//定义线程开关状态
bool B = false;
//定义一个线程
Thread th;
//主窗口加载
private void Form1_Load(object sender, EventArgs e)
{
//允许跨线程访问
Control.CheckForIllegalCrossThreadCalls = false;
button2.Enabled = false;
button3.Enabled = false;
button5.Enabled = false;
}
public Form1()
{
InitializeComponent();
WindowHandle = hWindowControl1.HalconWindow;
}
//halcon导出文件的函数
public void disp_message(HTuple hv_WindowHandle, HTuple hv_String, HTuple hv_CoordSystem,
HTuple hv_Row, HTuple hv_Column, HTuple hv_Color, HTuple hv_Box)
{
// Local iconic variables
// Local control variables
HTuple hv_Red = null, hv_Green = null, hv_Blue = null;
HTuple hv_Row1Part = null, hv_Column1Part = null, hv_Row2Part = null;
HTuple hv_Column2Part = null, hv_RowWin = null, hv_ColumnWin = null;
HTuple hv_WidthWin = null, hv_HeightWin = null, hv_MaxAscent = null;
HTuple hv_MaxDescent = null, hv_MaxWidth = null, hv_MaxHeight = null;
HTuple hv_R1 = new HTuple(), hv_C1 = new HTuple

本文详细介绍了如何在C#中配置Halcon库,包括添加dll引用、设置窗口控件、实现摄像头捕获和人脸模板绘制,以及关键函数如打开相机、绘制模板和人脸识别。通过实例代码展示了如何在Windows Form应用中进行人脸匹配操作。
最低0.47元/天 解锁文章
1346





