AR设备使用Vuforia的优化
主要是设置识别的范围,在应用内检测当前识别图和我的距离,以及识别图和我的角度,当进入了规定的范围和角度后,
在进行定位功能。我目前用的是距离在两米内 摄像机和识别图的角度正负不超过30度的范围
VuforiaManager 管理
VuforialFindImageAction 识别图上,设置对应管理里的第几个VuforiaAnchor
VuforiaAnchor 定位的物体,注意旋转,Z轴要和Camera 看向物体的方向一致(反正180 自己测一下)
/****************************
summary: ****************************/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI; public class VuforiaManager : MonoSingleton<VuforiaManager>
{
/// <summary>
/// 当前生成的场景
/// </summary>
public Transform sceneMap;
//[SerializeField]
//private List<Transform> list_ImageTargetObj;
[SerializeField]
public List<VuforiaAnchor> list_Anchor;
private VuforiaAnchor oldAnchor; public Text text;
public bool isCorrect;
private void Start()
{
oldAnchor = null; StartCoroutine(LoadARCamera());
isCorrect = false;
} //private void Update()
//{
// if (oldAnchor != null)
// text.text = oldAnchor.transform.eulerAngles.x + " " + oldAnchor.transform.eulerAngles.y + " " + oldAnchor.transform.eulerAngles.z;
//}
public void TrackingFound(Transform targetObj , int num)
{
try
{
if (list_Anchor.Count < (num+1) || list_Anchor.Count < 1)
return;
SelectSceneAnchor(targetObj, num);
}
catch (System.Exception e)
{
Debug.LogError(e.Message);
}
} public void TrackingLost(int num)
{
if (list_Anchor.Count < (num+1) || list_Anchor.Count < 1)
return;
list_Anchor[num].Close();
} public void SelectSceneAnchor(Transform targetObj, int num)
{
if (oldAnchor == null)
{
oldAnchor = list_Anchor[num];
oldAnchor.Show(targetObj);
}
else if (oldAnchor == list_Anchor[num])
{
// oldTarget.DirectClose();
oldAnchor.ReplaceShow();
}
else if (oldAnchor != list_Anchor[num])
{
oldAnchor.DirectClose();
oldAnchor = list_Anchor[num];
oldAnchor.Show(targetObj); // if(oldAnchor!=list_Anchor[num].gameObject)
}
} public void ARCameraLoad()
{
// StartCoroutine(LoadARCamera());
} IEnumerator LoadARCamera()
{
// yield return API_GSXR_Slam.SlamManager.IsRunning; yield return new WaitForSeconds(2f);
GameObject.Instantiate(Resources.Load<GameObject>("ARCamera"));
} }
/****************************
summary: 计算锚点差值,定位场景 ****************************/
using System.Collections;
using System.Collections.Generic;
using UnityEngine; public class VuforiaAnchor : MonoBehaviour
{
private Transform targetObj = null; private bool state = false;
private bool onlySet = true;
// private Collider[] coliders;
public Transform player; private float y;
private Vector3 disPos;
private float dic;
private Vector3 dir;
private Vector3 cross;
private float dot;
private float deg;
private void Start()
{
// player = API_SVR.GetHead();
} private void FixedUpdate()
{
/*
* 1.首次定位时直接整体 移动选择
* 2.后续矫正判断识别图和Player的公积和距离,在范围内再进行移动
*
*/
if (state && VuforiaManager.Instance.isCorrect)
{
if (player == null)
return; if (onlySet)
{
onlySet = false; y = targetObj.eulerAngles.y - transform.eulerAngles.y;
VuforiaManager.Instance.sceneMap.eulerAngles += new Vector3(0, y, 0);
disPos = targetObj.position - transform.position;
//Debug.Log(transform.position + " " + targetObj.position);
//Debug.Log(VuforiaManager.Instance.sceneMap.position);
//Debug.Log(" DisPos " + disPos);
VuforiaManager.Instance.sceneMap.position += disPos;
}
else
{ Vector3 disPos = targetObj.position - transform.position;
disPos = VuforiaManager.Instance.sceneMap.position + disPos;
VuforiaManager.Instance.sceneMap.position = Vector3.Lerp(VuforiaManager.Instance.sceneMap.position, disPos, Time.deltaTime * 10f); }
}
}
// 首次定位
public void Show( Transform targetObj)
{
Debug.Log(" Show ");
this.targetObj = targetObj;
// StartCoroutine(Show(1));
state = true;
onlySet = true;
} //再次定位
public void ReplaceShow()
{
state = true;
// onlySet = true;
// StartCoroutine(Show(1));
}
// 关闭
public void Close()
{
state = false;
}
// 强制关闭
public void DirectClose()
{
state = false;
} public void PhysicsCollider()
{
//coliders = Physics.OverlapSphere(transform.position, 2.5f, 8);
//player = coliders[0].transform;
//if (coliders.Length>1)
//{
// Debug.LogError(" 检测玩家个数设置错误 ");
// return;
//} } IEnumerator Show(float timer)
{
yield return new WaitForSeconds(timer); float y = targetObj.eulerAngles.y - transform.eulerAngles.y;
VuforiaManager.Instance.sceneMap.eulerAngles += new Vector3(0, y, 0); Vector3 disPos = targetObj.position - transform.position;
Debug.Log(transform.position + " " + targetObj.position);
Debug.Log(VuforiaManager.Instance.sceneMap.position);
Debug.Log(" DisPos " + disPos); VuforiaManager.Instance.sceneMap.position += disPos;
} }
using System.Collections;
using System.Collections.Generic;
using UnityEngine; public class VuforialFindImageAction : DefaultTrackableEventHandler
{
public string Name;
// [HideInInspector]
public TargetObjDeg targetObj;
// [HideInInspector]
public int num;
[HideInInspector]
public int pointObj;
protected override void OnTrackingFound()
{ //if (VuforialMap.Instance != null)
// VuforialMap.Instance.TargetPointShow(this);
if (VuforiaManager.Instance != null)
{
Debug.Log(num);
// VuforialControl.Instance.TrackingFound(targetObj, num, pointObj);
VuforiaManager.Instance.TrackingFound(targetObj.transform, num);
targetObj.state = true;
}
base.OnTrackingFound(); } protected override void OnTrackingLost()
{ // VuforialControl.Instance.TrackingLost(num);
if(VuforiaManager.Instance!=null)
{
Debug.Log(num);
VuforiaManager.Instance.TrackingLost(num);
targetObj.state = false;
} //if (VuforialMap.Instance != null)
// VuforialMap.Instance.TargetPointClose(this);
base.OnTrackingLost();
}
} public enum ShowObj
{
ScenicSpot = 0,
Rotue = 1,
obj3D = 2
}
AR设备使用Vuforia的优化的更多相关文章
- UNITY3d在移动设备上的一些优化实战(一)-概述
转自:UNITY3d在移动设备上的一些优化实战(一)-概述 http://blog.csdn.net/leonwei/article/details/39233921 项目进入了中期之后,就需要对程序 ...
- [AR]高通Vuforia Getting Started
Vuforia Getting Started 简介 Vuforia创建增强现实应用程序是一个软件平台.开发人员可以轻松地将先进的计算机视觉功能添加到任何应用程序中,允许它识别图像和对象,或在现实 ...
- UNITY3d在移动设备上的一些优化实战
项目进入了中期之后,就需要对程序在移动设备上的表现做分析评估和针对性的优化了,首先前期做优化,很多瓶颈没表现出来,能做的东西不多,而且很多指标会凭预想,如果太后期做优化又会太晚,到时发现一些问题改起来 ...
- [AR]高通Vuforia之Frame Markers
软件环境 SDK:FrameMarkers-6-0-112.unitypackage(从官网 -> Download -> Samples -> Core Features 下载 ) ...
- 与下位机或设备的通信解析优化的一点功能:T4+动态编译
去年接触的一个项目中,需要通过TCP与设备进行对接的,传的是Modbus协议的数据,然后后台需要可以动态配置协议解析的方式,即寄存器的解析方式,,配置信息有:Key,数据Index,源数据类型 ...
- 【Unity]】AR小工具-Vuforia
很有意思的增强现实玩具,六分钟应用. https://www.youtube.com/watch?v=khavGQ7Dy3c
- AR中的SLAM(一)
写在前面 本系列打算讲讲个人对AR行业和AR中的SLAM算法的一点浅显的看法.才疏学浅,文中必然有很多疏漏和不足,还望能和大家多多讨论.今天先讲讲我对AR的一些认识. AR的一点理解 AR是什么 AR ...
- 关于AR,你想要的全在这儿了
定义 增强现实(Augmented Reality,简称AR),是一种实时地计算摄影机影像的位置及角度并加上相应图像的技术,这种技术的目标是在屏幕上把虚拟世界套在现实世界并进行互动.这种技术估计由19 ...
- Vuforia开发完全指南---Vuforia概述
Vuforia概述 AR(Augmented Reality)增强现实,想必大家都已经很熟悉了.这是当下最热的技术之一,是利用计算机视觉和计算机图像学领域的相关知识将虚拟世界融入到现实生活当中.AR和 ...
- VR与AR的发展趋势分析
概要 你是否想象过与神秘的深海生物近距离接触?你是否梦想过穿戴钢铁侠那样的超先进科技装备成为超级英雄?你又是否幻想过与梦中的女神面对面的交流?这些可能在以前都只能是存在于脑海中的幻想,可是在如今有一项 ...
随机推荐
- Mac对文件夹加密
一.打开磁盘工具 电脑左上角文件->新建映像->基于文件夹新建映像->选择相对应的文件夹,进行aes加密->输入加密密码 然后保存文件就好了
- 蓝桥真题——最短路 & 门牌制作
题目1 最短路 标签:填空题 2019 省赛 如下图所示,G 是一个无向图,其中蓝色边的长度是 1.橘色边的长度是 2.绿色边的长度是 3. 则从 A 到 S 的最短距离是多少? 答案 由图可得,最短 ...
- 从 GPT2 到 Stable Diffusion:Elixir 社区迎来了 Hugging Face
上周,Elixir 社区向大家宣布,Elixir 语言社区新增从 GPT2 到 Stable Diffusion 的一系列神经网络模型.这些模型得以实现归功于刚刚发布的 Bumblebee 库.Bum ...
- 实操好用~~~~~antd 中 Table表格动态合并~~~
我写了两种方法 一种是前端处理数据渲染 一种是后端处理数据渲染 数据结构略有不同 下面上代码 <template> <page-view :title="title&quo ...
- 前端防错以及好用小tips指南总结
@前端防錯以及好用小tips指南總結 1.一般情況下我們接收到的都是對象格式,某些情況下,需要接到後端傳過來的奇怪的字符串格式的JSON,需要解析成對象,但是有時候他們傳過來的格式有問題,會報錯 解決 ...
- C#Autofac依赖注入批量注入 (目前版本.netcore3.0)
上一文:C#依赖注入一看就会系列 链接:C#依赖注入(直白明了)讲解 一看就会系列 - 22222220 - 博客园 (cnblogs.com) 上一次我们知道了 为什么要依赖注入,这次我们就用使用人 ...
- 【学习日志】MySQL分表与索引的关系
什么情况下需要分表呢?分表又能解决什么问题呢? 一般情况下分表的直接原因是数据量太大了,比如一张表一共只有1w条数据,确实没必要分表.为什么数据量大了就需要分表呢?首先得看看数量量过大后会带来什么问题 ...
- 2.5.scrollView和swiper组件的使用
# scroll-view 可滚动视图区域.用于区域滚动. 需注意在webview渲染的页面中,区域滚动的性能不及页面滚动. 属性说明 属性名 类型 默认值 说明 平台差异说明 scroll-x Bo ...
- Hyperledger Fabric部署与测试(Ubuntu)
Fabric部署与测试 Fabric部署与测试最正确的还是参照官方链接:Hyperledger Fabric官方链接 ok,接下来开始部署Fabric.(以Ubuntu为例) 一.部署Fabric 1 ...
- 软件设计原则(Principles)
设计模式的从许多优秀的软件中总结出来的 , 使用设计模式能够实现可复用.可维护.开发人员之间方便沟通设计和理解代码. Tips 对于模式的使用 , 不能拘泥于格式 , 事实上根据需要模式是可以演化的 ...