コード例 #1
0
 public void Dispose()
 {
     if (camera.IsRunning)
     {
         camera.StopPreview();
     }
     sourceBuffer = null;
     preview      = null;
 }
コード例 #2
0
    public void PlayCamera()
    {
        Debug.Log("Kauel: PlayCamera()");

        if (Mode == KameraMode.Camera)
        {
            Debug.Log("KAmera Mode");

            // Free the photo texture
            Texture2D.Destroy(photo); photo = null;
            NatCamCamera.StopPreview();
            NatCamCamera.StartPreview(OnStart);

            RawImageCamera.texture = previewTexture;
        }
    }
コード例 #3
0
 public CustomYieldInstruction Stop()
 {
     // Stop recording
     deviceCamera.StopPreview();
     videoRecorder.Dispose();
     return(this);
 }
        // Update is called once per frame
        protected override void Update()
        {
            if (hasInitDone)
            {
                // Catch the orientation change of the screen and correct the mat image to the correct direction.
                if (screenOrientation != Screen.orientation && (screenWidth != Screen.width || screenHeight != Screen.height))
                {
                    if (!natCamDeviceCamera.IsRunning)
                    {
                        bool isRotatedFrame = false;
                        DeviceOrientation oldOrientation = (DeviceOrientation)(int)screenOrientation;
                        DeviceOrientation newOrientation = (DeviceOrientation)(int)Screen.orientation;
                        if (oldOrientation == DeviceOrientation.Portrait ||
                            oldOrientation == DeviceOrientation.PortraitUpsideDown)
                        {
                            if (newOrientation == DeviceOrientation.LandscapeLeft ||
                                newOrientation == DeviceOrientation.LandscapeRight)
                            {
                                isRotatedFrame = true;
                            }
                        }
                        else if (oldOrientation == DeviceOrientation.LandscapeLeft ||
                                 oldOrientation == DeviceOrientation.LandscapeRight)
                        {
                            if (newOrientation == DeviceOrientation.Portrait ||
                                newOrientation == DeviceOrientation.PortraitUpsideDown)
                            {
                                isRotatedFrame = true;
                            }
                        }

                        if (isRotatedFrame)
                        {
                            int width  = frameMat.width();
                            int height = frameMat.height();

                            if (frameMat != null)
                            {
                                frameMat.Dispose();
                                frameMat = null;
                            }
                            if (rotatedFrameMat != null)
                            {
                                rotatedFrameMat.Dispose();
                                rotatedFrameMat = null;
                            }

                            frameMat = new Mat(width, height, CvType.CV_8UC4, new Scalar(0, 0, 0, 255));

                            if (rotate90Degree)
                            {
                                rotatedFrameMat = new Mat(height, width, CvType.CV_8UC4, new Scalar(0, 0, 0, 255));
                            }
                        }
                    }

                    #if UNITY_IOS && !UNITY_EDITOR
                    if (onDisposed != null)
                    {
                        onDisposed.Invoke();
                    }
                    if (onInitialized != null)
                    {
                        onInitialized.Invoke();
                    }
                    #elif UNITY_ANDROID && !UNITY_EDITOR
                    if (natCamDeviceCamera.IsRunning)
                    {
                        natCamDeviceCamera.StopPreview();
                        natCamDeviceCamera.StartPreview(OnStart, OnFrame);
                    }
                    else
                    {
                        if (onDisposed != null)
                        {
                            onDisposed.Invoke();
                        }
                        if (onInitialized != null)
                        {
                            onInitialized.Invoke();
                        }
                    }
                    #endif

                    screenOrientation = Screen.orientation;
                    screenWidth       = Screen.width;
                    screenHeight      = Screen.height;
                }
                else
                {
                    screenWidth  = Screen.width;
                    screenHeight = Screen.height;
                }
            }
        }
コード例 #5
0
 public void SwitchCamera()
 {
     deviceCamera.StopPreview();
     deviceCamera = deviceCamera.IsFrontFacing ? DeviceCamera.RearCamera : DeviceCamera.FrontCamera;
     deviceCamera.StartPreview(OnStart);
 }