public override void Dispose()
        {
            if (faceLandmarkDetector != null)
            {
                faceLandmarkDetector.Dispose();
            }

            if (debugMat != null)
            {
                debugMat.Dispose();
                debugMat = null;
            }

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

#if UNITY_WEBGL
            if (getFilePath_Coroutine != null)
            {
                StopCoroutine(getFilePath_Coroutine);
                ((IDisposable)getFilePath_Coroutine).Dispose();
            }
#endif
        }
        /// <summary>
        /// Raises the disable event.
        /// </summary>
        void OnDisable()
        {
            camMatrix.Dispose();
            distCoeffs.Dispose();

            faceLandmarkDetector.Dispose();
        }
        /// <summary>
        /// Raises the destroy event.
        /// </summary>
        void OnDestroy()
        {
            if (sourceToMatHelper != null)
            {
                sourceToMatHelper.Dispose();
            }

            if (faceLandmarkDetector != null)
            {
                faceLandmarkDetector.Dispose();
            }

            if (lowPassFilter != null)
            {
                lowPassFilter.Dispose();
            }
            if (kalmanFilter != null)
            {
                kalmanFilter.Dispose();
            }
            if (opticalFlowFilter != null)
            {
                opticalFlowFilter.Dispose();
            }

#if UNITY_WEBGL
            if (getFilePath_Coroutine != null)
            {
                StopCoroutine(getFilePath_Coroutine);
                ((IDisposable)getFilePath_Coroutine).Dispose();
            }
#endif
        }
        /// <summary>
        /// Raises the destroy event.
        /// </summary>
        void OnDestroy()
        {
            if (capture != null)
            {
                capture.release();
            }

            if (rgbMat != null)
            {
                rgbMat.Dispose();
            }

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

            if (faceLandmarkDetector != null)
            {
                faceLandmarkDetector.Dispose();
            }

            #if UNITY_WEBGL && !UNITY_EDITOR
            foreach (var coroutine in coroutines)
            {
                StopCoroutine(coroutine);
                ((IDisposable)coroutine).Dispose();
            }
            #endif
        }
        /// <summary>
        /// Raises the disable event.
        /// </summary>
        void OnDisable()
        {
            WebGLFileUploadManager.FileUploadEventHandler -= fileUploadHandler;
            WebGLFileUploadManager.Dispose();

            webCamTextureToMatHelper.Dispose();

            if (cascade != null)
            {
                cascade.Dispose();
            }

            if (rectangleTracker != null)
            {
                rectangleTracker.Dispose();
            }

            if (faceLandmarkDetector != null)
            {
                faceLandmarkDetector.Dispose();
            }

            if (frontalFaceParam != null)
            {
                frontalFaceParam.Dispose();
            }
        }
        private void Run()
        {
            gameObject.transform.localScale = new Vector3(texture2D.width, texture2D.height, 1);
            Debug.Log("Screen.width " + Screen.width + " Screen.height " + Screen.height + " Screen.orientation " + Screen.orientation);

            float width  = gameObject.transform.localScale.x;
            float height = gameObject.transform.localScale.y;

            float widthScale  = (float)Screen.width / width;
            float heightScale = (float)Screen.height / height;

            if (widthScale < heightScale)
            {
                Camera.main.orthographicSize = (width * (float)Screen.height / (float)Screen.width) / 2;
            }
            else
            {
                Camera.main.orthographicSize = height / 2;
            }

            FaceLandmarkDetector faceLandmarkDetector = new FaceLandmarkDetector(frontal_cat_face_svm_filepath, sp_cat_face_68_dat_filepath);

            faceLandmarkDetector.SetImage(texture2D);

            //detect face rects
            List <Rect> detectResult = faceLandmarkDetector.Detect();

            foreach (var rect in detectResult)
            {
                Debug.Log("face : " + rect);

                //detect landmark points
                List <Vector2> points = faceLandmarkDetector.DetectLandmark(rect);

                Debug.Log("face points count : " + points.Count);
                foreach (var point in points)
                {
                    Debug.Log("face point : x " + point.x + " y " + point.y);
                }

                //draw landmark points
                faceLandmarkDetector.DrawDetectLandmarkResult(texture2D, 0, 255, 0, 255);
            }

            //draw face rects
            faceLandmarkDetector.DrawDetectResult(texture2D, 255, 0, 0, 255, 3);

            faceLandmarkDetector.Dispose();

            gameObject.GetComponent <Renderer> ().material.mainTexture = texture2D;

            if (fpsMonitor != null)
            {
                fpsMonitor.Add("dlib object detector", "frontal_cat_face.svm");
                fpsMonitor.Add("dlib shape predictor", "sp_cat_face_68.dat");
                fpsMonitor.Add("width", width.ToString());
                fpsMonitor.Add("height", height.ToString());
                fpsMonitor.Add("orientation", Screen.orientation.ToString());
            }
        }
Beispiel #7
0
        /// <summary>
        /// Raises the destroy event.
        /// </summary>
        void OnDestroy()
        {
            if (webCamTextureToMatHelper != null)
            {
                webCamTextureToMatHelper.Dispose();
            }

            if (faceLandmarkDetector != null)
            {
                faceLandmarkDetector.Dispose();
            }

            if (lowPassFilter != null)
            {
                lowPassFilter.Dispose();
            }
            if (kalmanFilter != null)
            {
                kalmanFilter.Dispose();
            }
            if (opticalFlowFilter != null)
            {
                opticalFlowFilter.Dispose();
            }

            #if UNITY_WEBGL && !UNITY_EDITOR
            foreach (var coroutine in coroutines)
            {
                StopCoroutine(coroutine);
                ((IDisposable)coroutine).Dispose();
            }
            #endif
        }
Beispiel #8
0
        /// <summary>
        /// Raises the destroy event.
        /// </summary>
        void OnDestroy()
        {
            if (faceMaskColorCorrector != null)
            {
                faceMaskColorCorrector.Dispose();
            }

            if (faceLandmarkDetector != null)
            {
                faceLandmarkDetector.Dispose();
            }

            if (cascade != null)
            {
                cascade.Dispose();
            }

            #if UNITY_WEBGL && !UNITY_EDITOR
            foreach (var coroutine in coroutines)
            {
                StopCoroutine(coroutine);
                ((IDisposable)coroutine).Dispose();
            }
            #endif
        }
Beispiel #9
0
        /// <summary>
        /// Raises the disable event.
        /// </summary>
        void OnDisable()
        {
            webCamTextureToMatHelper.Dispose();

            if (faceLandmarkDetector != null)
            {
                faceLandmarkDetector.Dispose();
            }

            if (rectangleTracker != null)
            {
                rectangleTracker.Dispose();
            }

            if (rvec != null)
            {
                rvec.Dispose();
            }
            if (tvec != null)
            {
                tvec.Dispose();
            }
            if (rotMat != null)
            {
                rotMat.Dispose();
            }
        }
        /// <summary>
        /// Raises the destroy event.
        /// </summary>
        void OnDestroy()
        {
            if (capture != null)
            {
                capture.release();
            }

            if (rgbMat != null)
            {
                rgbMat.Dispose();
            }

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

            if (faceLandmarkDetector != null)
            {
                faceLandmarkDetector.Dispose();
            }

#if UNITY_WEBGL && !UNITY_EDITOR
            if (getFilePath_Coroutine != null)
            {
                StopCoroutine(getFilePath_Coroutine);
                ((IDisposable)getFilePath_Coroutine).Dispose();
            }
#endif
        }
        /// <summary>
        /// Raises the destroy event.
        /// </summary>
        void OnDestroy()
        {
            if (webCamTextureToMatHelper != null)
            {
                webCamTextureToMatHelper.Dispose();
            }

            if (imageOptimizationHelper != null)
            {
                imageOptimizationHelper.Dispose();
            }

            if (faceLandmarkDetector != null)
            {
                faceLandmarkDetector.Dispose();
            }

            if (cascade != null)
            {
                cascade.Dispose();
            }

            #if UNITY_WEBGL && !UNITY_EDITOR
            foreach (var coroutine in coroutines)
            {
                StopCoroutine(coroutine);
                ((IDisposable)coroutine).Dispose();
            }
            #endif
        }
        /// <summary>
        /// Raises the disable event.
        /// </summary>
        void OnDestroy()
        {
            WebGLFileUploadManager.FileUploadEventHandler -= fileUploadHandler;
            WebGLFileUploadManager.Dispose();

            capture.release();

            if (rgbMat != null)
            {
                rgbMat.Dispose();
            }
            if (grayMat != null)
            {
                grayMat.Dispose();
            }

            if (rectangleTracker != null)
            {
                rectangleTracker.Dispose();
            }

            if (faceLandmarkDetector != null)
            {
                faceLandmarkDetector.Dispose();
            }

            if (frontalFaceParam != null)
            {
                frontalFaceParam.Dispose();
            }
        }
        /// <summary>
        /// Raises the destroy event.
        /// </summary>
        void OnDestroy()
        {
            if (m_PhotoCaptureObj != null)
            {
                m_PhotoCaptureObj.StopPhotoModeAsync(OnStopPhotoMode);
            }

            if (m_GestureRecognizer != null && m_GestureRecognizer.IsCapturingGestures())
            {
                m_GestureRecognizer.StopCapturingGestures();
                #if UNITY_2017_2_OR_NEWER
                m_GestureRecognizer.Tapped -= OnTappedEvent;
                #else
                m_GestureRecognizer.TappedEvent -= OnTappedEvent;
                #endif
                m_GestureRecognizer.Dispose();
            }

            if (rgbaMat != null)
            {
                rgbaMat.Dispose();
            }

            if (faceLandmarkDetector != null)
            {
                faceLandmarkDetector.Dispose();
            }
        }
        /// <summary>
        /// Raises the destroy event.
        /// </summary>
        void OnDestroy()
        {
            if (faceMaskColorCorrector != null)
            {
                faceMaskColorCorrector.Dispose();
            }

            if (faceLandmarkDetector != null)
            {
                faceLandmarkDetector.Dispose();
            }

            if (cascade != null)
            {
                cascade.Dispose();
            }

            #if UNITY_WEBGL && !UNITY_EDITOR
            if (getFilePath_Coroutine != null)
            {
                StopCoroutine(getFilePath_Coroutine);
                ((IDisposable)getFilePath_Coroutine).Dispose();
            }
            #endif
        }
        /// <summary>
        /// Raises the destroy event.
        /// </summary>
        void OnDestroy()
        {
            webCamTextureToMatHelper.Dispose();

            if (cascade != null)
            {
                cascade.Dispose();
            }

            if (rectangleTracker != null)
            {
                rectangleTracker.Dispose();
            }

            if (faceLandmarkDetector != null)
            {
                faceLandmarkDetector.Dispose();
            }

            if (faceSwapper != null)
            {
                faceSwapper.Dispose();
            }

            #if UNITY_WEBGL && !UNITY_EDITOR
            foreach (var coroutine in coroutines)
            {
                StopCoroutine(coroutine);
                ((IDisposable)coroutine).Dispose();
            }
            #endif
        }
        /// <summary>
        /// Raises the destroy event.
        /// </summary>
        void OnDestroy()
        {
            if (imageOptimizationHelper != null)
            {
                imageOptimizationHelper.Dispose();
            }

            if (webCamTextureToMatHelper != null)
            {
                webCamTextureToMatHelper.Dispose();
            }

            if (faceLandmarkDetector != null)
            {
                faceLandmarkDetector.Dispose();
            }

#if UNITY_WEBGL && !UNITY_EDITOR
            if (getFilePath_Coroutine != null)
            {
                StopCoroutine(getFilePath_Coroutine);
                ((IDisposable)getFilePath_Coroutine).Dispose();
            }
#endif
        }
        // Update is called once per frame
        void Update()
        {
            if (!initDone)
            {
                return;
            }

            if (screenOrientation != Screen.orientation)
            {
                screenOrientation = Screen.orientation;
                updateLayout();
            }

                        #if UNITY_IOS && !UNITY_EDITOR && (UNITY_4_6_3 || UNITY_4_6_4 || UNITY_5_0_0 || UNITY_5_0_1)
            if (webCamTexture.width > 16 && webCamTexture.height > 16)
            {
                        #else
            if (webCamTexture.didUpdateThisFrame)
            {
                                #endif


                webCamTexture.GetPixels32(colors);
                faceLandmarkDetector.SetImage <Color32> (colors, webCamTexture.width, webCamTexture.height, 4, flip);

                //detect face rects
                List <Rect> detectResult = faceLandmarkDetector.Detect();

                foreach (var rect in detectResult)
                {
//			Debug.Log ("face : " + rect);

                    //detect landmark points
                    List <Vector2> points = faceLandmarkDetector.DetectLandmark(rect);


//			Debug.Log ("face point : " + points.Count);
                    if (points.Count > 0)
                    {
//				Debug.Log ("face points : x " + point.x + " y " + point.y);

                        //draw landmark points
                        faceLandmarkDetector.DrawDetectLandmarkResult <Color32> (colors, webCamTexture.width, webCamTexture.height, 4, flip, 0, 255, 0, 255);
                    }

                    //draw face rect
                    faceLandmarkDetector.DrawDetectResult <Color32> (colors, webCamTexture.width, webCamTexture.height, 4, flip, 255, 0, 0, 255, 2);
                }

                texture2D.SetPixels32(colors);
                texture2D.Apply();
            }
        }

        void OnDisable()
        {
            webCamTexture.Stop();
            faceLandmarkDetector.Dispose();
        }
Beispiel #18
0
 /// <summary>
 /// Destroyイベントの処理
 /// </summary>
 private void OnDestroy()
 {
     Dispose();
     if (faceLandmarkDetector != null)
     {
         faceLandmarkDetector.Dispose();
     }
 }
Beispiel #19
0
        private void Run()
        {
            //if true, The error log of the Native side Dlib will be displayed on the Unity Editor Console.
            Utils.setDebugMode(true);


            gameObject.transform.localScale = new Vector3(texture2D.width, texture2D.height, 1);
            Debug.Log("Screen.width " + Screen.width + " Screen.height " + Screen.height + " Screen.orientation " + Screen.orientation);

            float width  = gameObject.transform.localScale.x;
            float height = gameObject.transform.localScale.y;

            float widthScale  = (float)Screen.width / width;
            float heightScale = (float)Screen.height / height;

            if (widthScale < heightScale)
            {
                Camera.main.orthographicSize = (width * (float)Screen.height / (float)Screen.width) / 2;
            }
            else
            {
                Camera.main.orthographicSize = height / 2;
            }

            FaceLandmarkDetector faceLandmarkDetector = new FaceLandmarkDetector(sp_human_face_68_dat_filepath);

            faceLandmarkDetector.SetImage(texture2D);

            //detect face rects
            List <Rect> detectResult = faceLandmarkDetector.Detect();

            foreach (var rect in detectResult)
            {
                Debug.Log("face : " + rect);

                //detect landmark points
                List <Vector2> points = faceLandmarkDetector.DetectLandmark(rect);

                Debug.Log("face points count : " + points.Count);
                foreach (var point in points)
                {
                    Debug.Log("face point : x " + point.x + " y " + point.y);
                }

                //draw landmark points
                faceLandmarkDetector.DrawDetectLandmarkResult(texture2D, 0, 255, 0, 255);
            }

            //draw face rect
            faceLandmarkDetector.DrawDetectResult(texture2D, 255, 0, 0, 255, 2);

            faceLandmarkDetector.Dispose();

            gameObject.GetComponent <Renderer> ().material.mainTexture = texture2D;


            Utils.setDebugMode(false);
        }
        // Use this for initialization
        void Start()
        {
            gameObject.transform.localScale = new Vector3(texture2D.width, texture2D.height, 1);
            Debug.Log("Screen.width " + Screen.width + " Screen.height " + Screen.height + " Screen.orientation " + Screen.orientation);

            float width  = gameObject.transform.localScale.x;
            float height = gameObject.transform.localScale.y;

            float widthScale  = (float)Screen.width / width;
            float heightScale = (float)Screen.height / height;

            if (widthScale < heightScale)
            {
                Camera.main.orthographicSize = (width * (float)Screen.height / (float)Screen.width) / 2;
            }
            else
            {
                Camera.main.orthographicSize = height / 2;
            }


            FaceLandmarkDetector faceLandmarkDetector = new FaceLandmarkDetector(Utils.getFilePath("frontal_cat_face.svm"), Utils.getFilePath("shape_predictor_68_cat_face_landmarks.dat"));

            faceLandmarkDetector.SetImage(texture2D);

            //detect face rects
            List <Rect> detectResult = faceLandmarkDetector.Detect();

            foreach (var rect in detectResult)
            {
                Debug.Log("face : " + rect);

                //detect landmark points
                List <Vector2> points = faceLandmarkDetector.DetectLandmark(rect);

                Debug.Log("face points count : " + points.Count);
                if (points.Count > 0)
                {
                    foreach (var point in points)
                    {
                        Debug.Log("face point : x " + point.x + " y " + point.y);
                    }

                    //draw landmark points
                    faceLandmarkDetector.DrawDetectLandmarkResult(texture2D, 0, 255, 0, 255);
                }

                //draw face rects
                faceLandmarkDetector.DrawDetectResult(texture2D, 255, 0, 0, 255, 3);
            }

            faceLandmarkDetector.Dispose();

            gameObject.GetComponent <Renderer> ().material.mainTexture = texture2D;
        }
Beispiel #21
0
 /// <summary>
 /// Raises the destroy event.
 /// </summary>
 void OnDestroy()
 {
     if (webCamTexture != null)
     {
         webCamTexture.Stop();
     }
     if (faceLandmarkDetector != null)
     {
         faceLandmarkDetector.Dispose();
     }
 }
        void OnDestroy()
        {
            capture.release();

            if (rgbMat != null)
            {
                rgbMat.Dispose();
            }

            faceLandmarkDetector.Dispose();
        }
Beispiel #23
0
        /// <summary>
        /// Raises the disable event.
        /// </summary>
        void OnDisable()
        {
            if (webCamTextureToMatHelper != null)
            {
                webCamTextureToMatHelper.Dispose();
            }

            if (faceLandmarkDetector != null)
            {
                faceLandmarkDetector.Dispose();
            }
        }
Beispiel #24
0
        /// <summary>
        /// Raises the disable event.
        /// </summary>
        void OnDestroy()
        {
            capture.release();

            if (rgbMat != null)
            {
                rgbMat.Dispose();
            }
            if (grayMat != null)
            {
                grayMat.Dispose();
            }

            if (rectangleTracker != null)
            {
                rectangleTracker.Dispose();
            }

            if (faceLandmarkDetector != null)
            {
                faceLandmarkDetector.Dispose();
            }

            foreach (var key in lowPassFilterDict.Keys)
            {
                lowPassFilterDict [key].Dispose();
            }
            lowPassFilterDict.Clear();
            foreach (var key in opticalFlowFilterDict.Keys)
            {
                opticalFlowFilterDict [key].Dispose();
            }
            opticalFlowFilterDict.Clear();

            if (faceMaskColorCorrector != null)
            {
                faceMaskColorCorrector.Dispose();
            }

            if (frontalFaceChecker != null)
            {
                frontalFaceChecker.Dispose();
            }

            #if UNITY_WEBGL && !UNITY_EDITOR
            foreach (var coroutine in coroutines)
            {
                StopCoroutine(coroutine);
                ((IDisposable)coroutine).Dispose();
            }
            #endif
        }
        /// <summary>
        /// Raises the destroy event.
        /// </summary>
        void OnDestroy()
        {
            if (webCamTextureToMatHelper != null)
            {
                webCamTextureToMatHelper.Dispose();
            }

            if (cascade != null)
            {
                cascade.Dispose();
            }

            if (rectangleTracker != null)
            {
                rectangleTracker.Dispose();
            }

            if (faceLandmarkDetector != null)
            {
                faceLandmarkDetector.Dispose();
            }

            foreach (var key in lowPassFilterDict.Keys)
            {
                lowPassFilterDict[key].Dispose();
            }
            lowPassFilterDict.Clear();
            foreach (var key in opticalFlowFilterDict.Keys)
            {
                opticalFlowFilterDict[key].Dispose();
            }
            opticalFlowFilterDict.Clear();

            if (faceChanger != null)
            {
                faceChanger.Dispose();
            }

            if (faceMaskMat != null)
            {
                faceMaskMat.Dispose();
            }

#if UNITY_WEBGL
            if (getFilePath_Coroutine != null)
            {
                StopCoroutine(getFilePath_Coroutine);
                ((IDisposable)getFilePath_Coroutine).Dispose();
            }
#endif
        }
Beispiel #26
0
        /// <summary>
        /// Raises the destroy event.
        /// </summary>
        void OnDestroy()
        {
            if (faceLandmarkDetector != null)
            {
                faceLandmarkDetector.Dispose();
            }

            webCamTextureToMatHelper.Dispose();

            if (detector != null)
            {
                detector.Dispose();
            }
        }
Beispiel #27
0
        /// <summary>
        /// Raises the destroy event.
        /// </summary>
        void OnDestroy()
        {
            WebGLFileUploadManager.FileUploadEventHandler -= fileUploadHandler;
            WebGLFileUploadManager.Dispose();

            if (faceLandmarkDetector != null)
            {
                faceLandmarkDetector.Dispose();
            }

            if (cascade != null)
            {
                cascade.Dispose();
            }
        }
Beispiel #28
0
        /// <summary>
        /// Raises the disable event.
        /// </summary>
        void OnDisable()
        {
            if (camMatrix != null)
            {
                camMatrix.Dispose();
            }
            if (distCoeffs != null)
            {
                distCoeffs.Dispose();
            }

            if (faceLandmarkDetector != null)
            {
                faceLandmarkDetector.Dispose();
            }
        }
Beispiel #29
0
        void DeallocateObjects()
        {
            _faceDetector.Dispose();
            _faceMesh.Dispose();
            _irisMeshL.Dispose();
            _irisMeshR.Dispose();

            Object.Destroy(_cropMaterial);

            Object.Destroy(_faceCrop);
            Object.Destroy(_irisCropL);
            Object.Destroy(_irisCropR);

            _refineBuffer.Dispose();
            _eyeToFace.Dispose();
        }
        /// <summary>
        /// Raises the destroy event.
        /// </summary>
        void OnDestroy()
        {
            if (m_PhotoCaptureObj != null)
            {
                m_PhotoCaptureObj.StopPhotoModeAsync(OnStopPhotoMode);
            }

            if (rgbaMat != null)
            {
                rgbaMat.Dispose();
            }

            if (faceLandmarkDetector != null)
            {
                faceLandmarkDetector.Dispose();
            }
        }