Search Unity

  1. Read here to learn more about our latest preview of the XR Interaction Toolkit.
    Dismiss Notice
  2. Click here to see what's on sale for the "Best of Super Sale" on the Asset Store
    Dismiss Notice
  3. Read here for Unity's latest plans on OpenXR.
    Dismiss Notice

How to alert a user if the ARkit tracking is not having enough feature points in Unity?

Discussion in 'AR' started by zyonneo, Jun 4, 2019.

  1. zyonneo

    zyonneo

    Joined:
    Apr 13, 2018
    Posts:
    360
    Consider an ARKit application using Unity.If a user is planning to place an object.While scanning with the device yellow particles show up.I believe it is according to the features/patterns it recognises it adds the yellow particles.The more features the more yellow particles.This will be helpful while creating persistence AR experience.Next time when the user loads the data he may scan the same area but while mapping initially the user might have saved with less feature points.Due to this the user may not able to experience the persistence. How to notify the user before saving the data that he has sufficient feature points while scanning. I came up with the code below that will show if the camera is having insufficient feature points.

    Code (CSharp):
    1. public enum ARTrackingStateReason
    2. {
    3.     /** Tracking is not limited. */
    4.     ARTrackingStateReasonNone,
    5.  
    6.     /** Tracking is limited due to initialization in progress. */
    7.     ARTrackingStateReasonInitializing,
    8.  
    9.     /** Tracking is limited due to a excessive motion of the camera. */
    10.     ARTrackingStateReasonExcessiveMotion,
    11.  
    12.     /** Tracking is limited due to a lack of features visible to the camera. */
    13.     ARTrackingStateReasonInsufficientFeatures,
    14.  
    15.     /** Tracking is limited due to a relocalization in progress. */
    16.     ARTrackingStateReasonRelocalizing,
    17. }
    The above code works only if I cover the camera fully with my hand or the scene is really dark.The state will show Insufficient features.But my problem is I want to notify user while scanning that the feature points are not good, if there is not enough features or patterns.I want to make sure that the user tracking session will be a smooth tracking one.Later loads the data,scans the surface,loads models and have an persistence AR experience.


    See the pictures from 1 to 3 as marked in picture.

    Pic 1 shows only less feature points,so want to notify the user that feature point is less while scanning or tracking .How to show this?

    Pic 2 shows enough feature points,once we keep our models on top of it and save the map.Later for persistence when we load the arworldmap the models can easily recognise the same place and mounts the 3d model there just as saved earlier.

    Pic 3 shows some advanced features.The green shows good tracking features,the red colour shows less tracking.Any idea how to attain this feature?
     
  2. zyonneo

    zyonneo

    Joined:
    Apr 13, 2018
    Posts:
    360
    Code (CSharp):
    1. public ParticleSystem pointCloudParticlePrefab;
    2. public int maxPointsToShow;
    3. public float particleSize = 1.0f;
    4. Vector3[] m_PointCloudData;
    5. bool frameUpdated = false;
    6. ParticleSystem currentPS;
    7. ParticleSystem.Particle [] particles;
    8.  
    9.  
    10. //For creating instance of class
    11. public static PointCloudParticleExample pointinstance;
    12.  
    13. // Use this for initialization
    14. void Start ()
    15. {
    16.     UnityARSessionNativeInterface.ARFrameUpdatedEvent += ARFrameUpdated;
    17.     WorldMapManager.offevent += particlesoff;//Added event
    18.     currentPS = Instantiate (pointCloudParticlePrefab);
    19.     m_PointCloudData = null;
    20.     frameUpdated = false;
    21.     pointinstance = this;
    22. }
    23.  
    24. public void ARFrameUpdated(UnityARCamera camera)
    25. {
    26.     if (camera.pointCloud != null)
    27.     {
    28.        m_PointCloudData = camera.pointCloud.Points;
    29.     }
    30.     frameUpdated = true;
    31. }
    32.  
    33. // Update is called once per frame
    34. void Update ()
    35. {
    36.  
    37.     if (frameUpdated)
    38.     {
    39.         if (m_PointCloudData != null && m_PointCloudData.Length > 0 && maxPointsToShow > 0)
    40.         {
    41.             int numParticles = Mathf.Min (m_PointCloudData.Length, maxPointsToShow);
    42.             ParticleSystem.Particle[] particles = new ParticleSystem.Particle[numParticles];
    43.             int index = 0;
    44.             foreach (Vector3 currentPoint in m_PointCloudData)
    45.             {    
    46.                 particles [index].position = currentPoint;
    47.                 particles [index].startColor = new Color (1.0f, 1.0f, 1.0f);
    48.                 particles [index].startSize = particleSize;
    49.                 index++;
    50.                 if (index >= numParticles) break;
    51.             }
    52.             currentPS.SetParticles (particles, numParticles);
    53.  
    54.  
    55.         }
    56.         else
    57.         {
    58.             ParticleSystem.Particle[] particles = new ParticleSystem.Particle[1];
    59.             particles [0].startSize = 0.0f;
    60.             currentPS.SetParticles (particles, 1);
    61.         }
    62.         frameUpdated = false;
    63.     }
    64. }
    If I get the particle count may I able to do this? If I set that if pointclouds counts are less then insufficient features while counts are more than an average value(which needed to be found) will have sufficient features which will help on arworldmap tracking later?
     
unityunity