AR抖动问题的探究
今天是第一次写博客,想想就写一下前一段时间研究的关于AR抖动问题。抖动一直是AR实现探讨的问题,主要和两方面有关:识别算法和识别图质量。底层算法的识别定位有关,算法的核心是定位识别的物体。另一个有很大关系的就是识别图的质量,就是特征点的数量,这点是我们可以改变的,但是有些状况也很难避免识别出来的模型抖动问题,比如现场实时识别,采集的现场识别图质量在高,在现场由于光线和角度的差别,模型会在不停的抖动,由于项目需要,不得不解决这个问题,当前面两点(算法,识别图)都不能改变的情况下,
那就要通过对识别的目标进行采样,将识别的模型与展示的模型分开处理。以此提出了相应的解决方案:
解决思路大致是这样:让其缓动而不是抖动,获取ImageTarget的实时位置,然后引入采样帧数,在采样时间内采集物体的位移变化量,对采样的模型偏移量进行累加,然后在完成采样后控制物体在执行时间进行移动。移动公式如下
x’= lerp(Pos , Pos+Pos’ ,t’/t)
x’ :物体移动距离
Pos : 上一次采样后物体位置
Pos‘ : 采样时间内内位移的累加和
t : 采样时间
t’ : 执行时间
完成计算后,x’就是物体移动的距离。
最后附上代码:
using System;
using UnityEngine;public class MainScript : MonoBehaviour {public GameObject GamePannel;public GameObject TargetPos;public Vector3 pos;public int SamplingNumber = 10;private bool FindObjState = true;private int NumCount = 0;private int MovCount = 0;private Quaternion IndexRoa;private Vector3 IndexPos;private Vector3 MovePos;private Quaternion MoveRoa;void Update(){DelayMove();}public void SetPannelActive(bool Istrue){FindObjState = Istrue;GamePannel.SetActive(Istrue);}void DelayMove(){if (FindObjState){//Debug.Log("true");NumCount += 1;//Pos记录IndexPos.x = TargetPos.transform.localPosition.x - GamePannel.transform.localPosition.x + IndexPos.x + pos.x; IndexPos.y = TargetPos.transform.localPosition.y - GamePannel.transform.localPosition.y + IndexPos.y + pos.y;IndexPos.z = TargetPos.transform.localPosition.z - GamePannel.transform.localPosition.z + IndexPos.z + pos.z;//Roa记录IndexRoa.x = TargetPos.transform.rotation.x - GamePannel.transform.rotation.x + IndexRoa.x;IndexRoa.y = TargetPos.transform.rotation.y - GamePannel.transform.rotation.y + IndexRoa.y;IndexRoa.z = TargetPos.transform.rotation.z - GamePannel.transform.rotation.z + IndexRoa.z;IndexRoa.w = TargetPos.transform.rotation.w - GamePannel.transform.rotation.w + IndexRoa.w;if (NumCount >= SamplingNumber){NumCount = 0;//Debug.Log("x :" + X_dev + " y :" + Y_dev + " z :" + Z_dev);MovePos = new Vector3(IndexPos.x / (float) Math.Pow(SamplingNumber, 2), IndexPos.y / (float)Math.Pow(SamplingNumber, 2), IndexPos.z / (float)Math.Pow(SamplingNumber, 2));MoveRoa = new Quaternion(IndexRoa.x / (float)Math.Pow(SamplingNumber, 2),IndexRoa.y / (float)Math.Pow(SamplingNumber, 2), IndexRoa.z / (float)Math.Pow(SamplingNumber, 2), IndexRoa.w / (float)Math.Pow(SamplingNumber, 2));IndexPos = new Vector3(0,0,0);IndexRoa = new Quaternion(0, 0, 0, 0);MovCount = SamplingNumber;}if (Math.Abs(MovePos.x) > 0.001 || Math.Abs(MovePos.y) > 0.001 || Math.Abs(MovePos.z) > 0.001 && MovCount>0){MovCount -= 1;Vector3 new_pos = new Vector3(GamePannel.transform.localPosition.x + MovePos.x, GamePannel.transform.localPosition.y + MovePos.y, GamePannel.transform.localPosition.z + MovePos.z);GamePannel.transform.localPosition = new_pos;}if (Math.Abs(MoveRoa.x) > 0.001 || Math.Abs(MoveRoa.y) > 0.001 || Math.Abs(MoveRoa.z) > 0.001 && MovCount > 0){MovCount -= 1;Quaternion new_roa = new Quaternion(GamePannel.transform.rotation.x + MoveRoa.x,GamePannel.transform.rotation.y + MoveRoa.y, GamePannel.transform.rotation.z + MoveRoa.z, GamePannel.transform.rotation.w + MoveRoa.w);GamePannel.transform.rotation = new_roa;}}
}}
最后需要补充的是FindObjState是在识别成功的状态值,修改该状态应该是在识别的回调函数。此外也是抛砖引玉,希望有大牛可以一起交流。
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
