private void enableExternalCamera() { MLog("enableExternalCamera :: External Camera Enabled"); MLCamera.Start(); MLCamera.Connect(); MLCamera.StartPreview(); externalCameraActive = true; }
/// <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!"); } }
/// <summary> /// Once privileges have been granted, enable the camera and callbacks. /// </summary> private void StartCapture() { if (!_hasStarted) { lock (_cameraLockObject) { EnableMLCamera(); } _hasStarted = true; MLCamera.StartPreview(); texture = new Texture2D(MLCamera.PreviewTextureWidth, MLCamera.PreviewTextureHeight, TextureFormat.RGBA32, false); Debug.Log("WebCamTextureToMatHelper:: " + " width:" + MLCamera.PreviewTextureWidth + " height:" + MLCamera.PreviewTextureHeight); if (colors == null || colors.Length != MLCamera.PreviewTextureWidth * MLCamera.PreviewTextureHeight) { colors = new Color32[MLCamera.PreviewTextureWidth * MLCamera.PreviewTextureHeight]; } frameMat = new Mat(MLCamera.PreviewTextureHeight, MLCamera.PreviewTextureWidth, CvType.CV_8UC4); screenOrientation = Screen.orientation; screenWidth = Screen.width; screenHeight = Screen.height; bool isRotatedFrame = false; if (rotate90Degree) { isRotatedFrame = true; } if (isRotatedFrame) { rotatedFrameMat = new Mat(MLCamera.PreviewTextureWidth, MLCamera.PreviewTextureHeight, CvType.CV_8UC4); } isInitWaiting = false; hasInitDone = true; initCoroutine = null; if (onInitialized != null) { onInitialized.Invoke(); } } }
/// <summary> /// Starts the camera. /// </summary> public virtual void Play() { #if !UNITY_EDITOR if (hasInitDone) { MLCamera.StartPreview(); } #else if (hasInitDone) { webCamTexture.Play(); } #endif }
void OnApplicationPause(bool pauseStatus) { if (!pauseStatus) { if (!MLLocation.IsStarted) { MLLocation.Start(); } MLCamera.Start(); MLCamera.Connect(); MLCamera.StartPreview(); } else { OnDisable(); } }
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); }
public void Enable() { MLCamera.Start().ThrowIfFail(); MLCamera.Connect().ThrowIfFail(); _previewTexture = MLCamera.StartPreview(); }