1,加预制体。

2. 脚本

LeapGestures.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;using Leap;
using Leap.Unity;public class LeapGestures : MonoBehaviour {public static bool Gesture_left = false;public static bool Gesture_right = false;public static bool Gesture_up = false;public static bool Gesture_down = false;public static bool Gesture_zoom = false;public static float movePOs = 0.0f;private LeapProvider mProvider;private Frame mFrame;private Hand mHand;private Vector leftPosition;private Vector rightPosition;public static float zoom = 1.0f;[Tooltip ("Velocity (m/s) of Palm ")]public float smallestVelocity = 1.45f;//手掌移动的最小速度[Tooltip ("Velocity (m/s) of Single Direction ")][Range(0,1)]public float deltaVelocity = 10.0f;//单方向上手掌移动的速度// Use this for initializationvoid Start () {mProvider = FindObjectOfType<LeapProvider>() as LeapProvider;}// Update is called once per framevoid Update () {mFrame = mProvider.CurrentFrame;//获取当前帧//获得手的个数//print ("hand num are " + mFrame.Hands.Count);if (mFrame.Hands.Count > 0) {if (mFrame.Hands.Count == 2) zoom = CalcuateDistance(mFrame);if (mFrame.Hands.Count == 1) LRUDGestures(mFrame,ref movePOs);}}float CalcuateDistance(Frame mFrame){Gesture_zoom = true;Gesture_left = false;Gesture_right = false;float distance = 0f;//print ("Two hands");foreach (var itemHands in mFrame.Hands) {if (itemHands.IsLeft) {leftPosition = itemHands.PalmPosition;//print ("leftPosition" + leftPosition);}if (itemHands.IsRight) {rightPosition = itemHands.PalmPosition;//print ("rightPosition" + rightPosition);}}if (leftPosition != Vector.Zero && rightPosition != Vector.Zero ) {Vector3 leftPos = new Vector3 (leftPosition.x, leftPosition.y,leftPosition.z);Vector3 rightPos = new Vector3 (rightPosition.x, rightPosition.y,rightPosition.z);distance = 10*Vector3.Distance (leftPos, rightPos);print ("distance" + distance);}if (distance != 0)return distance;elsereturn distance = 1;}void LRUDGestures(Frame mFrame, ref float movePOs){Gesture_zoom = false;foreach (var item in mFrame.Hands) {int numFinger = item.Fingers.Count;//print ("item is  " + numFinger);//print("hand are " + isOpenFullHand (item));// print ("isOpenFullHands is  " + isOpenFullHands(item));if (item.GrabStrength == 1) {print ("num is 0, gestures is woquan");}else if ( item.GrabStrength == 0) {//print ("num is 5, open your hand");//print("PalmVelocity" + item.PalmVelocity);//print("PalmPosition" + item.PalmPosition);movePOs = item.PalmPosition.x;if (isMoveLeft (item)) {Gesture_left = true;Gesture_right = false;print ("move left");} else if (isMoveRight (item)) {Gesture_left = false;Gesture_right = true;print ("move Right");}else if (isMoveUp (item)) {Gesture_left = false;Gesture_right = false;print ("move Up");}else if (isMoveDown (item)) {Gesture_left = false;Gesture_right = false;print ("move Down");}else if (isMoveForward (item)) {Gesture_left = false;Gesture_right = false;print ("move Forward");}else if (isMoveBack (item)) {Gesture_left = false;Gesture_right = false;print ("move back");}}}}//判断有多少个手指是伸开的,以及伸开的手指是哪个public int extendFingerNum(Hand hand){int extendedFingers = 0;//一个手指的一次遍历for (int f = 0; f < hand.Fingers.Count; f++){Finger digit = hand.Fingers[f];if (digit.IsExtended) {print ("Fingers is " + digit);extendedFingers++;}}return extendedFingers;}//是否抓取public bool isGrabHand (Hand hand)       {return hand.GrabStrength > 0.8f;        //抓取力 }//hand move four directionpublic bool isMoveRight (Hand hand)    {//print (hand.PalmVelocity.x);return hand.PalmVelocity.x < -deltaVelocity && !isStationary (hand);}  // 手划向右边public bool isMoveLeft (Hand hand)     {//print (hand.PalmVelocity.x );return hand.PalmVelocity.x > deltaVelocity && !isStationary (hand);}  //手向上 public bool isMoveUp (Hand hand)     {return hand.PalmVelocity.y > deltaVelocity && !isStationary (hand);}//手向下  public bool isMoveDown (Hand hand)       {return hand.PalmVelocity.y < -deltaVelocity && !isStationary (hand);}//手向前public bool isMoveForward (Hand hand)     {//print (hand.PalmVelocity.z);return hand.PalmVelocity.z > deltaVelocity && !isStationary (hand);}//手向后 public bool isMoveBack (Hand hand)      {return hand.PalmVelocity.z < -deltaVelocity && !isStationary (hand);}//固定不动的public bool isStationary (Hand hand)         {return hand.PalmVelocity.Magnitude < smallestVelocity;     //Vector3.Magnitude返回向量的长度}}

CubeChange.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class CubeChange : MonoBehaviour {private bool isSure = true;// Use this for initializationvoid Start () {}// Update is called once per framevoid Update () {if (LeapGestures.Gesture_left) {ColorGreen ();MoveCube (LeapGestures.movePOs);} else if (LeapGestures.Gesture_right) {ColorRed ();} else if (LeapGestures.Gesture_up) {ColorWihte ();} else if (LeapGestures.Gesture_down) {ColorBlue ();} else if (LeapGestures.Gesture_zoom) {if (true) {ZoomCube (LeapGestures.zoom);}}}void MoveCube (float move_x){float pos_x = transform.localPosition.x;float pos_y = transform.localPosition.y;float pos_z = transform.localPosition.z;}void ZoomCube (float scale){scale *= Mathf.PI;this.transform.localScale = new Vector3(scale, scale, scale);}void ColorGreen(){this.GetComponent<MeshRenderer> ().material.color = Color.green;//this.transform.localScale = }void ColorRed(){this.GetComponent<MeshRenderer> ().material.color = Color.red;}void ColorWihte (){this.GetComponent<MeshRenderer> ().material.color = Color.white;}void ColorBlue(){this.GetComponent<MeshRenderer> ().material.color = Color.blue;}
}

hand.grabAngle()返回的是除却大拇指四根手指的平均弯曲程度,所以紧握拳头的时候数值为3.14左右,手全部张开是的时候基本也为0。一般使用0为一个手势,>2为一个手势,其余为一个手势。

所有⼿指的弯曲程度。通过观察四个⼿指的⽅向和⼿的⽅向之间的夹⻆来计算这个⻆。当计算⻆度时,不考虑拇指。这个⻆度是⼀个开着的⼿的0弧度,当这个姿势是⼀个紧的拳头时,它就会到达pi弧度。

leapmotion 定义识别手势改变物体颜色相关推荐

  1. 虚幻随笔(UI改变物体颜色)

    内容浏览器里创建材质参数集,里面点击向量参数. 物体材质里面,把对应的替换为材质参数集(材质参数集是四维,使用mask节点能遮罩不需要的).左边参数名要对应好自己创建的. UI界面点击事件,线性颜色设 ...

  2. Unity改变物体颜色(添加材质Materials)

    例子:让Cube方块变成红色 第一步:创建一个Cube 第二步:新建一个材质Materials 第三步:将材质修改为红色 第四步:将材质拖动到Cube上 这样就可以啦(●'◡'●)

  3. python红色的颜色表达式_50行Python代码实现视频中物体颜色识别和跟踪(必须以红色为例)...

    目前计算机视觉(CV)与自然语言处理(NLP)及语音识别并列为人工智能三大热点方向,而计算机视觉中的对象检测(objectdetection)应用非常广泛,比如自动驾驶.视频监控.工业质检.医疗诊断等 ...

  4. MATLAB实现物体颜色识别

    颜色是物体表面的固有特征,在目标识别和图像分割中有着无法替代的作用. 机器视觉利用光电成像系统和图像处理模块对物体进行尺寸.形状.颜色等的识别.这样就把计算机的快速性.可重复性与人眼视觉的高度智能化和 ...

  5. 【机器视觉案例】(5) AI视觉,手势调节物体尺寸,附python完整代码

    各位同学好,今天和大家分享一下如何使用opencv+mediapipe完成远程手势调节图片尺寸的案例.先放张图看效果.当拇指和食指竖起时,根据食指间的连线的长度自由缩放图片尺寸.图片的中点始终位于指尖 ...

  6. Python3识别判断图片主要颜色并和颜色库进行对比的方法

    [更新]主要提供两种方案: 方案一:(参考网上代码,感觉实用性不是很强)使用PIL截取图像,然后将RGB转为HSV进行判断,统计判断颜色,最后输出RGB值 方案二:使用opencv库函数进行处理.(效 ...

  7. python颜色识别_浅谈Python3识别判断图片主要颜色并和颜色库进行对比的方法

    [更新]主要提供两种方案: 方案一:(参考网上代码,感觉实用性不是很强)使用PIL截取图像,然后将RGB转为HSV进行判断,统计判断颜色,最后输出RGB值 方案二:使用opencv库函数进行处理.(效 ...

  8. android自定义手势,Android实现自定义手势和识别手势的功能

    这篇文章主要介绍了Android实现自定义手势和识别手势的功能,本文通过实例代码给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下 1. 先完成自定义手势的Activity 1.1 因 ...

  9. Mlab - 改变物体外观及鼠标选取操作

    Python科学计算三维可视化 黄天羽.嵩天 Mlab 基础 MLab reference 改变物体的外观 改变颜色 colormap 定义的颜色,也叫 LUT(Look Up Table) 常见的 ...

  10. 贺利坚老师汇编课程74笔记:按下esc键改变显示颜色

    依次显示'a' - 'z' 无法看清屏幕显示,同一位置显示字母,字母切换太快 在显示一个字母后,延时一段时间 assume cs:code code segment start:mov ax,0b80 ...

最新文章

  1. Shell中创建序列和数组(list、array)的方法
  2. MySql ORDER BY 索引优化
  3. httpRuntime 一点经验---引
  4. Machine Learning On Spark——基础数据结构(二)
  5. Golang实现一个密码生成器
  6. 【渝粤教育】国家开放大学2018年春季 8623-22T燃气行业法律法规 参考试题
  7. 程序员专属精品简历合集—面试必备
  8. 一些大厂的css reset 代码
  9. java 二分查找算法
  10. python函数和模块有什么关键特性_【Python函数与模块】(2)函数的特点
  11. 至少清楚知道兼容IE8 ie9 ;持续更新
  12. 数据结构------图-----深度广度优先遍历
  13. 远程计算机没反映6678,6678 PCIe 与FPGA LINK UP 后 不能获得FPGA的DEVICE_ID和VENDDR_ID
  14. magisk卸载内置软件_GJ2x_免root搞机工具箱V6.71 更新:增加卸载内置功能
  15. 图解Java类加载机制
  16. tableau实战系列(十二)-使用盒须图查看你的数据分布
  17. 使用Tab键控制切换网页光标位置
  18. 解决 IE下ajaxfileupload不兼容的问题
  19. 模线性方程ax≡b(mod n) (再结合 程序理解)
  20. excel转pdf的在线免费转换技巧,超实用

热门文章

  1. mysql vc调用时内存错误
  2. 遗传算法 python_Python实现入门级遗传算法
  3. 服务器修改lang值,golang设置http response响应头与填坑记录
  4. 如何用python读取表_Python读取MySQL表数据的方法介绍
  5. 企业级 SpringBoot 教程 (一)构建第一个SpringBoot工程
  6. wow.js中各种特效对应的类名
  7. javascript call and apply
  8. 从零开始发布web项目(七)
  9. sprig aop事务配置
  10. Centos 7 zabbix 实战应用