Example #1
0
        public bool DeleteFaceObject(FaceObject mFaceObj)
        {
            bool ret     = false;
            var  builder = Builders <FaceObject> .Filter;
            var  filter  = builder.Eq("_id", mFaceObj.Id);
            var  result  = mFaceObjectCollection.DeleteOne(filter);

            if (result.DeletedCount >= 1)
            {
                ret = true;
            }
            return(ret);
        }
    /// <summary>
    /// Spawns cursor for the Main Camera
    /// </summary>
    // private void CreateLabel()
    // {
    //     // Create a sphere as new cursor
    //     GameObject newLabel = new GameObject();
    //
    //     // Attach the label to the Main Camera
    //     newLabel.transform.parent = gameObject.transform;
    //
    //     // Resize and position the new cursor
    //     newLabel.transform.localScale = new Vector3(0.4f, 0.4f, 0.4f);
    //     newLabel.transform.position = new Vector3(0f, 3f, 60f);
    //
    //     // Creating the text of the Label
    //     labelText = newLabel.AddComponent<TextMesh>();
    //     labelText.anchor = TextAnchor.MiddleCenter;
    //     labelText.alignment = TextAlignment.Center;
    //     labelText.tabSize = 4;
    //     labelText.fontSize = 50;
    //     labelText.text = ".";
    // }

    public void PlayTextToSpeechMessage(FaceObject faceObj)
    {
        string message     = string.Empty;
        string emotionName = string.Empty;
        int    numOfFaces  = faceObj.faces.Count;

        if (numOfFaces > 0)
        {
            // StartCoroutine(IdentifyFaces(faceObj.faces));
            message += "There are " + numOfFaces + " people here.";

            foreach (Face face in faceObj.faces)
            {
                EmotionAttributes emotionAttributes = face.emotionAttributes;

                Dictionary <string, float> emotions = new Dictionary <string, float>
                {
                    { "neutral", emotionAttributes.neutral },
                    { "angry", emotionAttributes.anger },
                    { "argumentive", emotionAttributes.contempt },
                    { "disgusted", emotionAttributes.disgust },
                    { "scared", emotionAttributes.fear },
                    { "happy", emotionAttributes.happiness },
                    { "sad", emotionAttributes.sadness },
                    { "suprised", emotionAttributes.surprise }
                };

                emotionName = emotions.Aggregate((x, y) => x.Value > y.Value ? x : y).Key;

                //Message
                message += string.Format("A {0} year old {1} who is feeling {2}",
                                         face.faceAttributes.age,
                                         face.faceAttributes.gender == 0 ? "man" : "woman",
                                         emotionName);
            }
        }
        else
        {
            message = "I couldn't detect anyone.";
        }

        // Try and get a TTS Manager
        // TextToSpeech tts = ttsManager;

        if (ttsManager != null)
        {
            //Play voice message
            ttsManager.StartSpeaking(message);
        }
    }
Example #3
0
    private void SaveJsonToFaceModel(JSONObject j)
    {
        FaceObject  faceObj = new FaceObject();
        List <Face> faces   = new List <Face>();

        foreach (var faceItem in j.list)
        {
            Face face = new Face();

            face = new Face()
            {
                faceId = faceItem.GetField("faceId").ToString()
            };

            var faceRectangle = faceItem.GetField("faceRectangle");
            face.faceRectangle = new FaceRectangle()
            {
                left   = int.Parse(faceRectangle.GetField("left").ToString()),
                top    = int.Parse(faceRectangle.GetField("top").ToString()),
                width  = int.Parse(faceRectangle.GetField("width").ToString()),
                height = int.Parse(faceRectangle.GetField("height").ToString())
            };

            var faceAttributes = faceItem.GetField("faceAttributes");
            face.faceAttributes = new FaceAttributes()
            {
                age    = int.Parse(faceAttributes.GetField("age").ToString().Split('.')[0]),
                gender = faceAttributes.GetField("gender").ToString().Replace("\"", "") == "male" ? 0 : 1
            };

            var emotion = faceAttributes.GetField("emotion");
            face.emotionAttributes = new EmotionAttributes()
            {
                anger     = float.Parse(emotion.GetField("anger").ToString()),
                contempt  = float.Parse(emotion.GetField("contempt").ToString()),
                disgust   = float.Parse(emotion.GetField("disgust").ToString()),
                fear      = float.Parse(emotion.GetField("fear").ToString()),
                happiness = float.Parse(emotion.GetField("happiness").ToString()),
                neutral   = float.Parse(emotion.GetField("neutral").ToString()),
                sadness   = float.Parse(emotion.GetField("sadness").ToString()),
                surprise  = float.Parse(emotion.GetField("surprise").ToString()),
            };
            faces.Add(face);
        }

        faceObj.faces = faces;

        PlayVoiceMessage.Instance.PlayTextToSpeechMessage(faceObj);
    }
Example #4
0
    void Update()
    {
        FaceObject currentFace = this.GetComponent <CountTime> ().thisFace();
        float      value       = (float)((currentFace.counter / 5000));

        if (value > duration)
        {
            value = duration;
        }



        float lerp = Mathf.PingPong(value, duration) / duration;

        rend.material.color = Color.Lerp(colourStart, colourEnd, lerp);
    }
Example #5
0
    void Update()
    {
        Slider slider1 = GameObject.Find("Slider1").GetComponent <Slider>();
        Slider slider2 = GameObject.Find("Slider2").GetComponent <Slider>();
        Slider slider3 = GameObject.Find("Slider3").GetComponent <Slider>();


        if (_gazeAware.HasGaze)
        {
            attentionTimer.Start();
            distractionTimer.Stop();
            distractionTimer.Reset();

            switch (this.tag)
            {
            case "HappyTag":
                currentFace = Happy;
                break;

            case "SadTag":
                currentFace = Sad;
                break;

            case "ConfusedTag":
                currentFace = Confused;
                break;
            }

            thisFace().counter = attentionTimer.Elapsed.TotalMilliseconds;

            slider1.value = (float)(Happy.counter) / 5000;
            slider2.value = (float)(Sad.counter) / 5000;
            slider3.value = (float)(Confused.counter) / 5000;

            //print ("Face = " + thisFace().name + " Counter =" + thisFace().counter);
        }
        else
        {
            attentionTimer.Stop();
            distractionTimer.Start();

            if (distractionTimer.ElapsedMilliseconds > 750)
            {
                attentionTimer.Reset();
            }
        }
    }
Example #6
0
    void Update()
    {
        Slider slider1 = GameObject.Find ("Slider1").GetComponent<Slider>();
        Slider slider2 = GameObject.Find ("Slider2").GetComponent<Slider>();
        Slider slider3 = GameObject.Find ("Slider3").GetComponent<Slider>();

        if (_gazeAware.HasGaze) {
            attentionTimer.Start ();
            distractionTimer.Stop ();
            distractionTimer.Reset();

            switch (this.tag) {
            case "HappyTag":
                currentFace = Happy;
                break;
            case "SadTag":
                currentFace = Sad;
                break;
            case "ConfusedTag":
                currentFace = Confused;
                break;
            }

            thisFace().counter = attentionTimer.Elapsed.TotalMilliseconds;

            slider1.value = (float)(Happy.counter)/5000;
            slider2.value = (float)(Sad.counter)/5000;
            slider3.value = (float)(Confused.counter)/5000;

            //print ("Face = " + thisFace().name + " Counter =" + thisFace().counter);
        } else {
            attentionTimer.Stop();
            distractionTimer.Start();

            if(distractionTimer.ElapsedMilliseconds > 750) {
                attentionTimer.Reset();
            }
        }
    }
Example #7
0
 public bool AddFaceObject(FaceObject mFaceObj)
 {
     mFaceObjectCollection.InsertOne(mFaceObj);
     return(true);
 }
Example #8
0
        void timer_Tick(object sender, EventArgs e)
        {
            try
            {
                currentFrame = capture.QueryFrame();

                Image <Gray, Byte> gray = currentFrame.Convert <Gray, byte>();

                faceDetected = Process.Detector.DetectFace(gray);
                double[] distance = new double[found.Length + 1];

                List <DrawTextData> faceFound = new List <DrawTextData>();
                faceObjects[0] = new List <FaceObject>();

                for (int i = 0; i < faceDetected.Length; i++)
                {
                    Image <Gray, Byte> face = gray.Copy(faceDetected[i]).Resize(100, 100, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);
                    face = Process.Detector.PreProcess(face);

                    FaceRecognizer.PredictionResult tmp  = recognizer.Who(face);
                    FaceRecognizer.PredictionResult tmp2 = recognizer.Who(face.Copy().Flip(FLIP.HORIZONTAL).Convert <Gray, Byte>());
                    FaceRecognizer.PredictionResult who  = tmp.Distance < tmp2.Distance ? tmp : tmp2;

                    if (who.Label > -1)
                    {
                        FaceObject facObj = new FaceObject(faceDetected[i], face, who.Distance, who.Label, CurrentMillis.Millis + "");
                        facObj.Label    = who.Label;
                        facObj.Distance = who.Distance;
                        facObj.Rect     = faceDetected[i];
                        facObj.DateTime = CurrentMillis.Millis + "";
                        faceObjects[0].Add(facObj);
                    }
                }

                if (faceObjects[1] != null)
                {
                    foreach (FaceObject fobj1 in faceObjects[1])
                    {
                        int    idxMin = -1;
                        double d2pMin = Double.MaxValue;
                        for (int i = 0; i < faceObjects[0].Count; i++)
                        {
                            double d2p = Math.Sqrt((fobj1.Rect.X - faceObjects[0][i].Rect.X) * (fobj1.Rect.X - faceObjects[0][i].Rect.X) + (fobj1.Rect.Y - faceObjects[0][i].Rect.Y) * (fobj1.Rect.Y - faceObjects[0][i].Rect.Y));
                            if (d2p < d2pMin)
                            {
                                d2pMin = d2p; idxMin = i;
                            }
                        }
                        Student s    = (Student)mapStudentData[fobj1.Label + ""];
                        String  text = s.ID + " " + s.StudentID + " " + s.Name + " " + s.LastName;


                        if (d2pMin > 50f)
                        {
                            if (found[fobj1.Label] != null)
                            {
                                if (found[fobj1.Label].Distance > fobj1.Distance)
                                {
                                    found[fobj1.Label] = new Found(fobj1.Distance, fobj1.Image.Clone());
                                    Image <Gray, byte> test = found[fobj1.Label].Image.Clone();

                                    String imagePath = currDatePath + s.StudentID + ".jpg";
                                    Display.Bitmap.SaveToJpeg(found[fobj1.Label].Image.Clone().Convert <Gray, Byte>(), imagePath);

                                    using (System.IO.StreamWriter file = new System.IO.StreamWriter(currDatePath + s.StudentID + ".txt"))
                                    {
                                        String textOut = s.ID + "\t" + s.StudentID + "\t" + s.Name + "\t" + s.LastName + "\t" + fobj1.Distance;

                                        file.WriteLine(textOut);
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (faceObjects[0][idxMin].Distance > fobj1.Distance)
                            {
                                faceObjects[0][idxMin].Distance = fobj1.Distance;
                                faceObjects[0][idxMin].Label    = fobj1.Label;
                                faceObjects[0][idxMin].Image    = fobj1.Image.Clone();
                            }
                            faceObjects[0][idxMin].DateTime = fobj1.DateTime;
                        }
                        distance[fobj1.Label] = fobj1.Distance;
                        faceFound.Add(new DrawTextData(fobj1.Rect, text + " " + fobj1.Distance));
                    }
                }

                // StackPanelMain.Children.Clear();
                for (int i = 0; i < found.Length; i++)
                {
                    if (found[i] != null)
                    {
                        if (found[i].Distance < double.MaxValue)
                        {
                            Student      s    = (Student)mapStudentData[i + ""];
                            UCResultItem item = (UCResultItem)mapImage[s.StudentID];
                            item.RPic.Source  = Display.Bitmap.ToBitmapSource(found[i].Image);
                            item.Name.Content = found[i].Distance + " " + distance[i];
                            mark(i);
                            //StackPanelMain.Children[2]
                            // StackPanelMain.Children.Add(item);
                        }
                    }
                }
                faceObjects[1] = new List <FaceObject>(faceObjects[0]);

                DispFrame.Source = Display.Bitmap.ToBitmapSource(Process.Detector.DrawFace(currentFrame.Clone(), faceDetected, (faceFound.Count > 0)), faceFound);
            }
            catch {
            }
        }