Exemple #1
0
    void Start()
    {
        StartCoroutine(HttpLongPollNotification("http://vcm-12481.vm.duke.edu/push/"));

        MLImageTracker.Start();
        MLImageTracker.Enable();
        MLImageTracker.AddTarget("sea", imageTarget, 0.279f, (target, result) =>
        {
            if (!_imageObjectAdded && result.Status == MLImageTargetTrackingStatus.Tracked)
            {
                Debug.Log("Image recognized.");

                DisplayAssets();

                _imageObjectAdded = true;
            }
        }, true);

        MLResult camera = MLCamera.Start();

        if (camera.IsOk)
        {
            MLCamera.Connect();
            Debug.Log("Camera Enabled");
        }

//        MLCamera.OnRawImageAvailable += delegate(byte[] jpegBytes) { StartCoroutine(Upload(jpegBytes)); };
//        StartCoroutine(Capture());
    }
Exemple #2
0
 /// <summary>
 /// Connects the MLCamera component and instantiates a new instance
 /// if it was never created.
 /// </summary>
 private void EnableMLCamera()
 {
     #if PLATFORM_LUMIN
     MLResult result = MLCamera.Start();
     if (result.IsOk)
     {
         result = MLCamera.Connect();
         if (_rawVideoCaptureMode)
         {
             MLCamera.OnRawVideoFrameAvailableYUV += OnRawCaptureDataReceived;
         }
         else
         {
             _rawVideoCaptureVisualizer.OnRawCaptureEnded();
         }
         _isCameraConnected = true;
     }
     else
     {
         Debug.LogErrorFormat("Error: VideoCaptureExample failed starting MLCamera, disabling script. Reason: {0}", result);
         enabled = false;
         return;
     }
     #endif
 }
Exemple #3
0
 /// <summary>
 /// Connects the MLCamera component and instantiates a new instance
 /// if it was never created.
 /// </summary>
 public bool EnableMLCamera()
 {
     if (MLCamera.Start())
     {
         _isCameraConnected = MLCamera.Connect();
     }
     return(_isCameraConnected);
 }
 private void enableExternalCamera()
 {
     MLog("enableExternalCamera :: External Camera Enabled");
     MLCamera.Start();
     MLCamera.Connect();
     MLCamera.StartPreview();
     externalCameraActive = true;
 }
        /// <summary>
        /// Connects the MLCamera component and instantiates a new instance
        /// if it was never created.
        /// </summary>
        public bool EnableMLCamera()
        {
            MLResult result = MLCamera.Start();

            if (result.IsOk)
            {
                result             = MLCamera.Connect();
                _isCameraConnected = result.IsOk;
            }
            return(_isCameraConnected);
        }
        /// <summary>
        /// Connects the MLCamera component and instantiates a new instance
        /// if it was never created.
        /// </summary>
        private void EnableMLCamera()
        {
            MLResult result = MLCamera.Start();

            if (result.IsOk)
            {
                result             = MLCamera.Connect();
                _isCameraConnected = true;
            }
            else
            {
                Debug.LogErrorFormat("Error: ImageCaptureExample failed starting MLCamera, disabling script. Reason: {0}", result);
                enabled = false;
                return;
            }
        }
        /// <summary>
        /// Connects the MLCamera component and instantiates a new instance
        /// if it was never created.
        /// </summary>
        private void EnableMLCamera()
        {
            MLResult result = MLCamera.Start();

            if (result.IsOk)
            {
                result = MLCamera.Connect();
                MLCamera.OnRawVideoFrameAvailableYUV += OnRawCaptureDataReceived;
                _isCameraConnected = true;
            }
            else
            {
                CheckPrivilegeDenied(result);
                Debug.LogErrorFormat("Error: RawVideoCaptureExample failed starting MLCamera, disabling script. Reason: {0}", result);
                enabled = false;
            }
        }
    void OnApplicationPause(bool pauseStatus)
    {
        if (!pauseStatus)
        {
            if (!MLLocation.IsStarted)
            {
                MLLocation.Start();
            }

            MLCamera.Start();
            MLCamera.Connect();
            MLCamera.StartPreview();
        }
        else
        {
            OnDisable();
        }
    }
Exemple #9
0
        /// <summary>
        /// Connects the MLCamera component and instantiates a new instance
        /// if it was never created.
        /// </summary>
        private void EnableMLCamera()
        {
            MLResult result = MLCamera.Start();

            if (result.IsOk)
            {
                result             = MLCamera.Connect();
                _isCameraConnected = true;
            }
            else
            {
                if (result.Code == MLResultCode.PrivilegeDenied)
                {
                    Instantiate(Resources.Load("PrivilegeDeniedError"));
                }

                Debug.LogErrorFormat("Error: VideoCaptureExample failed starting MLCamera, disabling script. Reason: {0}", result);
                enabled = false;
                return;
            }
        }
Exemple #10
0
        byte[] _colorsPost;      // Intermediate texture but half the width

        public void Enable()
        {
            MLCamera.Start().ThrowIfFail();
            MLCamera.Connect().ThrowIfFail();
            _previewTexture = MLCamera.StartPreview();

            _width  = MLCamera.PreviewTextureWidth;
            _height = MLCamera.PreviewTextureHeight;

            _computeBuffer = new ComputeBuffer(_width * _height * 3, sizeof(float));
            _computeShader = Resources.Load <ComputeShader>("AsyncRead");

            _kernel = _computeShader.FindKernel("CSMain");
            _computeShader.SetInt("_Width", _width);
            _computeShader.SetInt("_Height", _height);
            _computeShader.SetTexture(_kernel, "_SrcTex", _previewTexture);
            _computeShader.SetBuffer(_kernel, "_DstBuffer", _computeBuffer);

            _colors     = new float[_width * _height * 3];         // 3 = RGB
            _colorsPost = new byte[_width * _height * 3 / 2];      // 2 = half width
        }
    void OnEnable()
    {
        Logger.D(TAG, "Called OnEnable()...");

        // Start MagicLeap's Location service:
        if (!MLLocation.IsStarted)
        {
            MLLocation.Start();
        }

        // Needs a render Texture.
        Logger.D(TAG, "Calling Start to camera...");
        MLCamera.Start();
        Logger.D(TAG, "Calling Connect()...");
        MLCamera.Connect();

        Logger.D(TAG, "Calling StartPreview()...");
        MLCamera.StartPreview();

        Logger.D(TAG, "Setting texture sizes app side...");

        // Preview has fixed capture height and width. May need a prepare capture to do parameters not in preview.
        W = MLCamera.PreviewTextureWidth;
        H = MLCamera.PreviewTextureHeight;

        // Image width and height to send to face detection server
        ImageWidth  = 1440;
        ImageHeight = 1080;


        // Allocate space for render buffers:
        tmp = RenderTexture.GetTemporary(
            W,
            H,
            0,
            RenderTextureFormat.ARGB32,
            RenderTextureReadWrite.Linear);
        nt = new Texture2D(ImageWidth, ImageHeight, TextureFormat.ARGB32, false);
    }
Exemple #12
0
    private void StartCapture()
    {
        Debug.Log(MLCamera.IsStarted);
        MLResult result = MLCamera.Start();

        if (result.IsOk)
        {
            result = MLCamera.Connect();
            MLCamera.OnRawImageAvailable += OnCaptureRawImageComplete;
            isConnected = true;
        }
        else
        {
            isConnected = false;
            Debug.Log("Error: Start camera failed.");
            Debug.Log(result.Code);
            if (result.Code == MLResultCode.PrivilegeDenied)
            {
                Debug.LogError("Error: Privilege Denied.");
            }
        }
    }
 public void Enable()
 {
     MLCamera.Start().ThrowIfFail();
     MLCamera.Connect().ThrowIfFail();
     _previewTexture = MLCamera.StartPreview();
 }
Exemple #14
0
        async UniTask DoStart()
        {
            // Get a WiFi privilege
            await MLUtils.RequestPrivilege(MLPrivilegeId.LocalAreaNetwork);

            _credentials.ClearStorage();
            _client = new TWClient(_credentials, _credentials);

            _onApplicationResume = new Subject <Unit>();

            ClearLines();
            AppendLine("You may use a dummy Twitter account for this demo.");
            AppendLine("Press Trigger button to start...");

            // Wait for a trigger by user
            await MLUtils.OnTriggerUpAsObservable().ToUniTask(useFirstValue: true);

            ClearLines();
            AppendLine("You'll be prompted to open Helio shortly...");

            // Initiate 3-legged authentication.
            // Callback URL must be your app's URI configured in the manifest,
            // also must be registered in your Twitter app's "Callback URLs" list.
            // See https://forum.magicleap.com/hc/en-us/community/posts/360042601671
            // and https://developer.twitter.com/en/docs/basics/apps/guides/callback-urls
            string authUrl = await _client.GetUserAuthenticationUrl(_credentials.CallbackUrl);

            // Open the URL on Helio and let user log in to Twitter
            MLDispatcher.TryOpenAppropriateApplication(authUrl).ThrowIfFail();

            ClearLines();
            AppendLine("Waiting for a redirect from Helio...");
            AppendLine("(if you'd like to retry, please exit all apps)");

            /* Magic Leap's dispatcher is generally immature and
             * you'll find MANY causes of failure here
             * but for this demo I just let user initialize everything in such cases
             * for the simplicity of this code...
             */

            // Wait for getting redirected from Helio
            await _onApplicationResume.ToUniTask(useFirstValue : true);

            // Authorize using the redirect URL sent from Helio
            var redirectUrl = Environment.GetCommandLineArgs()[0];
            await _client.AuthorizeUser(redirectUrl);

            ClearLines();
            AppendLine("Authorized with your Twitter account!");
            AppendLine("Press Trigger button to tweet on your account");
            AppendLine("Please end this demo if your account is public)");

            // Wait for a trigger by user
            await MLUtils.OnTriggerUpAsObservable().ToUniTask(useFirstValue: true);

            // Tweet a sample text (note that all characters survive URL encoding)
            await _client.UpdateStatus("Tweeting from #MagicLeap using MLTwitter https://github.com/ryo0ka/MLTwitter");

            // Get the authorized user's latest status (which is the tweet above)
            var user = await _client.VerifyCredentials();

            // Present the tweet to user
            await _statusView.Show(user);

            ClearLines();
            AppendLine("Check out your new tweet!");
            AppendLine("Press Trigger button to move on to the next demo...");

            // Wait for a trigger by user
            await MLUtils.OnTriggerUpAsObservable().ToUniTask(useFirstValue: true);

            // Hide the twitter ui
            await _statusView.Hide();

            ClearLines();
            AppendLine("Press Trigger button to start video capture & upload...");
            AppendLine("(Tweet will contain a video captured from now.");
            AppendLine("Please end this demo if your privacy is concerned)");

            // Wait for a trigger by user
            await MLUtils.OnTriggerUpAsObservable().ToUniTask(useFirstValue: true);

            // Make a file path for the video
            string videoFilePath = Path.Combine(Application.temporaryCachePath, "video.mp4");

            // Update privileges just in case
            await MLUtils.RequestPrivilege(MLPrivilegeId.LocalAreaNetwork);

            await MLUtils.RequestPrivilege(MLPrivilegeId.CameraCapture);

            await MLUtils.RequestPrivilege(MLPrivilegeId.AudioCaptureMic);

            // Start video recording
            MLCamera.Start().ThrowIfFail();
            MLCamera.Connect().ThrowIfFail();
            MLCamera.StartVideoCapture(videoFilePath);

            ClearLines();
            AppendLine("Press Trigger button to STOP video capture and upload it on Twitter...");

            // Wait for a trigger by user
            await MLUtils.OnTriggerUpAsObservable().ToUniTask(useFirstValue: true);

            // Stop video recording
            MLCamera.StopVideoCapture().ThrowIfFail();

            ClearLines();
            AppendLine("Stoped video capture. Encoding...");

            // Wait until encoding is over
            await MLUtils.OnCaptureCompletedAsObservable().ToUniTask(useFirstValue: true);

            // Stop capture service
            MLCamera.Disconnect().ThrowIfFail();
            MLCamera.Stop();

            ClearLines();
            AppendLine("Finished encoding. Uploading to Twitter...");

            // Read the video file
            byte[] video = File.ReadAllBytes(videoFilePath);

            // Upload the video to Twitter (this is just a media upload; not a tweet)
            string videoMediaId = await _client.UploadVideo(video, (upload, encode) =>
            {
                ClearLines();
                AppendLine($"Uploading: {upload * 100:0}% done, encoding: {encode * 100:0}% done...");
            });

            // Tweet the video
            await _client.UpdateStatus("Uploading a video capture from #MagicLeap using MLTwitter", videoMediaId);

            // Present the tweet to user
            user = await _client.VerifyCredentials();

            await _statusView.Show(user);

            ClearLines();
            AppendLine("Check out your new tweet!");
            AppendLine("");
            AppendLine("You've reached the end of this demo.");
            AppendLine("Press Trigger button to exit the app...");

            // Wait for a trigger by user
            await MLUtils.OnTriggerUpAsObservable().ToUniTask(useFirstValue: true);

            // Cool animation
            await _statusView.Hide();

            Application.Quit();
        }