How to reduce AR camera shaking ?

+2 votes
asked Sep 5, 2017 by tberthin (180 points)
edited Sep 5, 2017 by tberthin

Hello,

I saw the post about reducing vibrations of 3D gameobject augmented from target. (post : https://answers.easyar.com/30/reduce-vibration-gameobject-imagetarget-unity-app-android?show=39#a39 )

kenn mentioned looking at FrameUpdate event, applying lerp to the target result and writing back the position/rotation. I tried to but I can't manage to apply Vector3.Lerp before the ARCamera's position and rotation get updated (in an excessively precise way which creates the display' shaking).

I also tried too add an other ARCamera but I guess I didn't understand how Unity and EasyAR work because I can't get a camera to render reality while another renders the gameobject from target after smoothing its camera's position.

Would someone have any idea or method to smooth the display ?

Thanks 
 

3 Answers

+1 vote
answered Sep 5, 2017 by albert52 (31,850 points)
selected Sep 6, 2017 by tberthin
 
Best answer
hi,

First need to set the world center at Augmenter for Augmenter
And then rewrite the Update method in ImageTarge's EasyImageTargetBehaviour class

    protected override void Update()
        {
            base.Update();
            float myrx = 0;
            myrx = this.transform.localEulerAngles.x;
            while (myrx >= 360)
            {
                myrx -= 360;
            }
            while (myrx <= -360)
            {
                myrx += 360;
            }
            while (myrx > 270 && 360 - myrx >= 0)
                myrx = -(360 - myrx);
            float myry = 0;
            myry = this.transform.localEulerAngles.y;
            while (myry >= 360)
            {
                myry -= 360;
            }
            while (myry <= -360)
            {
                myry += 360;
            }
        
            while (myry > 270 && 360 - myry >= 0)
                myry = -(360 - myry);

            float myrz = 0;
            myrz = this.transform.localEulerAngles.z;
            while (myrz >= 360)
            {
                myrz -= 360;
            }

            while (myrz <= -360)
            {
                myrz += 360;
            }

            while (myrz > 270 && 360 - myrz >= 0)
                myrz = -(360 - myrz);
              
               if (((Math.Abs(this.transform.position.x - lastX) > 0.06 || Math.Abs(this.transform.position.y - lastY) > 0.06 || Math.Abs(this.transform.position.z - lastZ) > 0.06)&&
            (Math.Abs(this.transform.position.x - lastX) > 0.13 || Math.Abs(this.transform.position.y - lastY) > 0.13 || Math.Abs(this.transform.position.z - lastZ) > 0.13))||
            ( (Math.Abs(myrx - lastRX) > 3 &&Math.Abs(myry - lastRY) >3 &&Math.Abs(myrz - lastRZ) > 3)&& (Math.Abs(myrx - lastRX) > 6 || Math.Abs(myry - lastRY) > 6 || Math.Abs(myrz - lastRZ) > 6))
                {
                    lastX = this.transform.position.x;
                    lastY = this.transform.position.y;
                    lastZ = this.transform.position.z;
                    lastRX = myrx;
                    lastRY = myry;
                    lastRZ = myrz;
                this.transform.rotation = Quaternion.Euler(lastRX, lastRY, lastRZ);
                this.transform.position = new Vector3(lastX, lastY, lastZ);
                }
                else
                {
             
                    this.transform.rotation = Quaternion.Euler(lastRX, lastRY, lastRZ);
                    this.transform.position = new Vector3(lastX, lastY, lastZ);
                }
           
        }
commented Sep 13, 2017 by hacaro (160 points)
Unfortunately this code gave me some errors.  Can you please check ?

where LastX, LastY, LastZ ?  

Better is to have some step to follow

Thanks in advance
commented Sep 13, 2017 by albert52 (31,850 points)
hi,
You need to set the appropriate value
commented Oct 14, 2017 by tonicg (110 points)
As said before by another user, that code make errors. Not usable at all.
Please, bring more easy to understand step by step instructions, or the developers we'll have more hard to implement EasyAR on our project.
We understand that you are making a lot of efforts, also translating tutorials to at least English, but this is really needed if you want people around the world be able to use your SDK.
Thanks in advance for all help to the community.
commented Mar 1, 2018 by qcode-linus (330 points)
edited Mar 1, 2018 by qcode-linus
come on guys.. just think a little bit....

you need this on the top:

float lastX;    float lastRX;
float lastY;    float lastRY;
float lastZ;    float lastRZ;

and use Mathf not Math ...

try some other value for 0.06 / 0.13  and 3 / 6 to optimzie it for your projekt...
commented Mar 1, 2018 by albert52 (31,850 points)
The next version will be released soon. ļ¼ˆoptimized image trackingļ¼‰
commented Mar 2, 2018 by qcode-linus (330 points)
awesome.. nice work with the EasyAR SDK!
commented Mar 7, 2018 by kordou (180 points) 1 flag
hi,
is this working also for the V2 sdk? because i do not have an augmenter and I have huge problem of shaking a video plane ...

thanks
commented May 10, 2018 by psedoykin (120 points)
Hi, do you have some news about new version ? when is should be released ?
+1 vote
answered May 5, 2018 by outlinegorilla (180 points)
my 3d objects vibrate also.... hope they fix it ....
+2 votes
answered Oct 15, 2018 by guinunez (200 points)

Hi, based on this thread, I worked on a solution to this. 

This script fixes the model shake behavior on EasyAr v2. You should use this instead of ImageTargetBehaviour on your target. Just delete the ImageTargetBehaviour component and add this one.
 

https://gist.github.com/guinunez/83fc638b37a43d57ef30e6966f66bd76

This can still be improved a lot, but it is good enough for me.

Welcome to EasyAR SDK Q&A, where you can ask questions and receive answers from other members of the community.
...