Exemplo n.º 1
0
        public override void LocalizeServer()
        {
            ARCameraImageBytes image = null;

            if (m_Sdk.androidResolution == ImmersalSDK.CameraResolution.Max)
            {
                try
                {
                    image = ARFrame.AcquirPreviewImageBytes();
                }
                catch (NullReferenceException e)
                {
                    Debug.LogError("Cannot acquire FullHD image: " + e.Message);

                    image = ARFrame.AcquireCameraImageBytes();
                }
            }
            else
            {
                image = ARFrame.AcquireCameraImageBytes();
            }

            if (image != null && image.IsAvailable)
            {
                CoroutineJobLocalizeServer j = new CoroutineJobLocalizeServer();
                j.host = this;

                if (this.useGPS)
                {
                    j.useGPS    = true;
                    j.latitude  = m_Latitude;
                    j.longitude = m_Longitude;
                    j.radius    = DefaultRadius;
                }

                Camera cam = this.mainCamera;
                j.rotation   = cam.transform.rotation;
                j.position   = cam.transform.position;
                j.intrinsics = HWARHelper.GetIntrinsics();
                j.width      = image.Width;
                j.height     = image.Height;

                HWARHelper.GetPlaneData(out j.pixels, image);
                j.channels = 1;

                m_Jobs.Add(j);
                image.Dispose();
            }
        }
Exemplo n.º 2
0
        public override void LocalizeServer()
        {
            ARCameraImageBytes image = null;
            bool isHD = HWARHelper.TryGetCameraImageBytes(out image);

            if (image != null && image.IsAvailable)
            {
                CoroutineJobLocalizeServer j = new CoroutineJobLocalizeServer();

                if (gpsOn)
                {
                    j.useGPS    = true;
                    j.latitude  = m_Latitude;
                    j.longitude = m_Longitude;
                    j.radius    = DefaultRadius;
                }
                else
                {
                    int n = pcr.Count;

                    j.mapIds = new SDKMapId[n];

                    int count = 0;
                    foreach (int id in pcr.Keys)
                    {
                        j.mapIds[count]      = new SDKMapId();
                        j.mapIds[count++].id = id;
                    }
                }

                Camera     cam    = this.mainCamera;
                Vector3    camPos = cam.transform.position;
                Quaternion camRot = cam.transform.rotation;
                j.host       = this;
                j.rotation   = camRot;
                j.position   = camPos;
                j.intrinsics = isHD ? HWARHelper.GetIntrinsics() : HWARHelper.GetIntrinsics(image.Width, image.Height);
                j.width      = image.Width;
                j.height     = image.Height;

                HWARHelper.GetPlaneData(out j.pixels, image);
                j.channels = 1;

                j.OnResult += (SDKLocalizeResult result) =>
                {
                    /*if (result.error == "none")
                     * {*/
                    if (result.success)
                    {
                        Matrix4x4 m          = Matrix4x4.identity;
                        Matrix4x4 cloudSpace = Matrix4x4.identity;
                        cloudSpace.m00 = result.r00; cloudSpace.m01 = result.r01; cloudSpace.m02 = result.r02; cloudSpace.m03 = result.px;
                        cloudSpace.m10 = result.r10; cloudSpace.m11 = result.r11; cloudSpace.m12 = result.r12; cloudSpace.m13 = result.py;
                        cloudSpace.m20 = result.r20; cloudSpace.m21 = result.r21; cloudSpace.m22 = result.r22; cloudSpace.m23 = result.pz;
                        Matrix4x4 trackerSpace = Matrix4x4.TRS(camPos, camRot, Vector3.one);
                        this.stats.locSucc++;

                        Debug.Log("*************************** On-Server Localization Succeeded ***************************");
                        Debug.Log("fc 4x4\n" + cloudSpace + "\n" +
                                  "ft 4x4\n" + trackerSpace);

                        m = trackerSpace * (cloudSpace.inverse);

                        foreach (KeyValuePair <int, PointCloudRenderer> p in this.pcr)
                        {
                            if (p.Key == result.map)
                            {
                                p.Value.go.transform.position = m.GetColumn(3);
                                p.Value.go.transform.rotation = m.rotation;
                                break;
                            }
                        }

                        CoroutineJobEcef je = new CoroutineJobEcef();
                        je.host       = this;
                        je.id         = result.map;
                        je.OnSuccess += (SDKEcefResult result2) =>
                        {
                            if (result2.error == "none")
                            {
                                Debug.Log(result2.ecef);
                                LocalizerPose lastLocalizedPose;
                                LocalizerBase.GetLocalizerPose(out lastLocalizedPose, result.map, cloudSpace.GetColumn(3), cloudSpace.rotation, m.inverse, result2.ecef);
                                this.lastLocalizedPose = lastLocalizedPose;
                            }
                            else
                            {
                                Debug.LogError(result2.error);
                            }
                        };

                        m_Jobs.Add(je);
                    }
                    else
                    {
                        this.stats.locFail++;
                        Debug.Log("*************************** On-Server Localization Failed ***************************");
                    }

                    /*}
                     * else
                     * {
                     *  Debug.LogError(result.error);
                     * }*/
                };

                m_Jobs.Add(j);
                image.Dispose();
            }
        }