Log in or register to post comments

Filter Camera Position and Rotation to avoid jitter?

April 9, 2012 - 11:43am #121

Can i do that?

I'm trying to figure where is the camera transform updated, but i can't find it.

Can i filter those values so i can avoid some jitter in the camera? Basically, smooth the movement of the camera, something like a low pass filter, because it jitters too much and is very noticeable.

Cheers.

Re: Filter Camera Position and Rotation to avoid jitter?

April 9, 2012 - 1:39pm #120

Hi,

Started to look at this as well - We have implemented a crude lerp lowpass filter in Tracker.PositionTrackable and Tracker.PositionCamera but no joy as of yet. :cool:

Will post a reply when we have an acceptable result.

Re: Filter Camera Position and Rotation to avoid jitter?

April 10, 2012 - 1:23am #119

Thanks setentis.

I've taken another approach, but it's not too goo either.

I've created another camera an assigned it as MainCamera (i also untagged the AR camera), deactivated the AR camera (the camera, not the game object) and i've assigned an script to the new camera to do a soft follow of the original camera with two lerps, one for the position and another for the rotation (with two different dampering values), after that i pick the projection matrix and the fov from the AR camera and put it into the new camera.
Apart from that i've modified the QCARBehaviour.cs script to assign the background to my new camera, inside

case CameraState.DEVICE_INITED:

I can notice the result, but i'm not very pleased with it.

There is another thing, is there a way to detect when my current marker is gone from the screen, i mean, i want to avoid the delay between a marker is lost and the object dissappears, but i don't know how.

Cheers and thanks for the answer.

Re: Filter Camera Position and Rotation to avoid jitter?

April 10, 2012 - 3:19pm #118
Quote:

There is another thing, is there a way to detect when my current marker is gone from the screen, i mean, i want to avoid the delay between a marker is lost and the object dissappears, but i don't know how.

Not directly, but you could try projecting the four corners of the marker into screen space and checking to see if they're within the bounds of the screen.

http://unity3d.com/support/documentation/ScriptReference/Camera.WorldToScreenPoint.html

- Kim

Re: Filter Camera Position and Rotation to avoid jitter?

April 11, 2012 - 12:26am #117

In the end it was quite straight forward - simply ass a lowpass filter to the position and rotation in Tracker.PositionTrackable and Tracker.PositionCamera and you are golden.

Cheers
Sententis

Re: Filter Camera Position and Rotation to avoid jitter?

April 11, 2012 - 12:39am #116
sententis wrote:

In the end it was quite straight forward - simply ass a lowpass filter to the position and rotation in Tracker.PositionTrackable and Tracker.PositionCamera and you are golden.

Cheers
Sententis

Can you post some sample code.

Where should i use this low pass filter? (i mean, in which script?)

Is this a Lerp function?
Because that's what you said you used in the first post, but you wasn't very happy with it, did you achieved an optimal value for the dampering value for the Lerp?

Thanks, this are really good news.

BTW I'm protecting the corners of the trackables too, it's a great idea, it avoids jumps when a trackable is lost, but i use Camera.WorldToViewportPoint:

http://unity3d.com/support/documentation/ScriptReference/Camera.WorldToViewportPoint.html

This is because this returns you normalized values of the screen from 0.0 to 1.0 in X and Y, so you don't have to worry about screen resolution. :)

Cheers and thanks!

Re: Filter Camera Position and Rotation to avoid jitter?

April 16, 2012 - 2:09am #115

No news about that?

Where should i filter Tracker.PositionTrackable and Tracker.PositionCamera, i don't find those two.

Cheers.

Re: Filter Camera Position and Rotation to avoid jitter?

April 20, 2012 - 1:04am #114

Hmmm What verison of Vuforia are you developing from ?

Re: Filter Camera Position and Rotation to avoid jitter?

April 20, 2012 - 5:40am #113
sententis wrote:

Hmmm What verison of Vuforia are you developing from ?

Thanks for answering setentis.

I'm developing with the latest version available in the asset store, also with the latest update of Unity.

Cheers.

Re: Filter Camera Position and Rotation to avoid jitter?

May 1, 2012 - 2:03pm #112

Hi,
Any more news about the camera filter?
I worked this afternoon to create a filter without any success, by adding a smooth-damping to the camera position and rotation.
I'll try to change my algorithm by change the track position itself, to send the position only when a big position change appears, not an user hand shaking.

If anyone have a code that working it will great to share it under the community.

Thanks.

Re: Filter Camera Position and Rotation to avoid jitter?

May 2, 2012 - 2:31pm #111

Ok, after one more day working on it I've something good enough, I think.
I change directly the track position and orientation.
First of all I put a ceil to the position and orientation, if this limit is reached I update the new position/rotation.
With this new value, I apply a smooth damping to reach the new position/rotation.
The damping time is calculated with the acceleration of the camera position, more the camera move faster more the damping will have no effect.

If someone wants the code I'll put here, in order to optimize it.

Loic.

Re: Filter Camera Position and Rotation to avoid jitter?

May 2, 2012 - 2:44pm #110

Please do.

Re: Filter Camera Position and Rotation to avoid jitter?

May 3, 2012 - 7:08am #109

Ok, first the new Track.cs script, if you have more than one track at the same time, you should write the same code in the PositionTrackable function.

Tracker.cs

using UnityEngine;

public abstract class Tracker
{
    #region NESTED

    // Enumeration of the different tracker types
    public enum Type
    {
        IMAGE_TRACKER,    // Tracks ImageTargets and MultiTargets
        MARKER_TRACKER    // Tracks Markers
    }

    #endregion // NESTED

   #region PRIVATE _MEMBERS
   
   private Vector3 previousTrackPosition, previousTrackerOrientation, currentTrackPosition, currentTrackPositionRef;
   private float currentTrackOrientationX, currentTrackOrientationY, currentTrackOrientationZ, currentTrackOrientationXRef, currentTrackOrientationYRef, currentTrackOrientationZRef, acceleration = 0f, deltaPositionRef;
   private bool firstCall = true;
   #endregion
   
   #region PUBLIC_MEMBERS
   
   [HideInInspector]
   public float deltaPosition = .5f, deltaPositionRotation = 5f, dampingTime = .5f;
   
   #endregion

    #region PUBLIC_METHODS

    // Starts the Tracker
    public abstract bool Start();

    // Stops the Tracker
    public abstract void Stop();

    #endregion // PUBLIC_METHODS



    #region PROTECTED_METHODS

    // Position the camera relative to a Trackable
    protected void PositionCamera(TrackableBehaviour trackableBehaviour,
                                  Camera arCamera,
                                  QCARManager.PoseData camToTargetPose)
    {
      //First call of this function, init variables
      if(firstCall)
      {
         firstCall = false;
         previousTrackPosition = camToTargetPose.position;
         currentTrackPosition = previousTrackPosition;
         previousTrackerOrientation = camToTargetPose.orientation.eulerAngles;
         currentTrackOrientationX = previousTrackerOrientation.x;
         currentTrackOrientationY = previousTrackerOrientation.y;
         currentTrackOrientationZ = previousTrackerOrientation.z;
      }
      
      //If the position limit is reached, update the new position target
      if(Mathf.Abs (Vector3.Magnitude(camToTargetPose.position - previousTrackPosition)) > deltaPosition)
      {
         //And update the acceleration
         acceleration += (Mathf.Sign(Vector3.Magnitude(camToTargetPose.position - previousTrackPosition)) * deltaPosition * 100f);
         previousTrackPosition = camToTargetPose.position;
      }
      //Same for rotation
      if(Mathf.Abs (Vector3.Magnitude(camToTargetPose.orientation.eulerAngles - previousTrackerOrientation)) > deltaPositionRotation)
      {
         previousTrackerOrientation = camToTargetPose.orientation.eulerAngles;
      }
      
      Debug.Log("deltaPosition : " + Mathf.Abs (Vector3.Magnitude(camToTargetPose.position - previousTrackPosition)) + " dampingTime:" + (dampingTime / acceleration)); 
      Debug.Log( " previousTrackPosition :" + previousTrackPosition + "\npreviousTrackerOrientation:" + previousTrackerOrientation);
      
      //smoothdamping values with the actual value of position / rotation and the target
      currentTrackPosition = Vector3.SmoothDamp(currentTrackPosition, previousTrackPosition, ref currentTrackPositionRef, dampingTime / acceleration);
      currentTrackOrientationX = Mathf.SmoothDampAngle(currentTrackOrientationX, previousTrackerOrientation.x, ref currentTrackOrientationXRef,dampingTime / acceleration);
      currentTrackOrientationY = Mathf.SmoothDampAngle(currentTrackOrientationY, previousTrackerOrientation.y, ref currentTrackOrientationYRef,dampingTime / acceleration);
      currentTrackOrientationZ = Mathf.SmoothDampAngle(currentTrackOrientationZ, previousTrackerOrientation.z, ref currentTrackOrientationZRef,dampingTime / acceleration);
      
      //Create a quaternion from the the actual deg values
      Quaternion orientation = Quaternion.identity;
      orientation.eulerAngles = new Vector3(currentTrackOrientationX, currentTrackOrientationY, currentTrackOrientationZ);
      
      //smooth down acceleration
      acceleration = Mathf.SmoothDamp(acceleration, 0f, ref deltaPositionRef, 1f);
      
      //Calculate the new position
      Vector3 newPosition = trackableBehaviour.transform.rotation *
                Quaternion.AngleAxis(90, Vector3.left) *
                Quaternion.Inverse(orientation) *
                (-currentTrackPosition) +
                trackableBehaviour.transform.position;
      
      //Apply it
        arCamera.transform.localPosition = newPosition;
      
      //Calculate the new rotation and apply it
        arCamera.transform.rotation =
                trackableBehaviour.transform.rotation *
                Quaternion.AngleAxis(90, Vector3.left) *
                Quaternion.Inverse(orientation);
    }    
    
    // Position a Trackable relative to the Camera.
    protected void PositionTrackable(TrackableBehaviour trackableBehaviour,
                                     Camera arCamera,
                                     QCARManager.PoseData camToTargetPose)
    {
        trackableBehaviour.transform.position =
                arCamera.transform.TransformPoint(camToTargetPose.position);

        trackableBehaviour.transform.rotation =
                arCamera.transform.rotation *
                camToTargetPose.orientation *
                Quaternion.AngleAxis(270, Vector3.left);
    }

    #endregion // PROTECTED_METHODS
}

You have 3 variables that you should change values of them, "float deltaPosition = .5f, deltaPositionRotation = 5f, dampingTime = .5f;".

I've also changed the script attached to the ARCamera to see these variables and change them while testing with some GUI Sliders.

DataSetLoadBehaviour.cs


using System.Collections.Generic;
using UnityEngine;

public class DataSetLoadBehaviour : MonoBehaviour
{
    #region PROPERTIES

    public string DataSetToActivate
    {
        get
        {
            return mDataSetToActivate;
        }

        set
        {
            mDataSetToActivate = value;
        }
    }

    #endregion // PROPERTIES



    #region PRIVATE_MEMBER_VARIABLES

    [SerializeField]
    [HideInInspector]
    private string mDataSetToActivate;
   
   private ImageTracker lastTracker;
   private float testValue = 0.05f;

    #endregion // PRIVATE_MEMBER_VARIABLES



    #region PUBLIC_MEMBER_VARIABLES
    [SerializeField]
    [HideInInspector]
    public List<string> mDataSetsToLoad = new List<string>();
   
   public GUISkin skin;
    #endregion // PUBLIC_MEMBER_VARIABLES



    #region UNITY_MONOBEHAVIOUR_METHODS

    void Awake()
    {
        if (Application.isEditor)
        {
            return;
        }
        
        if (TrackerManager.Instance.GetTracker(Tracker.Type.IMAGE_TRACKER) == null)
        {
            TrackerManager.Instance.InitTracker(Tracker.Type.IMAGE_TRACKER);
        }

        if (mDataSetsToLoad.Count <= 0)
        {
            Debug.LogWarning("No data sets defined. Not loading any data sets.");
            return;
        }

        foreach (string dataSetName in mDataSetsToLoad)
        {
            if (!DataSet.Exists(dataSetName))
            {
                Debug.LogError("Data set " + dataSetName + " does not exist.");
                continue;
            }
            ImageTracker imageTracker = (ImageTracker)TrackerManager.Instance.GetTracker(Tracker.Type.IMAGE_TRACKER);
            DataSet dataSet = imageTracker.CreateDataSet();
         lastTracker = imageTracker;

            if (!dataSet.Load(dataSetName))
            {
                Debug.LogError("Failed to load data set " + dataSetName + ".");
                continue;
            }

            // Activate the data set if it is the one specified in the editor.
            if (mDataSetToActivate == dataSetName)
            {
                imageTracker.ActivateDataSet(dataSet);
            }
        }
    }


    void OnDestroy()
    {
        // Note we do not destroy the dataset as this is handled by the
        // QCARBehaviour.
    }
   
   void OnGUI()
   {
      GUI.skin = skin;
      if(lastTracker != null)
      {
         lastTracker.deltaPosition = GUI.HorizontalSlider(new Rect(0,0,Screen.width / 2f, Screen.height / 6f), lastTracker.deltaPosition,   0,0.2f);
         GUI.Label(new Rect(0,Screen.height / 6f,Screen.width / 2f, Screen.height / 6f), lastTracker.deltaPosition.ToString());
         lastTracker.deltaPositionRotation = GUI.HorizontalSlider(new Rect(0,Screen.height / 6f * 2f,Screen.width / 2f, Screen.height / 6f), lastTracker.deltaPositionRotation,   0f,180f);
         GUI.Label(new Rect(0,Screen.height / 6f * 3f,Screen.width / 2f, Screen.height / 6f), lastTracker.deltaPositionRotation.ToString());
         lastTracker.dampingTime = GUI.HorizontalSlider(new Rect(0,Screen.height / 6f * 4f,Screen.width / 2f, Screen.height / 6f), lastTracker.dampingTime,   0f,5f);
         GUI.Label(new Rect(0,Screen.height / 6f * 5f,Screen.width / 2f, Screen.height / 6f), lastTracker.dampingTime.ToString());
         
         
      }
      else
      {
         testValue = GUI.HorizontalSlider(new Rect(0,0,Screen.width / 2f, Screen.height / 6f), testValue,   0,0.1f);
         GUI.Label(new Rect(0,Screen.height / 6f,Screen.width / 2f, Screen.height / 6f), testValue.ToString());
      }
   }

    #endregion // UNITY_MONOBEHAVIOUR_METHODS

}

It works with very low values of these 3 variables, except maybe the damping one.
If you see anything on this code that could be optimized or upgraded please let me know.

Thanks.

Filter Camera Position and Rotation to avoid jitter?

August 14, 2012 - 6:41am #108

Just wanted to say thanks. Implemented it today and it works brilliantly and makes Vuforia seem much more polished

Filter Camera Position and Rotation to avoid jitter?

September 27, 2012 - 2:07pm #107

And a big thanks from me too. Solved a major issue for us here.

Filter Camera Position and Rotation to avoid jitter?

October 4, 2012 - 9:37am #106

What is your primary motivation for applying filtering of this sort? Is it to smooth the jitter associated w/ augmentations that are offset from the target?

Are you deactivating, or modifying the filter strength, while the camera is moving?

We've been discussing some approaches to smoothing, and are interested in understanding how and where this is being applied by developers.

 

Filter Camera Position and Rotation to avoid jitter?

October 7, 2012 - 11:08pm #105

I tried out loic_illogika's modified Tracker script, and the difference was night and day!  I am running with a lowered deltaPosition (.01) and deltaPositionRotation (.1), and I am getting MUCH smoother tracking than I was with the default tracking script.  Cheers, mate!

Thanks guys, I just came back

December 14, 2012 - 12:42pm #104

Thanks guys, I just came back to this thread and discovered your answer, I'm glad that is working for all of you :)

@DavidBeard:  I needed to apply a filter when I had object far from the marker. The more they are far, the more they are shaking.
And yes, the idea is to depend of the acceleration. 

PS: What a cool new website !
But the code I posted is now unusable...

I'll see if we can clean that

December 14, 2012 - 12:45pm #103

I'll see if we can clean that up, it's useful code. Please try the new SDK as well. You should see signfiicant improvements in stabilization with motion. 

That's wonderfull ! I'll try

December 14, 2012 - 12:50pm #102

That's wonderfull !

I'll try the new SDK ASAP. I guess it's Unity4 compatible? And how the editor mode is working? Is it using computer webcam?

Yes you can use Unity 4.0.

December 14, 2012 - 12:53pm #101

Yes you can use Unity 4.0. The play mode feature requires Unity Pro, because it uses a plugin. You can use either a built-in or attached webcam. 

I was waiting this update

December 14, 2012 - 12:55pm #100

I was waiting this update since so many months, good job guys \o/

Thank you !

Filter Camera Position and Rotation to avoid jitter?

February 3, 2013 - 2:14pm #99

I've updated your scripts for the 2.0 API. Please test them to confirm that they are behaving as expected.

 

Tracker.cs

/*==============================================================================
Copyright (c) 2010-2012 QUALCOMM Austria Research Center GmbH.
All Rights Reserved.
Qualcomm Confidential and Proprietary
==============================================================================*/

using UnityEngine;

/// <summary>
/// The common base class for the ImageTracker and the MarkerTracker
/// </summary>
public abstract class Tracker
{
    #region NESTED

    /// <summary>
    /// Enumeration of the different tracker types
    /// </summary>
    public enum Type
    {
        IMAGE_TRACKER,    // Tracks ImageTargets and MultiTargets
        MARKER_TRACKER    // Tracks Markers
    }

    #endregion // NESTED

   #region PRIVATE _MEMBERS
   
   private Vector3 previousTrackPosition, previousTrackerOrientation, currentTrackPosition, currentTrackPositionRef;
   private float currentTrackOrientationX, currentTrackOrientationY, currentTrackOrientationZ, currentTrackOrientationXRef, currentTrackOrientationYRef, currentTrackOrientationZRef, acceleration = 0f, deltaPositionRef;
   private bool firstCall = true;
	
   #endregion
	
   #region PUBLIC_MEMBERS
   
   [HideInInspector]
   public float deltaPosition = .5f, deltaPositionRotation = 5f, dampingTime = .5f;
   
   #endregion

    #region PUBLIC_METHODS

    /// <summary>
    /// Starts the Tracker
    /// </summary>
    public abstract bool Start();

    /// <summary>
    /// Stops the Tracker
    /// </summary>
    public abstract void Stop();

    #endregion // PUBLIC_METHODS



    #region PROTECTED_METHODS

    // Position the camera relative to a Trackable
    protected void PositionCamera(TrackableBehaviour trackableBehaviour,
                                  Camera arCamera,
                                  QCARManagerImpl.PoseData camToTargetPose)
    {
      //First call of this function, init variables
      if(firstCall)
      {
         firstCall = false;
         previousTrackPosition = camToTargetPose.position;
         currentTrackPosition = previousTrackPosition;
         previousTrackerOrientation = camToTargetPose.orientation.eulerAngles;
         currentTrackOrientationX = previousTrackerOrientation.x;
         currentTrackOrientationY = previousTrackerOrientation.y;
         currentTrackOrientationZ = previousTrackerOrientation.z;
      }
      
      //If the position limit is reached, update the new position target
      if(Mathf.Abs (Vector3.Magnitude(camToTargetPose.position - previousTrackPosition)) > deltaPosition)
      {
         //And update the acceleration
         acceleration += (Mathf.Sign(Vector3.Magnitude(camToTargetPose.position - previousTrackPosition)) * deltaPosition * 100f);
         previousTrackPosition = camToTargetPose.position;
      }
      //Same for rotation
      if(Mathf.Abs (Vector3.Magnitude(camToTargetPose.orientation.eulerAngles - previousTrackerOrientation)) > deltaPositionRotation)
      {
         previousTrackerOrientation = camToTargetPose.orientation.eulerAngles;
      }
      
      Debug.Log("deltaPosition : " + Mathf.Abs (Vector3.Magnitude(camToTargetPose.position - previousTrackPosition)) + " dampingTime:" + (dampingTime / acceleration)); 
      Debug.Log( " previousTrackPosition :" + previousTrackPosition + "\npreviousTrackerOrientation:" + previousTrackerOrientation);
      
      //smoothdamping values with the actual value of position / rotation and the target
      currentTrackPosition = Vector3.SmoothDamp(currentTrackPosition, previousTrackPosition, ref currentTrackPositionRef, dampingTime / acceleration);
      currentTrackOrientationX = Mathf.SmoothDampAngle(currentTrackOrientationX, previousTrackerOrientation.x, ref currentTrackOrientationXRef,dampingTime / acceleration);
      currentTrackOrientationY = Mathf.SmoothDampAngle(currentTrackOrientationY, previousTrackerOrientation.y, ref currentTrackOrientationYRef,dampingTime / acceleration);
      currentTrackOrientationZ = Mathf.SmoothDampAngle(currentTrackOrientationZ, previousTrackerOrientation.z, ref currentTrackOrientationZRef,dampingTime / acceleration);
      
      //Create a quaternion from the the actual deg values
      Quaternion orientation = Quaternion.identity;
      orientation.eulerAngles = new Vector3(currentTrackOrientationX, currentTrackOrientationY, currentTrackOrientationZ);
      
      //smooth down acceleration
      acceleration = Mathf.SmoothDamp(acceleration, 0f, ref deltaPositionRef, 1f);
      
      //Calculate the new position
      Vector3 newPosition = trackableBehaviour.transform.rotation *
                Quaternion.AngleAxis(90, Vector3.left) *
                Quaternion.Inverse(orientation) *
                (-currentTrackPosition) +
                trackableBehaviour.transform.position;
      
      //Apply it
        arCamera.transform.localPosition = newPosition;
      
      //Calculate the new rotation and apply it
        arCamera.transform.rotation =
                trackableBehaviour.transform.rotation *
                Quaternion.AngleAxis(90, Vector3.left) *
                Quaternion.Inverse(orientation);
    }    
    

    // Position a Trackable relative to the Camera.
    protected void PositionTrackable(TrackableBehaviour trackableBehaviour,
                                     Camera arCamera,
                                     QCARManagerImpl.PoseData camToTargetPose)
    {
        trackableBehaviour.transform.position =
                arCamera.transform.TransformPoint(camToTargetPose.position);

        trackableBehaviour.transform.rotation =
                arCamera.transform.rotation *
                camToTargetPose.orientation *
                Quaternion.AngleAxis(270, Vector3.left);
    }


    #endregion // PROTECTED_METHODS
}

DataSetLoadBehaviour.cs

 

/*==============================================================================
Copyright (c) 2010-2012 QUALCOMM Austria Research Center GmbH.
All Rights Reserved.
Qualcomm Confidential and Proprietary
==============================================================================*/

using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// This behaviour allows to automatically load and activate one or more DataSet on startup
/// </summary>
public class DataSetLoadBehaviour : MonoBehaviour
{
    #region PRIVATE_MEMBER_VARIABLES

    [SerializeField]
    [HideInInspector]
    public List<string> mDataSetsToActivate = new List<string>();
	
	private ImageTracker lastTracker;
   	private float testValue = 0.05f;

    #endregion // PRIVATE_MEMBER_VARIABLES



    #region PUBLIC_MEMBER_VARIABLES

    [SerializeField]
    [HideInInspector]
    public List<string> mDataSetsToLoad = new List<string>();
	
	public GUISkin skin;
    #endregion // PUBLIC_MEMBER_VARIABLES



    #region UNITY_MONOBEHAVIOUR_METHODS

    void Awake()
    {
        if (!QCARRuntimeUtilities.IsQCAREnabled())
        {
            return;
        }

        if (QCARRuntimeUtilities.IsPlayMode())
        {
            // initialize QCAR 
            QCARUnity.CheckInitializationError();
        }

        if (TrackerManager.Instance.GetTracker(Tracker.Type.IMAGE_TRACKER) == null)
        {
            TrackerManager.Instance.InitTracker(Tracker.Type.IMAGE_TRACKER);
        }

        if (mDataSetsToLoad.Count <= 0)
        {
            Debug.LogWarning("No data sets defined. Not loading any data sets.");
            return;
        }

        foreach (string dataSetName in mDataSetsToLoad)
        {
            if (!DataSet.Exists(dataSetName))
            {
                Debug.LogError("Data set " + dataSetName + " does not exist.");
                continue;
            }

            ImageTracker imageTracker = (ImageTracker)TrackerManager.Instance.GetTracker(Tracker.Type.IMAGE_TRACKER);
            DataSet dataSet = imageTracker.CreateDataSet();
			
			lastTracker = imageTracker;

            if (!dataSet.Load(dataSetName))
            {
                Debug.LogError("Failed to load data set " + dataSetName + ".");
                continue;
            }

            // Activate the data set if it is the one specified in the editor.
            if (mDataSetsToActivate.Contains(dataSetName))
            {
                imageTracker.ActivateDataSet(dataSet);
            }
        }
    }
	
	void OnGUI()
   {
      GUI.skin = skin;
      if(lastTracker != null)
      {
         lastTracker.deltaPosition = GUI.HorizontalSlider(new Rect(0,0,Screen.width / 2f, Screen.height / 6f), lastTracker.deltaPosition,   0,0.2f);
         GUI.Label(new Rect(0,Screen.height / 6f,Screen.width / 2f, Screen.height / 6f), lastTracker.deltaPosition.ToString());
         lastTracker.deltaPositionRotation = GUI.HorizontalSlider(new Rect(0,Screen.height / 6f * 2f,Screen.width / 2f, Screen.height / 6f), lastTracker.deltaPositionRotation,   0f,180f);
         GUI.Label(new Rect(0,Screen.height / 6f * 3f,Screen.width / 2f, Screen.height / 6f), lastTracker.deltaPositionRotation.ToString());
         lastTracker.dampingTime = GUI.HorizontalSlider(new Rect(0,Screen.height / 6f * 4f,Screen.width / 2f, Screen.height / 6f), lastTracker.dampingTime,   0f,5f);
         GUI.Label(new Rect(0,Screen.height / 6f * 5f,Screen.width / 2f, Screen.height / 6f), lastTracker.dampingTime.ToString());
         
         
      }
      else
      {
         testValue = GUI.HorizontalSlider(new Rect(0,0,Screen.width / 2f, Screen.height / 6f), testValue,   0,0.1f);
         GUI.Label(new Rect(0,Screen.height / 6f,Screen.width / 2f, Screen.height / 6f), testValue.ToString());
      }
   }


    #endregion // UNITY_MONOBEHAVIOUR_METHODS

}

 

Filter Camera Position and Rotation to avoid jitter?

February 3, 2013 - 7:43pm #98

This week I've to update an old project to vuforia 2.0, I'll tell you,

thanks !

Filter Camera Position and Rotation to avoid jitter?

February 13, 2013 - 6:44am #97

Hi guys,

I tried to implement this feature into the new version of the plugin.
It works pretty well, but I'm using user target mode, so I needed to change another script that do exactly the same thing (duplicated code :D), this is script is StateManagerImpl.cs.

You have the same function, called PositionCamera, that you need to change. Copy paste the function from the script Tracker.cs (don't forget variables !), and it will work.

I don't know if it's only related to user target mode, I don't really have the time now to test it right now.

Loic.

Filter Camera Position and Rotation to avoid jitter?

February 13, 2013 - 6:46am #96

Double post.

Filter Camera Position and Rotation to avoid jitter?

February 13, 2013 - 8:23am #95

Auww yess, that last bit is what the fix needed to make it work.

Thank you sir or madam, that script's a gem. Tell me, however...have you run into any gimbal lock issues?

Filter Camera Position and Rotation to avoid jitter?

February 13, 2013 - 8:28am #94

Sir :)

And no, I never had gimbal lock issues, but it could happen I guess because there is a conversion from a Vector3 to a Quaternion.
Honestly I made this little code when I joined the game dev industry a year ago and I'm sure now I can do better (without using any Vector3 for example).

But I tried it this morning and it works very well, mostly when you have objects far away from the center.

 

How about you, have you run into gimbal lock issues?

Filter Camera Position and Rotation to avoid jitter?

February 13, 2013 - 8:35am #93

I have up until now - I thought it was going crazy because of the axes alignment - but looks like it was the other way around - the noise causing axes alignment, not the alignment causing the noise.

Filter Camera Position and Rotation to avoid jitter?

February 23, 2013 - 12:51am #92

 

Hi,

I did many researches but I couldn’t find a proper answer. Is there a way to get the tracker rotation angles? I need to display several different images based on the tracker angle.
For example: In 0 degrees one image and in 10 degrees another image and it goes on...
For that I need to get the tracker rotation. Please acknowledge me on how to get the tracker angle, either from JAVA Android code or from C# code.
It will be great if this can be achieved by Java Android code, But even C# code also would be fine. 
Thanks in advance.

Amal.

Filter Camera Position and Rotation to avoid jitter?

February 23, 2013 - 6:08am #91

Hi,

the tracker is not rotating, it's the camera rotating around the tracker. So get the transform.eulerAngles.y to get the actual rotation.

But this question is off-topic, create a new thread if you want a better answer.

Filter Camera Position and Rotation to avoid jitter?

February 23, 2013 - 9:15am #90

Thank you (loic_illogika) very much for your support. Highly appriciate. I will try to do the code with your clue. I am opening a new thread for this topic. Looking forward for your support. It will be better if I can have a sample segement of code to have a clear idea. 

 

https://developer.vuforia.com/forum/general-discussion/how-get-camera-rotation-according-tracker

Please follow the link and help me on this when you have time. 
Thank in advance.

Filter Camera Position and Rotation to avoid jitter?

March 2, 2013 - 2:47pm #89

loic_illogika - your method has been very useful. I had to pump up the values quite a bit for my situation (deltaPosition = .0745f, deltaPositionRotation = 45f, dampingTime = 4.05f), but the damping helps.

However, useful as it might be, it doesn't completely meet the needs for my specific project since I'm using multiple targets. Can you point me in the right direction as to how I could change the code to accomodate damping of the targets, and not the camera?

Filter Camera Position and Rotation to avoid jitter?

March 2, 2013 - 11:36pm #88

Good question,

I didn't try, maybe DavidBeard can answer to this question.

Filter Camera Position and Rotation to avoid jitter?

April 5, 2013 - 8:31pm #87

Here is my way to smooth/dump QCAR's Harlem Shake :)

1. Edit method PositionCamera in StateManagerImpl.cs (code below. dont forget the bool)

http://clip2net.com/s/4RYwku (Pic)

http://pastebin.com/c34xGen4 (Code)

2. In DefaultTrackableEventHandler.cs in method OnTrackerFound add this line StateManagerImpl.isFoundTracker = true; (http://clip2net.com/s/4RYxfL)

   private void OnTrackingFound()
    {
		StateManagerImpl.isFoundTracker = true;
        Renderer[] rendererComponents = GetComponentsInChildren<Renderer>();
        Collider[] colliderComponents = GetComponentsInChildren<Collider>();
.........

3. In QCARBehaviour.cs declare two vars and assign lerpCoef to LerpCoef in Awake method

	public float lerpCoef = .4f;
	public static float LerpCoef = .4f;

 

	void Awake()
	{
		LerpCoef = lerpCoef;
	}

Then you can configure the smooth coefficient as you like in Inspector of ARCamera (http://clip2net.com/s/4RYzZC)

AttachmentSize
Binary Data bytes

Filter Camera Position and Rotation to avoid jitter?

May 15, 2013 - 10:58am #86

Thanks for posting it !

What kind of improvements did you do? 

Filter Camera Position and Rotation to avoid jitter?

July 17, 2013 - 3:14pm #85

Hi, 

I'm an independent developer working on a Vuforia project for iOS (and Android coming soon) -- really impressed with Vuforia overall by the way -- but encountering this same issue of the violent shaking. 

This is not really my area of expertise, and don't know anything about Unity. Can someone explain how this code (it's C#?) could be adapted into an iOS project? I not asking for it to be rewritten (though I wouldn't object) I just think DavidBeard's code is alot more self-explanatory to some people than to others.  Even just knowing which precise files to modify under iOS and which sections are new would be helpful. 

Or if there's a simpler way, such as just averaging the posematrix directly in renderFrameQCAR. I'll take less optimal results, but I have to do something, right now some flat planes coming straight out of the target on the z axis are flapping like flags in a hurricane. Thanks. 

Filter Camera Position and Rotation to avoid jitter?

July 17, 2013 - 4:03pm #84

Before you even attempt filtering the pose matrix, can you describe the implementation? - just to determine whether filtering will even help.

Are you seeing shaking because your model is significantly larger than your target, or offset from the target's origin, or is that you are far away from the target?

Filter Camera Position and Rotation to avoid jitter?

July 17, 2013 - 9:47pm #83

Before you even attempt filtering the pose matrix, can you describe the implementation? - just to determine whether filtering will even help.

Are you seeing shaking because your model is significantly larger than your target, or offset from the target's origin, or is that you are far away from the target?

 

Thanks for the quick reply. I think it's not far away because it happens when the target mostly occupies the screen. Also, as noted on another thread, the effect is lessened if not viewed head-on but at an angle.

I'm not sure if you can say the model is larger than the target, as I did think of something whilewriting this comment. Notably, the target is significantly wider than it is tall. This may be why the target flaps up and down on the y axis, but doesn't really move side-to-side. However, the targets are based on real-world images and I'm not going to get them changed in the course of this project.  

Being offset definitely has something to do with it, as the model currently is a long rectangle that extends straight out from the target (actually an arrow pointing to the target) though by less than the width of the target itself. It is offset y positive positively to be just above the target, centered on X though that could change. Currently, the point of the arrow "on" the target at z=0 mostly stays in place, but the offset side jitters: this exaggerates the jitter and creates the "flapping" effect. 

The flapping happens rapidly, and if it could stay displayed as the average of the range of its jitter, that would be great. Even if they fluttered less rapidly than a few times per second would be great - can you suggest a modification that updates the pose matrix less frequently instead of or in addition to using the average?

In exchagne for the average I'll gladly take the hit in responsiveness - this is new, unfamiliar technology, and I think it's reached an amazing point just recently - and the last message that we want to communicate to users is it's literally "shaky."  Thanks.  

Filter Camera Position and Rotation to avoid jitter?

July 19, 2013 - 8:47am #82

I think that you've accurately diagnosed the problem. Filtering may help, but you'll need to experiment w/ the weight of the filter. Are you using Unity or the native iOS SDK?

Though an easier and more reliable approach would be to orient the arrow differently, or use a different model.

Filter Camera Position and Rotation to avoid jitter?

August 19, 2013 - 2:23pm #81

Hello-

Forgive me if this is an oversight on my part - my C# skills aren't the strongest. Using Vuforia 2.6.7 with Unity 4

I've cut and paste the code exactly from the 2.x scripts DavidBeard posted. (BTW, you need to add the TEXT_TRACKER to the Type section to avoid an error)

All builds and works well, but I can't see much effect by moving the sliders or updaing the values manually (even when I use extreme values, like damping of 100). I assume doing this should give me drastic results, but if anything changes it's very subtle. I also notice I don't see the output of the Debug.Log statements in the Tracker.cs file. Not in the console of Unity using Play Mode or the output in XCode when building to a device. Should those show up somewhere? I guess I'm concerned the new code is never being run since I never see the log statements.

Thanks for any insight.

dp

Filter Camera Position and Rotation to avoid jitter?

August 19, 2013 - 3:01pm #80

What's your World Center Mode set to? That script filters the camera position relative to the target, which only occurs if a target serves as the scene origin (e.g. WCM = SPECIFIC_TARGET or FIRST_TARGET.

Also what are you trying to affect? - is your augmentation offset from the center of the target significantly, or is it that you're using a poor target?

Are you seeing a lot of shaking?

 

 

 

 

   
 

 

Filter Camera Position and Rotation to avoid jitter?

August 19, 2013 - 3:24pm #79

I'm using WCM = FIRST_TARGET, so that should be ok.

I'm using a 5-star target. I have 5 models that are spread across the target evenly, so it's not really an offset issue. 

Basically, if I have the camera stationary and put the target on something stationary, so no phyiscal movement, the AR still jumps around slightly / jitters. Not bad, and pretty consistent with previous AR projects I've done with Vuforia. I was hoping this script would alter it so if nothing is moving, there would be no movement of the AR. Is it unrealistic to expect that?

 

Filter Camera Position and Rotation to avoid jitter?

August 19, 2013 - 4:19pm #78

There will always be some jitter due to the nature of pose estimation, but it can be imperceptible.

One factor affecting jitter is the relative orientation of the plane of the target to that of the camera lense. Pose estimation benefits from some perspective distortion. You'll probably notice that the jitter is worse when the camera is parallel and centered on the target, for example.

Also tall targets will have more jitter than short ones, because their height is equivalent to lateral offset.

What you might try, is to deliberately move the models away fromt the target, and adjust the filter weight to determine if it's having any effect. It may be that there's something wrong and that the script needs to be revised. I'll take a look at it when I have a chance.

Filter Camera Position and Rotation to avoid jitter?

September 18, 2013 - 10:19am #77

Hello @DavidBeard.  Has there been any updates to this?  I was getting ready to implement this in an attempt to smooth things out for us and was hoping for an update.  

Also, I hope this isn't too noob, but in one of your earlier posts you say "Are you deactivating, or modifying the filter strength, while the camera is moving".  I looked through all my cameras and targets and didn't see anything regarding filter strenght.  Are you referring to the values applied to the variables in the smoothing script below?

Thanks!

-Mo

Filter Camera Position and Rotation to avoid jitter?

September 20, 2013 - 9:41am #76

Yes I'm referring to the filter in this thread. I haven't had a chance to update this for the current SDK version, but it shouldn't be difficult to do so. If you can send me a video to evaluate, I can advise on whether filtering might help.

Filter Camera Position and Rotation to avoid jitter?

September 23, 2013 - 8:11pm #75

I know there has been discussion about having a model that is much larger than the target, as well as significantly offset, but could having a model that is much smaller than the target also create jitter?

In the case of my project, the target is a map, so I'm having to use portions of the whole target to track an object specific to that area of the map. However, in another project, where the model is about the same size as the target and you view the entire target in the camera, the jitter is nearly imperceptible. It seems the less tracking information Vuforia has (i.e. the smaller percentage of the whole target that's in view), the more it's prone to make errors in position and rotation tracking. Which is understandable.

Filter Camera Position and Rotation to avoid jitter?

September 25, 2013 - 8:56am #74

That may be an issue if the larger target isn't being captured in the camera's field of view when observing the model. Have you tried dividing the target into sections and configuring these as a MultiTarget?

Filter Camera Position and Rotation to avoid jitter?

September 25, 2013 - 3:10pm #73

I converted my target to a multitarget, dividing the single map image into quadrants and adjusting the XML file manually so they were in the correct positions. On a small scale it does seem to have improved. I'll follow up here when I have tested it large scale.

Filter Camera Position and Rotation to avoid jitter?

November 5, 2013 - 8:58am #72

Does the new version of Vuforia use the Tracker.cs and does this low pass filter work?

 

I added the low pass filter stuff to my scripts and I don't get any of the debug messages, no errors and I can adjust the ongui slider but I get no debug statements and it makes no difference, so what has changed in the new version of vuforia vs. the examples at the bottom of this thread?

Filter Camera Position and Rotation to avoid jitter?

January 9, 2014 - 7:48am #71
Previous version (2.6.7)  vuforia works with StateManagerImpl.cs
Now with (2.8.7) this code was moved to Qualcomm.Vuforia.UnityExtensions.dll
 
If anybody want this library with simplest filter you can get it from attachments to this post
 
For setup filter you should set StateManagerImpl.isFoundTracker = true; when trackable found;
For adjust strength of filtering use StateManagerImpl.LerpCoef from 0 to 1
 
This library was compiled by mono for NET 3.5
 
Also i post code
 
public static bool isFoundTracker;
	public static float LerpCoef = 0.6f;

    private void PositionCamera(TrackableBehaviour trackableBehaviour, Camera arCamera, QCARManagerImpl.PoseData camToTargetPose)
    {
		//Debug.Log("PositionCam");
		if(isFoundTracker)
		{
			arCamera.transform.localPosition = trackableBehaviour.transform.rotation *
				Quaternion.AngleAxis(90, Vector3.left) *
					Quaternion.Inverse(camToTargetPose.orientation) *
					(-camToTargetPose.position) +
					trackableBehaviour.transform.position;
			
			arCamera.transform.rotation = trackableBehaviour.transform.rotation *
				Quaternion.AngleAxis(90, Vector3.left) *
					Quaternion.Inverse(camToTargetPose.orientation);
			isFoundTracker = false;
			Debug.Log("== SET POSE");
		}
		else
		{
			arCamera.transform.localPosition = Vector3.Lerp(arCamera.transform.localPosition, 
			                                                trackableBehaviour.transform.rotation *
			                                                Quaternion.AngleAxis(90, Vector3.left) *
			                                                Quaternion.Inverse(camToTargetPose.orientation) *
			                                                (-camToTargetPose.position) +
			                                                trackableBehaviour.transform.position, LerpCoef);
			
			arCamera.transform.rotation = Quaternion.Lerp( arCamera.transform.rotation, 
			                                              trackableBehaviour.transform.rotation *
			                                              Quaternion.AngleAxis(90, Vector3.left) *
			                                              Quaternion.Inverse(camToTargetPose.orientation), LerpCoef);
		}
    }

    private void PositionTrackable(TrackableBehaviour trackableBehaviour, Camera arCamera, QCARManagerImpl.PoseData camToTargetPose)
    {
		//Debug.Log("PositionTrackable");
		if(isFoundTracker)
		{
			trackableBehaviour.transform.position = arCamera.transform.TransformPoint(camToTargetPose.position);
			trackableBehaviour.transform.rotation = (arCamera.transform.rotation * camToTargetPose.orientation) * Quaternion.AngleAxis(270f, Vector3.left);
			isFoundTracker = false;
			Debug.Log("== SET POSE");
		}
		else
		{
			trackableBehaviour.transform.position = Vector3.Lerp(trackableBehaviour.transform.position, 
			                                                arCamera.transform.TransformPoint(camToTargetPose.position), LerpCoef);
			
			trackableBehaviour.transform.rotation = Quaternion.Lerp(trackableBehaviour.transform.rotation, 
			                                              (arCamera.transform.rotation * camToTargetPose.orientation) * Quaternion.AngleAxis(270f, Vector3.left), LerpCoef);
		}
    }

 

 

Log in or register to post comments