예제 #1
0
        protected override IEnumerator Capture(bool anchor)
        {
            yield return(new WaitForSeconds(0.25f));

            m_bCaptureRunning = true;

            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)
            {
                CoroutineJobCapture j = new CoroutineJobCapture();
                j.host   = this;
                j.run    = (int)(m_ImageRun & 0xEFFFFFFF);
                j.index  = m_ImageIndex++;
                j.anchor = anchor;

                if (useGPS)
                {
                    j.latitude  = m_Latitude;
                    j.longitude = m_Longitude;
                    j.altitude  = m_Altitude;
                }
                else
                {
                    j.latitude = j.longitude = j.altitude = 0.0;
                }

                Camera     cam = this.mainCamera;
                Quaternion _q  = cam.transform.rotation;
                Matrix4x4  r   = Matrix4x4.Rotate(new Quaternion(_q.x, _q.y, -_q.z, -_q.w));
                Vector3    _p  = cam.transform.position;
                Vector3    p   = new Vector3(_p.x, _p.y, -_p.z);
                j.rotation   = r;
                j.position   = p;
                j.intrinsics = HWARHelper.GetIntrinsics();
                j.width      = image.Width;
                j.height     = image.Height;

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

                if (m_SessionFirstImage)
                {
                    m_SessionFirstImage = false;
                }

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

            m_bCaptureRunning = false;
            var captureButton = workspaceManager.captureButton.GetComponent <Button>();

            captureButton.interactable = true;
        }
예제 #2
0
        protected override IEnumerator Capture(bool anchor)
        {
            yield return(new WaitForSeconds(0.25f));

            m_bCaptureRunning = true;
            float captureStartTime = Time.realtimeSinceStartup;
            float uploadStartTime  = Time.realtimeSinceStartup;

            ARCameraImageBytes image = null;
            bool isHD = HWARHelper.TryGetCameraImageBytes(out image);

            if (image != null && image.IsAvailable)
            {
                CoroutineJobCapture j = new CoroutineJobCapture();
                j.host   = this;
                j.run    = (int)(m_ImageRun & 0xEFFFFFFF);
                j.index  = m_ImageIndex++;
                j.anchor = anchor;

                if (gpsOn)
                {
                    j.latitude  = m_Latitude;
                    j.longitude = m_Longitude;
                    j.altitude  = m_Altitude;
                }
                else
                {
                    j.latitude = j.longitude = j.altitude = 0.0;
                }

                Camera     cam = this.mainCamera;
                Quaternion _q  = cam.transform.rotation;
                Matrix4x4  r   = Matrix4x4.Rotate(new Quaternion(_q.x, _q.y, -_q.z, -_q.w));
                Vector3    _p  = cam.transform.position;
                Vector3    p   = new Vector3(_p.x, _p.y, -_p.z);
                j.rotation   = r;
                j.position   = p;
                j.intrinsics = isHD ? HWARHelper.GetIntrinsics() : HWARHelper.GetIntrinsics(image.Width, image.Height);
                int width  = image.Width;
                int height = image.Height;

                byte[] pixels;
                int    channels = 0;

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

                byte[] capture = new byte[channels * width * height + 1024];

                Task <(string, icvCaptureInfo)> t = Task.Run(() =>
                {
                    icvCaptureInfo info = Core.CaptureImage(capture, capture.Length, pixels, width, height, channels);
                    return(Convert.ToBase64String(capture, 0, info.captureSize), info);
                });

                while (!t.IsCompleted)
                {
                    yield return(null);
                }

                j.encodedImage = t.Result.Item1;
                NotifyIfConnected(t.Result.Item2);

                if (m_SessionFirstImage)
                {
                    m_SessionFirstImage = false;
                }

                j.OnStart += () =>
                {
                    uploadStartTime = Time.realtimeSinceStartup;
                    mappingUIManager.SetProgress(0);
                    mappingUIManager.ShowProgressBar();
                };
                j.OnSuccess += (SDKImageResult result) =>
                {
                    if (result.error == "none")
                    {
                        float et = Time.realtimeSinceStartup - uploadStartTime;
                        Debug.Log(string.Format("Image uploaded successfully in {0} seconds", et));
                    }

                    mappingUIManager.HideProgressBar();
                };
                j.OnProgress += (float progress) =>
                {
                    int value = (int)(100f * progress);
                    Debug.Log(string.Format("Upload progress: {0}%", value));
                    mappingUIManager.SetProgress(value);
                };

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

                float elapsedTime = Time.realtimeSinceStartup - captureStartTime;
                Debug.Log(string.Format("Capture in {0} seconds", elapsedTime));
            }

            m_bCaptureRunning = false;
            var captureButton = workspaceManager.captureButton.GetComponent <Button>();

            captureButton.interactable = true;
        }