C#联合halcon实时采集图像实现人脸追踪项目

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

目录

C#配置halcon

程序代码


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
评论 9
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

猪猪派对

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值