Log in or register to post comments

Yes you can use Unity 4.0.

December 14, 2012 - 12:53pm #21

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. 

That's wonderfull ! I'll try

December 14, 2012 - 12:50pm #20

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?

I'll see if we can clean that

December 14, 2012 - 12:45pm #19

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. 

Thanks guys, I just came back

December 14, 2012 - 12:42pm #18

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...

Filter Camera Position and Rotation to avoid jitter?

October 7, 2012 - 11:08pm #17

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!

Filter Camera Position and Rotation to avoid jitter?

October 4, 2012 - 9:37am #16

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?

September 27, 2012 - 2:07pm #15

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

Filter Camera Position and Rotation to avoid jitter?

August 14, 2012 - 6:41am #14

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

Re: Filter Camera Position and Rotation to avoid jitter?

May 3, 2012 - 7:08am #13

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.

Re: Filter Camera Position and Rotation to avoid jitter?

May 2, 2012 - 2:44pm #12

Please do.

Re: Filter Camera Position and Rotation to avoid jitter?

May 2, 2012 - 2:31pm #11

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 1, 2012 - 2:03pm #10

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?

April 20, 2012 - 5:40am #9
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?

April 20, 2012 - 1:04am #8

Hmmm What verison of Vuforia are you developing from ?

Re: Filter Camera Position and Rotation to avoid jitter?

April 16, 2012 - 2:09am #7

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 11, 2012 - 12:39am #6
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 11, 2012 - 12:26am #5

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 10, 2012 - 3:19pm #4
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 10, 2012 - 1:23am #3

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 9, 2012 - 1:39pm #2

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.

Pages

Log in or register to post comments