unity+opencv实时检测人脸及眼睛区域检测

这是最近做的一个工作,由于要调用电脑摄像头实时检测人眼主要是检测闭眼睁眼
**

1.工具

**
1.1unity(作者用的是2020.3.25 大部分版本都ok
1.2opencv for unity(可从这个链接下载链接:https://pan.baidu.com/s/1Wti9m57-pe1et4U8LNgoCA 提取码:b0un
1.3haar模型
请添加图片描述

2.实现

2.1首先新建一个项目
然后将opencv for unity导入
2.2
新建一个脚本这里命名为EyeDetect


using OpenCVForUnity;
using OpenCVForUnityExample;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EyeDetect : MonoBehaviour
{
   
   
    //WebCamTextureToMatExample webcamTexToMat = new WebCamTextureToMatExample();//获取摄像头画面的辅助类
    //PoseEstimator poseEstimator = new PoseEstimator();
    string face_Xml_path;//人脸识别训练数据文件XML的路径
    string eye_Xml_path;//人眼识别训练数据文件XML的路径
    Mat gray;//灰度图
    MatOfRect faceRect;//识别到的人脸区域

    CascadeClassifier classifier;//人脸识别分类器
    public static int EyesChecked=0;//是否检测到眼睛
    void Start()
    {
   
   
        //webcamTexToMat = transform.GetComponent<WebCamTexToMat>();//获取Quad上挂载的WebCamTextureToMatExample脚本组件
        //poseEstimator = transform.GetComponent<PoseEstimator>();
        face_Xml_path = Application.streamingAssetsPath + "/haarcascade_frontalface_alt2.xml";//获取人脸识别训练数据XML
        eye_Xml_path = Application.streamingAssetsPath + "/haarcascade_eye.xml"
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值