#基于VR环境下的手指识别键盘输入# 利用OpenCV for Unity初步完成的手指识别效果(一)

本文介绍了如何在Unity中利用OpenCV进行手指识别,通过WebCamTexture获取摄像头图像,并利用HSV颜色空间进行肤色识别。文章讨论了RGB与HSV空间的区别,指出HSV更适合颜色对比,且在不同环境下需要调整HSV范围。文中还提到需要自定义工具进行颜色处理和边缘检测,以完成初步的手指识别效果。下篇博客将继续深入探讨此话题。
摘要由CSDN通过智能技术生成

前面几篇文章中介绍了OpenCVforUnity的使用方法,在导入了这个包之后,我们就可以在C#代码当中利用opencv的库了。

以下是在unity中编写OpenCV图像处理代码所用的一般格式:

using UnityEngine;
using UnityEngine.EventSystems;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;

#if UNITY_5_3 || UNITY_5_3_OR_NEWER
using UnityEngine.SceneManagement;
#endif
using OpenCVForUnity;

namespace OpenCVForUnityExample
{

    [RequireComponent(typeof(WebCamTextureToMatHelper))]
    public class HandPoseEstimationExample : MonoBehaviour
    {
        //详细内容
     }
}

首先阐述一下我们利用opencv库对手指进行识别的主要思路。利用摄像头对手部进行识别,有一个非常重要的工具:WebCamTexture,这是在unity中实现摄像头拍照和录像的必备工具。

一、启用摄像头:

该工具在unity当中的初始化过程:

		//初始化WebCamTextureToMat
        public void OnWebCamTextureToMatHelperInitialized ()
        {
            Debug.Log ("OnWebCamTextureToMatHelperInitialized");
            
            Mat webCamTextureMat = webCamTextureToMatHelper.GetMat ();

            texture = new Texture2D (webCamTextureMat.cols (), webCamTextureMat.rows (), TextureFormat.RGBA32, false);

            gameObject.GetComponent<Renderer> ().material.mainTexture = texture;
            
            gameObject.transform.localScale = new Vector3 (webCamTextureMat.cols (), webCamTextureMat.rows (), 1);
            
            Debug.Log ("Screen.width " + Screen.width + " Screen.height " + Screen.height + " Screen.orientation " + Screen.orientation);

            if (fpsMonitor != null){
                fpsMonitor.Add ("width", webCamTextureMat.width ().ToString());
                fpsMonitor.Add ("height", webCamTextureMat.height ().ToString());
                fpsMonitor.Add ("orientation", Screen.orientation.ToString());
                fpsMonitor.consoleText = "Please touch the area of the open hand.";
            }


            float wi
Works with Unity Cloud Build iOS & Android support Windows10 UWP support WebGL support Win & Mac & Linux Standalone support Preview support in the Editor OpenCV for Unity is an Assets Plugin for using OpenCV 3.4.2 from within Unity. Official Site | ExampleCode | Android Demo WebGL Demo | Tutorial & Demo Video | Forum | API Reference | Support Modules Features: - Since this package is a clone of OpenCV Java, you are able to use the same API as OpenCV Java 3.4.2 (link). - You can image processing in real-time by using the WebCamTexture capabilities of Unity. (real-time face detection works smoothly on iPhone 5) - Provides a method to interconversion of Unity's Texture2D and OpenCV's Mat. - IDisposable is implemented in many classes.You can manage the resources with the “using” statement. - Examples of integration with other publisher assets are available.(e.g. PlayMaker, NatCam, NatCorder) ExampleCode using OpenCV for Unity is available. MarkerBased AR Example MarkerLess AR Example FaceTracker Example FaceSwapper Example FaceMask Example RealTime FaceRecognition Example GoogleVR with OpenCV for Unity Example Kinect with OpenCV for Unity Example AVPro with OpenCV for Unity Example HoloLens with OpenCV for Unity Example PlayMakerActions for OpenCVforUnity NatCam with OpenCVForUnity Example NatCorder with OpenCVForUnity Example OpenCV for Unity uses OpenCV under 3-clause BSD License; see Third-Party Notices.txt file in package for details. System Requirements Build Win Standalone & Preview Editor : Windows 7 or later Build Mac Standalone & Preview Editor : OSX 10.9 or later
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值