Пример #1
0
        /// <summary>
        /// Releases all resource.
        /// </summary>
        private void Dispose()
        {
            NatCam.Release();

            if (matrix != null)
            {
                matrix.Dispose();
                matrix = null;
            }
            if (grayMatrix != null)
            {
                grayMatrix.Dispose();
                grayMatrix = null;
            }
            if (texture != null)
            {
                Texture2D.Destroy(texture);
                texture = null;
            }

            didUpdateThisFrame = false;

            //Reset material
            if (preview)
            {
                preview.material = originalMaterial;
            }
            //Destroy view material
            Destroy(viewMaterial);
        }
Пример #2
0
 void OnDisable()
 {
     if (!willDestroy)
     {
         NatCam.Release();               //We check that this wasn't caused by NatCam.Release() before calling NatCam.Release();
     }
 }
Пример #3
0
    private void ReleaseCamera()
    {
        if (NatCam.ActiveCamera != null)
        {
            NatCam.Release();
        }

        initialized = false;
    }
Пример #4
0
        /// <summary>
        /// Releases all resource.
        /// </summary>
        private void Dispose()
        {
            NatCam.Release();

            if (texture != null)
            {
                Texture2D.Destroy(texture);
                texture = null;
            }

            didUpdateThisFrame = false;
        }
Пример #5
0
 /// <summary>
 /// Releases all resource used by the <see cref="NatCamToMatHelper"/> object.
 /// </summary>
 /// <remarks>Call <see cref="Dispose"/> when you are finished using the <see cref="NatCamToMatHelper"/>. The
 /// <see cref="Dispose"/> method leaves the <see cref="NatCamToMatHelper"/> in an unusable state. After
 /// calling <see cref="Dispose"/>, you must release all references to the <see cref="NatCamToMatHelper"/> so
 /// the garbage collector can reclaim the memory that the <see cref="NatCamToMatHelper"/> was occupying.</remarks>
 public void Dispose()
 {
     // Release NatCam
     NatCam.Release();
     #if OPENCV_API
     // Dispose the matrix if it isn't null
     if (matrix != null)
     {
         matrix.Dispose();
     }
     matrix = null;
     #endif
     // Invoke the OnDisposedEvent
     if (OnDisposedEvent != null)
     {
         OnDisposedEvent.Invoke();
     }
 }
Пример #6
0
        /// <summary>
        /// To release the resources.
        /// </summary>
        protected override void ReleaseResources()
        {
            isInitWaiting = false;
            hasInitDone   = false;

            NatCam.Release();

            pixelBuffer        = null;
            didUpdateThisFrame = false;

            if (frameMat != null)
            {
                frameMat.Dispose();
                frameMat = null;
            }
            if (rotatedFrameMat != null)
            {
                rotatedFrameMat.Dispose();
                rotatedFrameMat = null;
            }
        }
Пример #7
0
        /// <summary>
        /// Releases all resource.
        /// </summary>
        private void Dispose()
        {
            NatCam.Release();

            if (matrix != null)
            {
                matrix.Dispose();
                matrix = null;
            }
            if (texture != null)
            {
                Texture2D.Destroy(texture);
                texture = null;
            }

            didUpdateThisFrame = false;

            if (comicFilter != null)
            {
                comicFilter.Dispose();
            }
        }
Пример #8
0
 public void changeScene_rec()//int changeTheScene)
 {
     //previewPanel = null;
     NatCam.Release();
     SceneManager.LoadScene(changeTheScene);
 }
Пример #9
0
        /// <summary>
        /// Initializes this instance by coroutine.
        /// </summary>
        protected override IEnumerator _Initialize()
        {
            if (!NatCam.Implementation.HasPermissions)
            {
                Debug.LogError("NatCam.Implementation.HasPermissions == false");
            }

            if (hasInitDone)
            {
                ReleaseResources();

                if (onDisposed != null)
                {
                    onDisposed.Invoke();
                }
            }

            isInitWaiting = true;


            // Creates the camera
            if (!String.IsNullOrEmpty(requestedDeviceName))
            {
                int requestedDeviceIndex = -1;
                if (Int32.TryParse(requestedDeviceName, out requestedDeviceIndex))
                {
                    if (requestedDeviceIndex >= 0 && requestedDeviceIndex < DeviceCamera.Cameras.Length)
                    {
                        NatCam.Camera = DeviceCamera.Cameras [requestedDeviceIndex];
                    }
                }
                if (NatCam.Camera == null)
                {
                    Debug.Log("Cannot find camera device " + requestedDeviceName + ".");
                }
            }

            NatCam.Camera = requestedIsFrontFacing ? DeviceCamera.FrontCamera : DeviceCamera.RearCamera;

            if (NatCam.Camera == null)
            {
                if (DeviceCamera.Cameras.Length > 0)
                {
                    NatCam.Camera = DeviceCamera.Cameras [0];
                }
                else
                {
                    isInitWaiting = false;

                    if (onErrorOccurred != null)
                    {
                        onErrorOccurred.Invoke(ErrorCode.CAMERA_DEVICE_NOT_EXIST);
                    }

                    yield break;
                }
            }

            NatCam.Camera.Framerate = requestedFPS;

            // Set the camera's preview resolution
            NatCam.Camera.PreviewResolution = new CameraResolution(requestedWidth, requestedHeight);

            // Register callback for when the preview starts
            // Note that this is a MUST when assigning the preview texture to anything
            NatCam.OnStart += OnStart;
            // Register for preview updates
            NatCam.OnFrame += OnFrame;

            // Starts the camera
            NatCam.Play();

            int  initFrameCount = 0;
            bool isTimeout      = false;

            while (true)
            {
                if (initFrameCount > timeoutFrameCount)
                {
                    isTimeout = true;
                    break;
                }
                else if (didUpdateThisFrame)
                {
                    Debug.Log("NatCamPreviewToMatHelper:: " + " width:" + NatCam.Preview.width + " height:" + NatCam.Preview.height + " fps:" + NatCam.Camera.Framerate
                              + " isFrongFacing:" + NatCam.Camera.IsFrontFacing);

                    frameMat = new Mat(NatCam.Preview.height, NatCam.Preview.width, CvType.CV_8UC4);

                    if (rotate90Degree)
                    {
                        rotatedFrameMat = new Mat(NatCam.Preview.width, NatCam.Preview.height, CvType.CV_8UC4);
                    }

                    isInitWaiting = false;
                    hasInitDone   = true;
                    initCoroutine = null;

                    if (onInitialized != null)
                    {
                        onInitialized.Invoke();
                    }

                    break;
                }
                else
                {
                    initFrameCount++;
                    yield return(null);
                }
            }

            if (isTimeout)
            {
                // Unregister from NatCam callbacks
                NatCam.OnStart -= OnStart;
                NatCam.OnFrame -= OnFrame;
                NatCam.Release();

                isInitWaiting = false;
                initCoroutine = null;

                if (onErrorOccurred != null)
                {
                    onErrorOccurred.Invoke(ErrorCode.TIMEOUT);
                }
            }
        }
Пример #10
0
 void OnApplicationQuit()
 {
     NatCam.Release();
 }