/// <summary>
        /// Start capturing video to input filename.
        /// </summary>
        /// <param name="fileName">File path to write the video to.</param>
        public void StartCapture(string fileName)
        {
            if (!_isCapturing && MLCamera.IsStarted && _isCameraConnected)
            {
                // Check file fileName extensions
                string extension = System.IO.Path.GetExtension(fileName);
                if (string.IsNullOrEmpty(extension) || !extension.Equals(_validFileFormat, System.StringComparison.OrdinalIgnoreCase))
                {
                    Debug.LogErrorFormat("Invalid fileName extension '{0}' passed into Capture({1}).\n" +
                                         "Videos must be saved in {2} format.", extension, fileName, _validFileFormat);
                    return;
                }

                string pathName = System.IO.Path.Combine(Application.persistentDataPath, fileName);

                MLResult result = MLCamera.StartVideoCapture(pathName);
                if (result.IsOk)
                {
                    _isCapturing      = true;
                    _captureStartTime = Time.time;
                    _captureFilePath  = pathName;
                    OnVideoCaptureStarted.Invoke();
                }
                else
                {
                    Debug.LogErrorFormat("Failure: Could not start video capture for {0}. Error Code: {1}",
                                         fileName, MLCamera.GetErrorCode().ToString());
                }
            }
            else
            {
                Debug.LogErrorFormat("Failure: Could not start video capture for {0} because '{1}' is already recording!",
                                     fileName, _captureFilePath);
            }
        }
 /// <summary>
 /// Stop capturing video.
 /// </summary>
 public void EndCapture()
 {
     if (_isCapturing)
     {
         MLResult result = MLCamera.StopVideoCapture();
         if (result.IsOk)
         {
             _isCapturing      = false;
             _captureStartTime = 0;
             OnVideoCaptureEnded.Invoke(_captureFilePath);
             _captureFilePath = null;
         }
         else
         {
             Debug.LogErrorFormat("Failure: Could not end video capture. Error Code: {0}",
                                  MLCamera.GetErrorCode().ToString());
         }
     }
     else
     {
         Debug.LogError("Failure: Could not EndCapture() because the camera is not recording.");
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Stop capturing video.
        /// </summary>
        public void EndCapture()
        {
            if (_isCapturing)
            {
                MLResult result = MLCamera.StopVideoCapture();
                if (result.IsOk)
                {
                    _isCapturing      = false;
                    _captureStartTime = 0;
                    OnVideoCaptureEnded.Invoke(_captureFilePath);
                    _captureFilePath = null;
                }
                else
                {
                    if (result.Code == MLResultCode.PrivilegeDenied)
                    {
                        Instantiate(Resources.Load("PrivilegeDeniedError"));
                    }

                    Debug.LogErrorFormat("Error: VideoCaptureExample failed to end video capture. Error Code: {0}", MLCamera.GetErrorCode().ToString());
                }
            }
            else
            {
                Debug.LogError("Error: VideoCaptureExample failed to end video capture because the camera is not recording.");
            }
        }
 /// <summary>
 /// Stop capturing video.
 /// </summary>
 public void EndCapture()
 {
     if (_isCapturing)
     {
         MLResult result = MLCamera.StopVideoCapture();
         if (result.IsOk)
         {
             _isCapturing      = false;
             _captureStartTime = 0;
             OnVideoCaptureEnded?.Invoke();
         }
         else
         {
             CheckPrivilegeDenied(result);
             Debug.LogErrorFormat("Error: RawVideoCaptureExample failed to end raw video capture. Error Code: {0}", MLCamera.GetErrorCode().ToString());
         }
     }
     else
     {
         Debug.LogError("Error: RawVideoCaptureExample failed to end raw video capture because the camera is not capturing.");
     }
 }
 /// <summary>
 /// Start capturing raw video.
 /// </summary>
 public void StartCapture()
 {
     if (!_isCapturing && MLCamera.IsStarted && _isCameraConnected)
     {
         MLResult result = MLCamera.StartRawVideoCapture();
         if (result.IsOk)
         {
             _isCapturing      = true;
             _captureStartTime = Time.time;
             OnVideoCaptureStarted?.Invoke();
             SetupCameraIntrinsics();
         }
         else
         {
             CheckPrivilegeDenied(result);
             Debug.LogErrorFormat("Error: RawVideoCaptureExample failed to start raw video capture. Reason: {1}", MLCamera.GetErrorCode().ToString());
         }
     }
     else
     {
         Debug.LogErrorFormat("Error: RawVideoCaptureExample failed to start raw video capture.");
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Stop capturing video.
        /// </summary>
        public void EndCapture()
        {
            if (_isCapturing)
            {
                #if PLATFORM_LUMIN
                MLResult result = MLCamera.StopVideoCapture();
                if (result.IsOk)
                {
                    //// If we did not record long enough make sure our path is marked as invalid to avoid trying to load invalid file.
                    //if (Time.time - _captureStartTime < _minRecordingTime)
                    //{
                    //    _captureFilePath = null;
                    //}

                    if (_rawVideoCaptureMode)
                    {
                        OnRawVideoCaptureEnded.Invoke();
                    }
                    //else
                    //{
                    //    OnVideoCaptureEnded.Invoke(_captureFilePath);
                    //}

                    _isCapturing = false;
                    //_captureStartTime = 0;
                    //_captureFilePath = null;
                }
                else
                {
                    Debug.LogErrorFormat("Error: VideoCaptureExample failed to end video capture. Error Code: {0}", MLCamera.GetErrorCode().ToString());
                }
                #endif
            }
            else
            {
                Debug.LogError("Error: VideoCaptureExample failed to end video capture because the camera is not recording.");
            }
        }
Ejemplo n.º 7
0
        ///// <summary>
        ///// Start capturing video to input filename.
        ///// </summary>
        ///// <param name="fileName">File path to write the video to.</param>
        //public void StartCapture(string fileName)
        //{
        //    #if PLATFORM_LUMIN
        //    if(!_isCapturing && MLCamera.IsStarted && _isCameraConnected)
        //    {
        //        // Check file fileName extensions
        //        string extension = System.IO.Path.GetExtension(fileName);
        //        if (string.IsNullOrEmpty(extension) || !extension.Equals(_validFileFormat, System.StringComparison.OrdinalIgnoreCase))
        //        {
        //            Debug.LogErrorFormat("Invalid fileName extension '{0}' passed into Capture({1}).\n" +
        //                "Videos must be saved in {2} format.", extension, fileName, _validFileFormat);
        //            return;
        //        }

        //        string pathName = System.IO.Path.Combine(Application.persistentDataPath, fileName);

        //        MLResult result = MLCamera.StartVideoCapture(pathName);
        //        if (result.IsOk)
        //        {
        //            _isCapturing = true;
        //            _captureStartTime = Time.time;
        //            _captureFilePath = pathName;
        //            OnVideoCaptureStarted.Invoke();
        //        }
        //        else
        //        {
        //            Debug.LogErrorFormat("Error: VideoCaptureExample failed to start video capture for {0}. Reason: {1}", fileName, MLCamera.GetErrorCode().ToString());
        //        }
        //    }
        //    else
        //    {
        //        Debug.LogErrorFormat("Error: VideoCaptureExample failed to start video capture for {0} because '{1}' is already recording!",
        //            fileName, _captureFilePath);
        //    }
        //    #endif
        //}

        /// <summary>
        /// Start capturing raw video.
        /// </summary>
        public void StartRawCapture()
        {
            #if PLATFORM_LUMIN
            if (!_isCapturing && MLCamera.IsStarted && _isCameraConnected)
            {
                MLResult result = MLCamera.StartRawVideoCapture();
                if (result.IsOk)
                {
                    _isCapturing = true;
                    //_captureStartTime = Time.time;
                    OnRawVideoCaptureStarted.Invoke();
                    SetupCameraIntrinsics();
                }
                else
                {
                    Debug.LogErrorFormat("Error: VideoCaptureExample failed to start raw video capture. Reason: {1}", MLCamera.GetErrorCode().ToString());
                }
            }
            else
            {
                Debug.LogErrorFormat("Error: VideoCaptureExample failed to start raw video capture.");
            }
            #endif
        }
 /// <summary>
 /// Start capturing video.
 /// </summary>
 public void StartCapture()
 {
     _text.text = "StartPreview called";
     if (!_isCapturing && MLCamera.IsStarted && _isCameraConnected)
     {
         // MLCamera.Settings.Apply();
         MLResult result = MLCamera.StartPreview(_texture);
         if (result.Code == MLResultCode.Ok)
         {
             _text.text = "StartPreview is OK";
             // _material.mainTexture = _texture;
             for (int i = 0; i < _rawImage.Count; i++)
             {
                 _rawImage[i].texture = _texture;
             }
             _isCapturing      = true;
             _captureStartTime = Time.time;
             OnVideoCaptureStarted.Invoke();
         }
         else
         {
             _text.text = "StartPreview is NOT OK";
             if (result.Code == MLResultCode.InvalidParam)
             {
                 _text.text = "Failed due to an invalid input parameter";
             }
             if (result.Code == MLResultCode.Pending)
             {
                 _text.text = "PCF system isn't fully initialized";
             }
             if (result.Code == MLResultCode.UnspecifiedFailure)
             {
                 _text.text = "Other internal error";
             }
             if (result.Code == MLResultCode.SnapshotPoseNotFound)
             {
                 _text.text = "Coordinate Frame is valid, but not found";
             }
             if (result.Code == MLResultCode.PrivilegeDenied)
             {
                 _text.text = "Privilege denied";
                 Instantiate(Resources.Load("PrivilegeDeniedError"));
             }
             Debug.LogErrorFormat("Error: VideoCaptureExample failed to start video capture for {0}. Reason: {1}", MLCamera.GetErrorCode().ToString());
         }
     }
     else
     {
         _text.text = "StartPreview failed";
         Debug.LogErrorFormat("Error: VideoCaptureExample failed to start video capture for {0} because '{1}' is already recording!");
     }
 }