主要是设置识别的范围,在应用内检测当前识别图和我的距离,以及识别图和我的角度,当进入了规定的范围和角度后,

在进行定位功能。我目前用的是距离在两米内 摄像机和识别图的角度正负不超过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的优化的更多相关文章

  1. UNITY3d在移动设备上的一些优化实战(一)-概述

    转自:UNITY3d在移动设备上的一些优化实战(一)-概述 http://blog.csdn.net/leonwei/article/details/39233921 项目进入了中期之后,就需要对程序 ...

  2. [AR]高通Vuforia Getting Started

    Vuforia Getting Started 简介 ​ Vuforia创建增强现实应用程序是一个软件平台.开发人员可以轻松地将先进的计算机视觉功能添加到任何应用程序中,允许它识别图像和对象,或在现实 ...

  3. UNITY3d在移动设备上的一些优化实战

    项目进入了中期之后,就需要对程序在移动设备上的表现做分析评估和针对性的优化了,首先前期做优化,很多瓶颈没表现出来,能做的东西不多,而且很多指标会凭预想,如果太后期做优化又会太晚,到时发现一些问题改起来 ...

  4. [AR]高通Vuforia之Frame Markers

    软件环境 SDK:FrameMarkers-6-0-112.unitypackage(从官网 -> Download -> Samples -> Core Features 下载 ) ...

  5. 与下位机或设备的通信解析优化的一点功能:T4+动态编译

        去年接触的一个项目中,需要通过TCP与设备进行对接的,传的是Modbus协议的数据,然后后台需要可以动态配置协议解析的方式,即寄存器的解析方式,,配置信息有:Key,数据Index,源数据类型 ...

  6. 【Unity]】AR小工具-Vuforia

    很有意思的增强现实玩具,六分钟应用. https://www.youtube.com/watch?v=khavGQ7Dy3c

  7. AR中的SLAM(一)

    写在前面 本系列打算讲讲个人对AR行业和AR中的SLAM算法的一点浅显的看法.才疏学浅,文中必然有很多疏漏和不足,还望能和大家多多讨论.今天先讲讲我对AR的一些认识. AR的一点理解 AR是什么 AR ...

  8. 关于AR,你想要的全在这儿了

    定义 增强现实(Augmented Reality,简称AR),是一种实时地计算摄影机影像的位置及角度并加上相应图像的技术,这种技术的目标是在屏幕上把虚拟世界套在现实世界并进行互动.这种技术估计由19 ...

  9. Vuforia开发完全指南---Vuforia概述

    Vuforia概述 AR(Augmented Reality)增强现实,想必大家都已经很熟悉了.这是当下最热的技术之一,是利用计算机视觉和计算机图像学领域的相关知识将虚拟世界融入到现实生活当中.AR和 ...

  10. VR与AR的发展趋势分析

    概要 你是否想象过与神秘的深海生物近距离接触?你是否梦想过穿戴钢铁侠那样的超先进科技装备成为超级英雄?你又是否幻想过与梦中的女神面对面的交流?这些可能在以前都只能是存在于脑海中的幻想,可是在如今有一项 ...

随机推荐

  1. 10.关于synchronized的一切,我都写在这里了

    大家好,我是王有志.关注王有志,一起聊技术,聊游戏,从北漂生活谈到国际风云. 之前我们已经通过3篇文章由浅到深的分析了synchronized的用法和原理: synchronized的基础:synch ...

  2. 使用SQL获取当前周别,oracle日期处理

    使用SQL获取当前周别 select to_char(sysdate,'yyyyww') from dual  select to_char(to_date('20200611','yyyymmdd' ...

  3. CF1051E Vasya and Big Integers

    [CF1051E Vasya and Big Integers](Problem - E - Codeforces) sb的做法 单调队列乱整( #include<bits/stdc++.h&g ...

  4. 详解 Gulp4 和 Gulp3 的区别

    最近在开发几个网站,为了优化一下前端代码,就复习一下gulpjs,之前工作gulp用的版本比较老,但是今天看了新的版本,新的语法出了一下,但是为了时间,我决定使用之前gulp3的旧版本,后面发现自己环 ...

  5. 如何通过Java应用程序添加或删除 PDF 中的附件

    当我们在制作PDF文件或者PPT演示文稿的时候,为了让自己的文件更全面详细,就会在文件中添加附件.并且将相关文档附加到 PDF 可以方便文档的集中管理和传输.那么如何添加或删除 PDF 中的附件呢?别 ...

  6. Qt添加自定义控件

    由于在自带的控件中没有发现滚动选择时间的控件,所以参考网上别人写的控件做了一点修改. 先看效果: 上代码: TimeScroll.h QT_BEGIN_NAMESPACE namespace Ui { ...

  7. Windows性能监控工具Perfmon的使用、性能指标分析

    Fighting_001 关注  0.1 2018.08.25 22:18* 字数 1488 阅读 7604评论 0喜欢 4 目录结构 一.Perfmon简介.性能监控指标.性能对象指标 1.常用的性 ...

  8. 阿里百秀后台管理项目笔记 ---- Day03

    来吧展示: step1:所有文章数据展示 引入 functions.php 文件执行数据库查询以及判断用户登录状态 require_once '../functions.php'; get_useri ...

  9. ChatGpt国内教程

    近ChatGPT大火呀,小伙伴们是不是在网上看到各种和ChatGPT有趣聊天的截图,比如翻译代码.编写代码,奈何自己实力不够,被网络拒之门外,只能眼馋别人的东西.看别人玩,肯定不如自己玩一把舒服的啊. ...

  10. 用ksweb+Android做服务器,搭建WordPress博客环境

    旧的安卓手机不要仍,安装上ksweb给wordpress做服务器,隔壁小孩都馋哭了. 为了能在自己的安卓手机服务器上写博客,首先我们来了解一下WordPress和ksweb: WordPress是使用 ...