Search Unity

Unity, and the Accelerometer vs. the Gyroscope: A Complete Guide

Discussion in 'General Discussion' started by Jjules, Jan 17, 2017.

  1. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,571
    One point is not enough.

    A simple brute force way to calculate position in AR would be having a marker take position of multiple corners of that marker, and then knowing parameters of the camera and real life size of the marker, calculate position of the camera - relative to the marker.

    See:
    https://docs.opencv.org/2.4/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html (see SolvePnP and SolvePnPRansac). This will give you slightly jittery position relative to the marker, as long as the camera can see it.

    Vuforia works the same way, by the way (unless something changed). You have a marker, and camera position is calcualted relative to the marker.

    However. This is used in situation when you don't have any assistance from any library and so on, and need to write everything by yourself.

    As far as I know, by now there are libraries like ARKit (Apple) and ARCore (Google). Those might make your life easier. Unfortunatley, while I worked with OpenCV (in unity) and Vuforia I didn't have a chance to mess with ARKit/ArCore.
     
    DarkUniverseGames likes this.
  2. waldgeist

    waldgeist

    Joined:
    May 6, 2017
    Posts:
    388
    I have a Unity AR app that locks the device orientation to Portrait. At the same time, I want to use the camera to shot photos, also in Landscape mode. So I am looking for a reliable way to implement my own orientation detection based on the Gyroscope.

    This article here
    https://answers.unity.com/questions/434096/lock-rotation-of-gyroscope-controlled-camera-to-fo.html
    kinda does the trick, but if you tilt the device too much, it reports wrong angles for the orientation.

    Does anybody know of a solution that includes tilt compensation?
     
  3. Enumerator_T

    Enumerator_T

    Joined:
    Nov 5, 2014
    Posts:
    16
    You can negate this by finding average values and lerping between constantly updating averages in microseconds.
     
  4. raggnic

    raggnic

    Joined:
    Sep 27, 2017
    Posts:
    13
    Thank you all for this thread, it's hard to find reliable info on this topic.

    I've been using Input.gyro.userAcceleration to try to estimate device acceleration of the phone in a car.
    Its supposed to be "true" acceleration with the gravity being removed ( from the doc https://docs.unity3d.com/ScriptReference/Gyroscope-userAcceleration.html)
    Idea is to use it to update world position between two GPS fix.

    Does it sound feasible?
     
    Marrt likes this.