public static IEnumerator FadeToPosition(Image image, EnumPosition position, NTemplate node, Vector2 point, float duration)
        {
            var canvas = DialogueDatabase.activeGraphPlayer.Canvas.transform as RectTransform;

            Vector2 pos;

            if (position != EnumPosition.Custom)
            {
                pos = new Vector2(EngineGraphUtilities.GetXPosition(position), .5f);
            }
            else
            {
                pos = point;
            }

            pos = EngineGraphUtilities.FromAbsolutePositionToAnchoredPosition(image.rectTransform, pos, canvas);

            var wait = new WaitForSeconds(duration / 2);

            image.CrossFadeAlpha(0, duration / 2, false);

            yield return(wait);

            image.rectTransform.anchoredPosition = pos;
            image.CrossFadeAlpha(1, duration / 2, false);

            yield return(wait);

            node.endedInstruction = true;
        }
        public static void Instante(Image image1, Image image2, Sprite newImage, NTemplate node)
        {
            image2.gameObject.SetActive(true);
            image2.sprite = newImage;

            image1.CrossFadeAlpha(0, 0, false);
            image2.CrossFadeAlpha(1, 0, false);

            image1.gameObject.SetActive(false);
            node.endedInstruction = true;
        }
Esempio n. 3
0
        public override void AddToTemplate(NTemplate tmpl)
        {
            if (tmpl.Faces == null)
            {
                tmpl.AddFaces();
            }

            foreach (NLRecord item in _nlTemplate.Records)
            {
                tmpl.Faces.Records.AddCopy(item);
            }
        }
        public static IEnumerator Fade(Image image1, Image image2, Sprite newImage, NTemplate node, float duration)
        {
            image2.rectTransform.anchoredPosition = image1.rectTransform.anchoredPosition;
            image2.CrossFadeAlpha(0, 0, false);
            image2.gameObject.SetActive(true);
            image2.sprite = newImage;

            image1.CrossFadeAlpha(0, duration, false);
            image2.CrossFadeAlpha(1, duration, false);

            yield return(new WaitForSeconds(duration));

            image1.gameObject.SetActive(false);
            node.endedInstruction = true;
        }
 public static void InitEngineGraphPopupWindow(NTemplate node)
 {
     currentPopup = (EnginePopupWindow)EditorWindow.GetWindow <EnginePopupWindow>();
     currentPopup.titleContent = new GUIContent("Paradox Engine: Node setting");
     currentPopup._node        = node;
 }
Esempio n. 6
0
        private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            bool extractionStarted = false;
            try
            {
                NImage frame = null;
                NGrayscaleImage grayscaleImage = null;
                int frameNumber = 0;
                int bestFrame;
                int frameCount = Tools.LiveEnrolFrameCount;
                _extractor.DetectAllFeaturePoints = false;

                while (backgroundWorker.CancellationPending == false)
                {
                    if (_pendingFormat != null && _fromCamera)
                    {
                        _camera.SetCurrentFormat(_pendingFormat);
                        _pendingFormat = null;
                    }

                    if (!_fromCamera && _pause)
                    {
                        System.Threading.Thread.Sleep(500);
                        continue;
                    }

                    try
                    {
                        TimeSpan duration = TimeSpan.Zero;
                        TimeSpan timeStamp = TimeSpan.Zero;

                        if (_fromCamera)
                        {
                            frame = _camera.GetFrame();
                        }
                        else
                        {
                            lock (_readerLock)
                            {
                                frame = _videoReader.ReadVideoSample(out timeStamp, out duration);
                            }
                        }

                        if (frame == null) //camera unplugged or end of file
                        {
                            createFaceRecord = false;
                            SetImageToView(null, null, null, NleExtractionStatus.None, -1, timeStamp);
                            return;
                        }

                        using (grayscaleImage = frame.ToGrayscale())
                        {
                            if (createFaceRecord)
                            {
                                NleDetectionDetails details;
                                NLTemplate template = null;
                                //NBuffer template = null;
                                if (!extractionStarted)
                                {
                                    UpdateExtractorTemplateSize();
                                    frameCount = Tools.LiveEnrolFrameCount;
                                    _extractor.ExtractStart();
                                    extractionStarted = true;
                                    frameNumber = 0;
                                    ClearCapturedImages();
                                }
                                frameNumber++;
                                NleExtractionStatus status = _extractor.ExtractNext(grayscaleImage, out details);
                                capturedImages.Add((NImage)frame.Clone());

                                if (status != NleExtractionStatus.None || frameNumber >= frameCount)
                                {
                                    template = _extractor.ExtractEnd(out bestFrame, out status);
                                    if (status == NleExtractionStatus.TemplateCreated)
                                    {
                                        NTemplate nTemplate = new NTemplate();
                                        NImage bestImage = frame;
                                        if (bestFrame < capturedImages.Count && bestFrame >= 0) bestImage = capturedImages[bestFrame];
                                        _newRecord = new FaceRecord(template, bestImage, details);
                                        _newRecord.AddToTemplate(nTemplate);
                                        template.Dispose();
                                        capturedImages.Remove(bestImage);
                                        _capturedTemplateList = new List<byte[]>();
                                        _capturedTemplateList.Add(nTemplate.Save().ToByteArray());

                                        score = Identify(_capturedTemplateList, _enrolledTemplateList);
                                        LogLine(string.Format("Face match details: score {0}.", score), true);

                                        backgroundWorker.CancelAsync();
                                    }
                                    else
                                    {
                                        _newRecord = null;
                                    }
                                    extractionStarted = false;
                                    createFaceRecord = false;
                                }

                                if (!createFaceRecord)
                                {
                                    ClearCapturedImages();
                                }

                                SetImageToView(nlView2, frame.ToBitmap(), new NleDetectionDetails[] { details }, status, (int)(frameNumber * 100.0 / frameCount), timeStamp);

                                if (status != NleExtractionStatus.None && status != NleExtractionStatus.TemplateCreated)
                                {
                                    backgroundWorker.CancelAsync();

                                    score = 0;
                                }
                            }
                            else
                            {
                                NleDetectionDetails[] details = null;
                                try
                                {
                                    NleFace[] faces = _extractor.DetectFaces(grayscaleImage);
                                    if (faces != null)
                                    {
                                        details = new NleDetectionDetails[faces.Length];
                                        for (int i = 0; i < faces.Length; i++)
                                        {
                                            details[i] = _extractor.DetectFacialFeatures(grayscaleImage, faces[i]);
                                        }
                                    }
                                }
                                finally
                                {
                                    SetImageToView(nlView2, frame.ToBitmap(), details, NleExtractionStatus.None, -1, timeStamp);
                                }
                            }
                        }//using
                    }// try
                    finally
                    {
                        if (frame != null) frame.Dispose();
                    }
                }// while
            }
            catch (Exception ex)
            {
                foreach (NImage img in capturedImages)
                {
                    img.Dispose();
                }
                capturedImages.Clear();

                ShowError(ex.Message);
            }
            finally
            {
                try
                {
                    int baseFrameIndex;
                    NleExtractionStatus status;
                    if (extractionStarted) _extractor.ExtractEnd(out baseFrameIndex, out status);
                    if (_fromCamera && _camera != null) _camera.StopCapturing();
                    if (!_fromCamera && _videoReader != null) _videoReader.Stop();
                }
                catch { }
            }
        }
Esempio n. 7
0
 public static void NodeSettingCallback(this NTemplate node)
 {
     EnginePopupWindow.InitEngineGraphPopupWindow(node);
 }
Esempio n. 8
0
        public static void DeleteNode(EngineGraph graph, int nodeID)
        {
            if (graph.nodes.Count <= nodeID)
            {
                return;
            }

            NTemplate deleteNode = graph.nodes[nodeID];

            if (deleteNode == null)
            {
                return;
            }

            if (deleteNode.nodeType == EnumNodeType.Answer)
            {
                for (int i = 0; i < deleteNode.input.inputNode.Count; i++)
                {
                    NQuestionBranch questionNode = (NQuestionBranch)deleteNode.input.inputNode[i];

                    questionNode.multiOutput.outputNode.Remove(graph.nodes[nodeID]);
                    questionNode.multiOutput.hasSomething = questionNode.multiOutput.outputNode.Count == 0 ? false : true;
                }
            }

            else
            {
                for (int i = 0; i < deleteNode.input.inputNode.Count; i++)
                {
                    deleteNode.input.inputNode[i].output.outputNode = null;
                    deleteNode.input.inputNode[i].output.isOccupied = false;
                }
            }

            if (deleteNode.nodeType == EnumNodeType.Branch_Question)
            {
                NQuestionBranch questionNode = (NQuestionBranch)deleteNode;

                for (int i = 0; i < questionNode.multiOutput.outputNode.Count; i++)
                {
                    questionNode.multiOutput.outputNode[i].input.inputNode.Remove(questionNode);
                    questionNode.multiOutput.outputNode[i].input.hasSomething = questionNode.multiOutput.outputNode[i].input.inputNode.Count > 0 ? true : false;
                }
            }

            else if (deleteNode.nodeType == EnumNodeType.Branch_Condition)
            {
                NConditionalBranch conditionalNode = (NConditionalBranch)deleteNode;

                for (int i = 0; i < conditionalNode.multiOutput.outputNode.Count; i++)
                {
                    conditionalNode.multiOutput.outputNode[i].input.inputNode.Remove(conditionalNode);
                    conditionalNode.multiOutput.outputNode[i].input.hasSomething = conditionalNode.multiOutput.outputNode[i].input.inputNode.Count > 0 ? true : false;
                }
            }

            else
            {
                if (deleteNode.output.outputNode != null)
                {
                    deleteNode.output.outputNode.input.inputNode.Remove(deleteNode);
                    deleteNode.output.outputNode.input.hasSomething = deleteNode.output.outputNode.input.inputNode.Count > 0 ? true : false;
                }
            }

            graph.nodes.RemoveAt(nodeID);
            GameObject.DestroyImmediate(deleteNode, true);
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
        public static IEnumerator Crossfade(AudioSource source1, AudioSource source2, AudioClip newClip, NTemplate node, float duration)
        {
            source2.clip = newClip;
            source2.Play();

            float lerpValue = 0;
            float result    = 0;

            yield return(new WaitUntil(() =>
            {
                source1.volume = Mathf.Lerp(1f, 0f, result);
                source2.volume = Mathf.Lerp(0f, 1f, result);

                lerpValue += Time.deltaTime;
                result = lerpValue / duration;

                return result > 1;
            }));

            source1.volume        = 0;
            source2.volume        = 1;
            node.endedInstruction = true;
        }
Esempio n. 10
0
        public static void Instante(Image image, Sprite sprite, EnumPosition position, NTemplate node, Vector2 point, bool reverse = false)
        {
            if (!reverse)
            {
                image.sprite = sprite;
            }

            image.CrossFadeAlpha(reverse? 0 : 1, 0, false);

            if (!reverse)
            {
                Vector2 pos;

                if (position == EnumPosition.Custom)
                {
                    pos = point;
                }
                else
                {
                    pos = new Vector2(EngineGraphUtilities.GetXPosition(position), .5f);
                }

                image.rectTransform.anchoredPosition = EngineGraphUtilities.FromAbsolutePositionToAnchoredPosition(image.rectTransform, pos, DialogueDatabase.activeGraphPlayer.Canvas.transform as RectTransform);
            }

            node.endedInstruction = true;
        }
        public static IEnumerator SlideToPosition(RectTransform trm, EnumPosition position, NTemplate node, Vector2 point, float duration)
        {
            var canvas = DialogueDatabase.activeGraphPlayer.Canvas.transform as RectTransform;

            Vector2 posA = trm.anchoredPosition;
            Vector2 posB;

            if (position != EnumPosition.Custom)
            {
                posB = new Vector2(EngineGraphUtilities.GetXPosition(position), .5f);
            }
            else
            {
                posB = point;
            }

            posB = EngineGraphUtilities.FromAbsolutePositionToAnchoredPosition(trm, posB, canvas);

            float lerpValue = 0;
            float result    = 0;

            yield return(new WaitUntil(() =>
            {
                trm.anchoredPosition = Vector2.Lerp(posA, posB, result);

                lerpValue += Time.deltaTime;
                result = lerpValue / duration;

                return result >= 1;
            }));

            node.endedInstruction = true;
        }
        public static IEnumerator SlideDown(Image image1, Image image2, Sprite newImage, NTemplate node, float duration)
        {
            image2.CrossFadeAlpha(1, 0, false);
            image2.gameObject.SetActive(true);
            image2.sprite = newImage;

            var trm1   = image1.rectTransform;
            var trm2   = image2.rectTransform;
            var center = new Vector2(.5f, .5f);

            var pos1Begin = EngineGraphUtilities.FromAbsolutePositionToAnchoredPosition(image1.rectTransform, center, DialogueDatabase.activeGraphPlayer.Canvas.transform as RectTransform);;
            var pos1End   = EngineGraphUtilities.FromAbsolutePositionToAnchoredPosition(image1.rectTransform, new Vector2(.5f, -.5f), DialogueDatabase.activeGraphPlayer.Canvas.transform as RectTransform);

            var pos2End   = EngineGraphUtilities.FromAbsolutePositionToAnchoredPosition(image2.rectTransform, center, DialogueDatabase.activeGraphPlayer.Canvas.transform as RectTransform);
            var pos2Begin = EngineGraphUtilities.FromAbsolutePositionToAnchoredPosition(image2.rectTransform, new Vector2(.5f, 1.5f), DialogueDatabase.activeGraphPlayer.Canvas.transform as RectTransform);

            float lerpValue = 0;
            float result    = 0;

            yield return(new WaitUntil(() =>
            {
                trm1.anchoredPosition = Vector2.Lerp(pos1Begin, pos1End, result);
                trm2.anchoredPosition = Vector2.Lerp(pos2Begin, pos2End, result);

                lerpValue += Time.deltaTime;
                result = lerpValue / duration;

                return result > 1.01;
            }));


            image1.gameObject.SetActive(false);
            node.endedInstruction = true;
        }
        public static IEnumerator FadeOutAndIn(AudioSource source1, AudioSource source2, AudioClip newClip, NTemplate node, float duration)
        {
            source2.clip   = newClip;
            source2.volume = 0;

            float lerpValue   = 0;
            float result      = 0;
            float midDuration = duration / 2;

            yield return(new WaitUntil(() =>
            {
                source1.volume = Mathf.Lerp(1, 0, result);

                lerpValue += Time.deltaTime;
                result = lerpValue / midDuration;

                return result > 1;
            }));

            source1.Stop();
            source1.volume = 0;
            lerpValue      = 0;
            result         = 0;

            source2.Play();

            yield return(new WaitUntil(() =>
            {
                source2.volume = Mathf.Lerp(0, 1, result);

                lerpValue += Time.deltaTime;
                result = lerpValue / midDuration;

                return result > 1;
            }));

            node.endedInstruction = true;
        }
        public static void Instante(AudioSource source1, AudioSource source2, AudioClip newClip, NTemplate node)
        {
            if (source1.isPlaying)
            {
                source1.Stop();
            }

            source1.volume = 0;

            source2.clip   = newClip;
            source2.volume = 1;
            source2.Play();

            node.endedInstruction = true;
        }
 public abstract void AddToTemplate(NTemplate tmpl);
        public static void InstanteToPosition(RectTransform trm, EnumPosition position, NTemplate node, Vector2 point)
        {
            var canvas = DialogueDatabase.activeGraphPlayer.Canvas.transform as RectTransform;

            Vector2 pos;

            if (position != EnumPosition.Custom)
            {
                pos = new Vector2(EngineGraphUtilities.GetXPosition(position), .5f);
            }
            else
            {
                pos = point;
            }

            pos = EngineGraphUtilities.FromAbsolutePositionToAnchoredPosition(trm, pos, canvas);

            trm.anchoredPosition = pos;

            node.endedInstruction = true;
        }
Esempio n. 17
0
        public static IEnumerator SlideUp(Image image, Sprite sprite, EnumPosition position, NTemplate node, Vector2 point, float duration, bool reverse = false)
        {
            if (!reverse)
            {
                image.sprite = sprite;
            }

            var canvas = DialogueDatabase.activeGraphPlayer.Canvas.transform as RectTransform;
            var trm    = image.rectTransform;

            Vector2 posA;
            Vector2 posB;

            if (position != EnumPosition.Custom)
            {
                posA = new Vector2(EngineGraphUtilities.GetXPosition(position), -.5f);
                posB = new Vector2(posA.x, .5f);
            }

            else
            {
                posA = new Vector2(point.x, -.5f);
                posB = point;
            }

            posA = EngineGraphUtilities.FromAbsolutePositionToAnchoredPosition(trm, posA, canvas);
            posB = reverse ? posB : EngineGraphUtilities.FromAbsolutePositionToAnchoredPosition(trm, posB, canvas);

            if (reverse)
            {
                posA.x = posB.x;
            }

            float lerpValue = 0;
            float result    = 0;

            yield return(new WaitUntil(() =>
            {
                if (reverse)
                {
                    trm.anchoredPosition = Vector2.Lerp(posB, posA, result);
                }
                else
                {
                    trm.anchoredPosition = Vector2.Lerp(posA, posB, result);
                }

                lerpValue += Time.deltaTime;
                result = lerpValue / duration;

                return result >= 1;
            }));

            node.endedInstruction = true;
        }
Esempio n. 18
0
        public static void CreateNode(EngineGraph currentGraph, EnumNodeType nodeType, Vector2 mousePos)
        {
            if (currentGraph != null)
            {
                NTemplate currentNode = null;
                switch (nodeType)
                {
                case EnumNodeType.Text:
                    currentNode          = (NText)ScriptableObject.CreateInstance <NText>();
                    currentNode.nodeName = "Text State";
                    break;

                case EnumNodeType.Branch_Condition:
                    currentNode          = (NConditionalBranch)ScriptableObject.CreateInstance <NConditionalBranch>();
                    currentNode.nodeName = "Conditional Branch State";
                    break;

                case EnumNodeType.Condition:
                    currentNode          = (NCondition)ScriptableObject.CreateInstance <NCondition>();
                    currentNode.nodeName = "Condition State";
                    break;

                case EnumNodeType.Branch_Question:
                    currentNode          = (NQuestionBranch)ScriptableObject.CreateInstance <NQuestionBranch>();
                    currentNode.nodeName = "Question Branch State";
                    break;

                case EnumNodeType.Answer:
                    currentNode          = (NAnswer)ScriptableObject.CreateInstance <NAnswer>();
                    currentNode.nodeName = "Answer State";
                    break;

                case EnumNodeType.Delay:
                    currentNode          = (NDelay)ScriptableObject.CreateInstance <NDelay>();
                    currentNode.nodeName = "Delay State";
                    break;

                case EnumNodeType.Start:
                    currentNode          = (NStart)ScriptableObject.CreateInstance <NStart>();
                    currentNode.nodeName = "Start State";
                    break;

                case EnumNodeType.End:
                    currentNode          = (NEnd)ScriptableObject.CreateInstance <NEnd>();
                    currentNode.nodeName = "End State";
                    break;

                case EnumNodeType.Clear:
                    currentNode          = (NClearText)ScriptableObject.CreateInstance <NClearText>();
                    currentNode.nodeName = "Clear Text State";
                    break;

                case EnumNodeType.Change_Flow_Chart:
                    currentNode          = (NChangeFlowChart)ScriptableObject.CreateInstance <NChangeFlowChart>();
                    currentNode.nodeName = "Change Flow Chart State";
                    break;

                case EnumNodeType.Set_Param:
                    currentNode          = (NSetParam)ScriptableObject.CreateInstance <NSetParam>();
                    currentNode.nodeName = "Set Parameter State";
                    break;

                case EnumNodeType.Play_Music:
                    currentNode          = (NPlayMusic)ScriptableObject.CreateInstance <NPlayMusic>();
                    currentNode.nodeName = "Play Music State";
                    break;

                case EnumNodeType.Stop_Music:
                    currentNode          = (NStopMusic)ScriptableObject.CreateInstance <NStopMusic>();
                    currentNode.nodeName = "Stop Music State";
                    break;

                case EnumNodeType.Play_Sound:
                    currentNode          = (NPlaySound)ScriptableObject.CreateInstance <NPlaySound>();
                    currentNode.nodeName = "Play Sound FX State";
                    break;

                case EnumNodeType.Stop_Sound:
                    currentNode          = (NStopSound)ScriptableObject.CreateInstance <NStopSound>();
                    currentNode.nodeName = "Stop Sound FX State";
                    break;

                case EnumNodeType.Play_Voice:
                    currentNode          = (NPlayVoice)ScriptableObject.CreateInstance <NPlayVoice>();
                    currentNode.nodeName = "Play Voice State";
                    break;

                case EnumNodeType.Stop_Voice:
                    currentNode          = (NStopVoice)ScriptableObject.CreateInstance <NStopVoice>();
                    currentNode.nodeName = "Stop Voice State";
                    break;

                case EnumNodeType.Hide_Text_Container:
                    currentNode          = (NHideTextContainer)ScriptableObject.CreateInstance <NHideTextContainer>();
                    currentNode.nodeName = "Hide Text Container State";
                    break;

                case EnumNodeType.Show_Text_Container:
                    currentNode          = (NShowTextContainer)ScriptableObject.CreateInstance <NShowTextContainer>();
                    currentNode.nodeName = "Show Text Container State";
                    break;

                case EnumNodeType.Change_Background:
                    currentNode          = (NChangeBackground)ScriptableObject.CreateInstance <NChangeBackground>();
                    currentNode.nodeName = "Change Background State";
                    break;

                case EnumNodeType.Show_Character:
                    currentNode          = (NShowCharacter)ScriptableObject.CreateInstance <NShowCharacter>();
                    currentNode.nodeName = "Show Character State";
                    break;

                case EnumNodeType.Hide_Character:
                    currentNode          = (NHideCharacter)ScriptableObject.CreateInstance <NHideCharacter>();
                    currentNode.nodeName = "Hide Character State";
                    break;

                case EnumNodeType.Change_Character_Sprite:
                    currentNode          = (NChangeCharacterSprite)ScriptableObject.CreateInstance <NChangeCharacterSprite>();
                    currentNode.nodeName = "Change Character Sprite State";
                    break;

                case EnumNodeType.Move_Character:
                    currentNode          = (NMoveCharacter)ScriptableObject.CreateInstance <NMoveCharacter>();
                    currentNode.nodeName = "Move Character State";
                    break;

                case EnumNodeType.Trigger_Event:
                    currentNode          = (NTriggerEvent)ScriptableObject.CreateInstance <NTriggerEvent>();
                    currentNode.nodeName = "Trigger Event State";
                    break;
                }

                if (currentNode != null)
                {
                    currentNode.name = currentNode.nodeName;
                    currentNode.InitNode();
                    currentNode.myRect.x    = mousePos.x;
                    currentNode.myRect.y    = mousePos.y;
                    currentNode.parentGraph = currentGraph;
                    currentGraph.nodes.Add(currentNode);

                    if (currentGraph.wantsConnection)
                    {
                        currentNode.CallConnection();
                    }

                    AssetDatabase.AddObjectToAsset(currentNode, currentGraph);
                    AssetDatabase.SaveAssets();
                    AssetDatabase.Refresh();
                }
            }
        }
Esempio n. 19
0
        private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            bool extractionStarted = false;

            try
            {
                NImage          frame          = null;
                NGrayscaleImage grayscaleImage = null;
                int             frameNumber    = 0;
                int             bestFrame;
                int             frameCount = Tools.LiveEnrolFrameCount;
                _extractor.DetectAllFeaturePoints = false;

                while (backgroundWorker.CancellationPending == false)
                {
                    if (_pendingFormat != null && _fromCamera)
                    {
                        _camera.SetCurrentFormat(_pendingFormat);
                        _pendingFormat = null;
                    }

                    if (!_fromCamera && _pause)
                    {
                        System.Threading.Thread.Sleep(500);
                        continue;
                    }

                    try
                    {
                        TimeSpan duration  = TimeSpan.Zero;
                        TimeSpan timeStamp = TimeSpan.Zero;

                        if (_fromCamera)
                        {
                            frame = _camera.GetFrame();
                        }
                        else
                        {
                            lock (_readerLock)
                            {
                                frame = _videoReader.ReadVideoSample(out timeStamp, out duration);
                            }
                        }

                        if (frame == null) //camera unplugged or end of file
                        {
                            createFaceRecord = false;
                            SetImageToView(null, null, null, NleExtractionStatus.None, -1, timeStamp);
                            return;
                        }

                        using (grayscaleImage = frame.ToGrayscale())
                        {
                            if (createFaceRecord)
                            {
                                NleDetectionDetails details;
                                NLTemplate          template = null;
                                //NBuffer template = null;
                                if (!extractionStarted)
                                {
                                    UpdateExtractorTemplateSize();
                                    frameCount = Tools.LiveEnrolFrameCount;
                                    _extractor.ExtractStart();
                                    extractionStarted = true;
                                    frameNumber       = 0;
                                    ClearCapturedImages();
                                }
                                frameNumber++;
                                NleExtractionStatus status = _extractor.ExtractNext(grayscaleImage, out details);
                                capturedImages.Add((NImage)frame.Clone());

                                if (status != NleExtractionStatus.None || frameNumber >= frameCount)
                                {
                                    template = _extractor.ExtractEnd(out bestFrame, out status);
                                    if (status == NleExtractionStatus.TemplateCreated)
                                    {
                                        NTemplate nTemplate = new NTemplate();
                                        NImage    bestImage = frame;
                                        if (bestFrame < capturedImages.Count && bestFrame >= 0)
                                        {
                                            bestImage = capturedImages[bestFrame];
                                        }
                                        _newRecord = new FaceRecord(template, bestImage, details);
                                        _newRecord.AddToTemplate(nTemplate);
                                        template.Dispose();
                                        capturedImages.Remove(bestImage);
                                        _capturedTemplateList = new List <byte[]>();
                                        _capturedTemplateList.Add(nTemplate.Save().ToByteArray());

                                        score = Identify(_capturedTemplateList, _enrolledTemplateList);
                                        LogLine(string.Format("Face match details: score {0}.", score), true);

                                        backgroundWorker.CancelAsync();
                                    }
                                    else
                                    {
                                        _newRecord = null;
                                    }
                                    extractionStarted = false;
                                    createFaceRecord  = false;
                                }

                                if (!createFaceRecord)
                                {
                                    ClearCapturedImages();
                                }

                                SetImageToView(nlView2, frame.ToBitmap(), new NleDetectionDetails[] { details }, status, (int)(frameNumber * 100.0 / frameCount), timeStamp);

                                if (status != NleExtractionStatus.None && status != NleExtractionStatus.TemplateCreated)
                                {
                                    backgroundWorker.CancelAsync();

                                    score = 0;
                                }
                            }
                            else
                            {
                                NleDetectionDetails[] details = null;
                                try
                                {
                                    NleFace[] faces = _extractor.DetectFaces(grayscaleImage);
                                    if (faces != null)
                                    {
                                        details = new NleDetectionDetails[faces.Length];
                                        for (int i = 0; i < faces.Length; i++)
                                        {
                                            details[i] = _extractor.DetectFacialFeatures(grayscaleImage, faces[i]);
                                        }
                                    }
                                }
                                finally
                                {
                                    SetImageToView(nlView2, frame.ToBitmap(), details, NleExtractionStatus.None, -1, timeStamp);
                                }
                            }
                        } //using
                    }     // try
                    finally
                    {
                        if (frame != null)
                        {
                            frame.Dispose();
                        }
                    }
                }// while
            }
            catch (Exception ex)
            {
                foreach (NImage img in capturedImages)
                {
                    img.Dispose();
                }
                capturedImages.Clear();

                ShowError(ex.Message);
            }
            finally
            {
                try
                {
                    int baseFrameIndex;
                    NleExtractionStatus status;
                    if (extractionStarted)
                    {
                        _extractor.ExtractEnd(out baseFrameIndex, out status);
                    }
                    if (_fromCamera && _camera != null)
                    {
                        _camera.StopCapturing();
                    }
                    if (!_fromCamera && _videoReader != null)
                    {
                        _videoReader.Stop();
                    }
                }
                catch { }
            }
        }
Esempio n. 20
0
        //Métodos secundarios
        void ProcessEvents(Event e, Rect viewRect)
        {
            if (viewRect.Contains(e.mousePosition))
            {
                if (e.button == 2)
                {
                    if (e.type == EventType.MouseDown)
                    {
                        for (int i = 0; i < nodes.Count; i++)
                        {
                            nodes[i].isPanning = true;
                        }

                        panningScreen = true;
                    }

                    if (e.type == EventType.MouseDrag && panningScreen)
                    {
                        offset += e.delta / zoom;
                    }

                    else if (e.type == EventType.MouseUp)
                    {
                        for (int i = 0; i < nodes.Count; i++)
                        {
                            nodes[i].isPanning = false;
                        }

                        panningScreen = false;
                    }
                }

                else if (e.button == 0)
                {
                    if (e.type == EventType.MouseDown)
                    {
                        DeselectAllNodes();
                        bool setNode = false;
                        selectedNode = null;
                        for (int i = 0; i < nodes.Count; i++)
                        {
                            if (nodes[i].myRect.Contains(e.mousePosition))
                            {
                                if (selectedNode == null)
                                {
                                    var temp = nodes[i];
                                    nodes.RemoveAt(i);
                                    temp.isSelected = true;
                                    selectedNode    = temp;
                                    nodes.Add(temp);
                                    setNode = true;
                                    //edTemp = Editor.CreateEditor(selectedNode);

                                    Selection.activeObject = selectedNode;
                                    //AssetDatabase.Refresh();
                                }
                            }
                        }

                        if (!setNode)
                        {
                            DeselectAllNodes();
                        }

                        if (wantsConnection)
                        {
                            wantsConnection = false;
                        }
                    }
                }

                else
                {
                    if (e.type == EventType.MouseDown && !nodes.Any(x => x.myRect.Contains(e.mousePosition)))
                    {
                        DeselectAllNodes();
                    }
                }
            }
        }