コード例 #1
0
        public override void Localize()
        {
            XRCpuImage      image;
            ARCameraManager cameraManager   = m_Sdk.cameraManager;
            var             cameraSubsystem = cameraManager.subsystem;

            if (cameraSubsystem != null && cameraSubsystem.TryAcquireLatestCpuImage(out image))
            {
                CoroutineJobLocalize j = new CoroutineJobLocalize();
                Camera     cam         = this.mainCamera;
                Vector3    camPos      = cam.transform.position;
                Quaternion camRot      = cam.transform.rotation;
                j.intrinsics = ARHelper.GetIntrinsics();
                j.width      = image.width;
                j.height     = image.height;
                j.rotation   = camRot;
                j.position   = camPos;
                j.OnSuccess += (int mapId, Vector3 position, Quaternion rotation) =>
                {
                    this.stats.locSucc++;

                    Debug.Log("*************************** Localization Succeeded ***************************");
                    Matrix4x4 cloudSpace   = Matrix4x4.TRS(position, rotation, Vector3.one);
                    Matrix4x4 trackerSpace = Matrix4x4.TRS(camPos, camRot, Vector3.one);
                    Debug.Log("id " + mapId + "\n" +
                              "fc 4x4\n" + cloudSpace + "\n" +
                              "ft 4x4\n" + trackerSpace);

                    Matrix4x4 m = trackerSpace * (cloudSpace.inverse);

                    LocalizerPose lastLocalizedPose;
                    LocalizerBase.GetLocalizerPose(out lastLocalizedPose, mapId, position, rotation, m.inverse);
                    this.lastLocalizedPose = lastLocalizedPose;

                    foreach (PointCloudRenderer p in this.pcr.Values)
                    {
                        if (p.mapId == mapId)
                        {
                            p.go.transform.position = m.GetColumn(3);
                            p.go.transform.rotation = m.rotation;
                            break;
                        }
                    }
                };
                j.OnFail += () =>
                {
                    this.stats.locFail++;
                    Debug.Log("*************************** Localization Failed ***************************");
                };

                ARHelper.GetPlaneData(out j.pixels, image);
                m_Jobs.Add(j);
                image.Dispose();
            }
        }
コード例 #2
0
ファイル: Mapper.cs プロジェクト: XRBASE/arcloud-sdk-samples
        public override void Localize()
        {
            XRCameraImage   image;
            ARCameraManager cameraManager   = m_Sdk.cameraManager;
            var             cameraSubsystem = cameraManager.subsystem;

            if (cameraSubsystem != null && cameraSubsystem.TryGetLatestImage(out image))
            {
                CoroutineJobLocalize j = new CoroutineJobLocalize();
                Camera cam             = this.mainCamera;
                j.intrinsics = ARHelper.GetIntrinsics();
                j.width      = image.width;
                j.height     = image.height;
                j.rotation   = cam.transform.rotation;
                j.position   = cam.transform.position;
                j.host       = this;

                ARHelper.GetPlaneData(out j.pixels, image);
                m_Jobs.Add(j);
                image.Dispose();
            }
        }
コード例 #3
0
        public void Localize()
        {
            XRCameraImage image;

            if (m_CameraManager.TryGetLatestImage(out image))
            {
                CoroutineJobLocalize j = new CoroutineJobLocalize();
                Camera cam             = Camera.main;
                j.rotation   = cam.transform.rotation;
                j.position   = cam.transform.position;
                j.intrinsics = ARHelper.GetIntrinsics(m_CameraManager);
                j.width      = image.width;
                j.height     = image.height;
                j.stats      = this.stats;
                j.pcr        = this.pcr;

                XRCameraImagePlane plane = image.GetPlane(0);                 // use the Y plane
                j.pixels = new byte[plane.data.Length];
                plane.data.CopyTo(j.pixels);
                jobs.Add(j);
                image.Dispose();
            }
        }