Local Area Description: Learning

不羁的心 提交于 2019-12-12 04:40:39

问题


I've just started learning something about Google Tango and i am having some troubles in understanding how to implement Local Area Description Learning. I have followed one of the How-to-guides from the documentation, the one with Placing Virtual Objects in AR and i wanted the app to remember the places where those kittens were placed. I will attach the Scene from Unity and a script where I've tried to enable SaveCurrent method for AreaDEscription. The scene from Unity and the following code is mainly the one from the How-To-Guide where i have tried to create another Thread for saving the current AreaDescription

public class KittyUIController : MonoBehaviour
{
Thread thread;
public GameObject m_kitten;
private TangoPointCloud m_pointCloud;

void Start()
{
    m_pointCloud = FindObjectOfType<TangoPointCloud>();
    thread = new Thread(Thread123);
}

void Update()
{
    if (Input.touchCount == 1)
    {
        // Trigger place kitten function when single touch ended.
        Touch t = Input.GetTouch(0);
        if (t.phase == TouchPhase.Ended)
        {
            PlaceKitten(t.position);
            thread.Start();
        }
    }
}

void PlaceKitten(Vector2 touchPosition)
{
    // Find the plane.
    Camera cam = Camera.main;
    Vector3 planeCenter;
    Plane plane;
    if (!m_pointCloud.FindPlane(cam, touchPosition, out planeCenter, out plane))
    {
        Debug.Log("cannot find plane.");
        return;
    }

    // Place kitten on the surface, and make it always face the camera.
    if (Vector3.Angle(plane.normal, Vector3.up) < 30.0f)
    {
        Vector3 up = plane.normal;
        Vector3 right = Vector3.Cross(plane.normal, cam.transform.forward).normalized;
        Vector3 forward = Vector3.Cross(right, plane.normal).normalized;
        Instantiate(m_kitten, planeCenter, Quaternion.LookRotation(forward, up));
    }
    else
    {
        Debug.Log("surface is too steep for kitten to stand on.");
    }
}

void Thread123()
{
    AreaDescription.SaveCurrent();
}

public void OnApplicationQuit()
{
    thread.Abort();
}

}


回答1:


I don't have enough reputation points to comment so I post my answer here. You should provide more details about what is working, and what is not.

First, start with this page, because you need to set up AreaLearning properly in your App. Then, examine this code and the corresponding AreaLearning scene example, this is all you need to do want you want to do.

Something that is not in the turorial nor in the code, and that is very important to make it work is that you need to check "Use Area Description" in the "Tango AR Pose Controller" of the "Tango AR Camera" prefab (or Tango Camera, if you are using the latest SDK's prefab), otherwise your objects won't be placed regarding the ADF base frame.

If I had to sum it all up, the workflow is:

  1. Load an existing ADF (in learning mode or not) or start learning a new one.
  2. If an existing ADF is loaded, relocalize (if you load an ADF in learning mode, this can take a longer time)
  3. Once relocalized, load the xml storing your objects (in your cas the kittens). The XML usually have the same name as the ADF's UUID and is stored in the Application.persistentDataPath (Android/data/com.YourApp/files). All the loaded objects will be placed regarding the ADF base frame.
  4. For each new kitten that you place, record the timestamp when you place it. This time stamp will allow you to recover the transformation between the frame when you placed the kitten and the ADF base frame.
  5. When you save to the XML, thanks to the transformation, you will be able to save the cordinates of the kitten regarding the ADF base frame (in the example, the transformation is computed in _UpdateMarkersForLoopClosures).

In the example, they reload the scene after they save, so they go back to the AreaDescriptionPicker screen but it is up to you to decide how you want to do this.

I really don't know what more to say. Hope this helps.



来源:https://stackoverflow.com/questions/45798171/local-area-description-learning

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!