Ejemplo n.º 1
0
    protected void AddFace(NBTMesh mesh, FaceAttributes fa, CubeAttributes ca)
    {
        UnityEngine.Profiling.Profiler.BeginSample("AddFace");
        ushort startIndex = mesh.vertexCount;

        if (fa.skyLight == null)
        {
            fa.skyLight = skylight_default;
        }
        if (fa.blockLight == null)
        {
            fa.blockLight = blocklight_default;
        }

        SetVertex(mesh, fa.pos[0] + ca.pos, fa.faceIndex, fa.uv[0], fa.skyLight[0], fa.blockLight[0], fa.color, fa.normal);
        SetVertex(mesh, fa.pos[1] + ca.pos, fa.faceIndex, fa.uv[1], fa.skyLight[1], fa.blockLight[1], fa.color, fa.normal);
        SetVertex(mesh, fa.pos[2] + ca.pos, fa.faceIndex, fa.uv[2], fa.skyLight[2], fa.blockLight[2], fa.color, fa.normal);
        SetVertex(mesh, fa.pos[3] + ca.pos, fa.faceIndex, fa.uv[3], fa.skyLight[3], fa.blockLight[3], fa.color, fa.normal);

        mesh.triangleArray[mesh.triangleCount++] = startIndex;
        mesh.triangleArray[mesh.triangleCount++] = (ushort)(startIndex + 1);
        mesh.triangleArray[mesh.triangleCount++] = (ushort)(startIndex + 2);
        mesh.triangleArray[mesh.triangleCount++] = startIndex;
        mesh.triangleArray[mesh.triangleCount++] = (ushort)(startIndex + 2);
        mesh.triangleArray[mesh.triangleCount++] = (ushort)(startIndex + 3);
        UnityEngine.Profiling.Profiler.EndSample();
    }
Ejemplo n.º 2
0
        private void PrintDebugDataToScreen(FaceWithEmotions[] faces)
        {
            var ignored = this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                //then show the data values
                if (faces != null)
                {
                    FaceCollection.Clear();

                    foreach (FaceWithEmotions faceEmotion in faces)
                    {
                        if (faceEmotion != null && faceEmotion.Face != null)
                        {
                            if (faceEmotion.Bitmap != null)
                            {
                                lastSendImage.Source = faceEmotion.Bitmap;
                            }
                            Emotion emotion     = faceEmotion.Emotion;
                            Face face           = faceEmotion.Face;
                            FaceAttributes attr = face.FaceAttributes;
                            if (attr != null)
                            {
                                FaceCollection.Insert(0, FaceDetails.FromFaceAndEmotion(face, emotion));
                            }
                        }
                    }
                }
            });
        }
Ejemplo n.º 3
0
    public override void AddCube(NBTChunk chunk, byte blockData, Vector3Int pos, NBTGameObject nbtGO)
    {
        ca.pos       = pos;
        ca.blockData = blockData;

        if (!chunk.HasOpaqueBlock(pos.x, pos.y, pos.z - 1))
        {
            FaceAttributes fa = GetFrontFaceAttributes(chunk, nbtGO.nbtMesh, ca);
            AddFace(nbtGO.nbtMesh, fa, ca);
        }
        if (!chunk.HasOpaqueBlock(pos.x + 1, pos.y, pos.z))
        {
            FaceAttributes fa = GetRightFaceAttributes(chunk, nbtGO.nbtMesh, ca);
            AddFace(nbtGO.nbtMesh, fa, ca);
        }
        if (!chunk.HasOpaqueBlock(pos.x - 1, pos.y, pos.z))
        {
            FaceAttributes fa = GetLeftFaceAttributes(chunk, nbtGO.nbtMesh, ca);
            AddFace(nbtGO.nbtMesh, fa, ca);
        }
        if (!chunk.HasOpaqueBlock(pos.x, pos.y, pos.z + 1))
        {
            FaceAttributes fa = GetBackFaceAttributes(chunk, nbtGO.nbtMesh, ca);
            AddFace(nbtGO.nbtMesh, fa, ca);
        }

        AddFace(nbtGO.nbtMesh, GetTopFaceAttributes(chunk, nbtGO.nbtMesh, ca), ca);

        if (!chunk.HasOpaqueBlock(pos.x, pos.y - 1, pos.z))
        {
            FaceAttributes fa = GetBottomFaceAttributes(chunk, nbtGO.nbtMesh, ca);
            AddFace(nbtGO.nbtMesh, fa, ca);
        }
    }
Ejemplo n.º 4
0
    public override Mesh GetItemMesh(NBTChunk chunk, Vector3Int pos, byte blockData)
    {
        CubeAttributes ca = new CubeAttributes();

        ca.blockData = blockData;

        NBTMesh nbtMesh = new NBTMesh(256);

        chunk.GetLights(pos.x - chunk.x * 16, pos.y, pos.z - chunk.z * 16, out float skyLight, out float blockLight);

        FaceAttributes fa = new FaceAttributes();

        fa.faceIndex  = TextureArrayManager.GetIndexByName(GetNameByData(blockData));
        fa.skyLight   = new float[] { skyLight, skyLight, skyLight, skyLight };
        fa.blockLight = new float[] { blockLight, blockLight, blockLight, blockLight };
        fa.color      = Color.white;

        FillMesh(fa, ca, nbtMesh);

        nbtMesh.Refresh();

        nbtMesh.Dispose();

        return(nbtMesh.mesh);
    }
        private void SaveConstituentPhotoAnalysis(IList <DetectedFace> faceList, Guid constituentID)
        {
            if (faceList == null || faceList.Count == 0)
            {
                throw new Exception("No faces found.");
            }
            else if (faceList.Count > 1)
            {
                throw new Exception("More than one face found.");
            }
            else
            {
                FaceAttributes faceAttributes = faceList[0].FaceAttributes;
                int            age            = -1;
                if (faceAttributes.Age.HasValue)
                {
                    age = (int)faceAttributes.Age.Value;
                }
                int genderCode = 0;
                if (faceAttributes.Gender.HasValue)
                {
                    switch (faceAttributes.Gender.ToString())
                    {
                    case "Unknown":
                        genderCode = 0;
                        break;

                    case "Male":
                        genderCode = 1;
                        break;

                    case "Female":
                        genderCode = 2;
                        break;
                    }
                    ;
                }


                using (SqlConnection conn = RequestContext.OpenAppDBConnection())
                {
                    SPWrapConstituentPhotoAnalysis.USR_USP_CONSTITUENTPHOTOANALYSIS_UPSERT.WrapperRoutines.ExecuteNonQuery(
                        conn,
                        constituentID,
                        (byte)genderCode,
                        age,
                        (decimal)faceAttributes.Emotion.Anger,
                        (decimal)faceAttributes.Emotion.Contempt,
                        (decimal)faceAttributes.Emotion.Disgust,
                        (decimal)faceAttributes.Emotion.Fear,
                        (decimal)faceAttributes.Emotion.Happiness,
                        (decimal)faceAttributes.Emotion.Neutral,
                        (decimal)faceAttributes.Emotion.Sadness,
                        (decimal)faceAttributes.Emotion.Surprise,
                        null,
                        null
                        );
                }
            }
        }
        public static string SummarizeFaceAttributes(FaceAttributes attr)
        {
            List <string> attrs = new List <string>();

            if (attr.Age < 18)
            {
                attrs.Add("!!UNDER 18 ALERT!! ");
            }

            if (attr.Gender != null)
            {
                attrs.Add(attr.Gender);
            }
            if (attr.Age > 0)
            {
                attrs.Add(attr.Age.ToString());
            }
            if (attr.HeadPose != null)
            {
                // Simple rule to estimate whether person is facing camera.
                bool facing = Math.Abs(attr.HeadPose.Yaw) < 25;
                attrs.Add(facing ? "facing camera" : "not facing camera");
            }
            return(string.Join("; ", attrs));
        }
Ejemplo n.º 7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="attr"></param>
        /// <returns></returns>
        public static string SummarizeFaceAttributes(FaceAttributes attr)
        {
            List <string> attrs = new List <string>();

            if (attr.Gender != null)
            {
                attrs.Add(attr.Gender);
            }
            if (attr.Age > 0)
            {
                attrs.Add(attr.Age.ToString());
            }
            if (attr.Emotion.Happiness > .5)
            {
                attrs.Add("Student Very Happy");
            }
            if (attr.HeadPose != null)
            {
                // Simple rule to estimate whether person is facing camera.
                bool facing = Math.Abs(attr.HeadPose.Yaw) < 25;

                if (facing && attr.Emotion.Happiness > .5)
                {
                    attrs.Add(facing ? "facing camera" : "not facing camera");
                }
            }
            return(string.Join(", ", attrs));
        }
Ejemplo n.º 8
0
    public override void AddCube(NBTChunk chunk, byte blockData, Vector3Int pos, NBTGameObject nbtGO)
    {
        ca.pos       = pos;
        ca.blockData = blockData;

        InitBlockAttributes(chunk, ref ca);

        bool topIsSnow = chunk.GetBlockByte(pos.x, pos.y + 1, pos.z) == 78;

        if (!chunk.HasOpaqueBlock(pos.x, pos.y, pos.z - 1))
        {
            FaceAttributes fa = GetFrontFaceAttributes(chunk, nbtGO.nbtMesh, ca);
            if (topIsSnow)
            {
                fa.faceIndex = TextureArrayManager.GetIndexByName("grass_side_snowed");
            }
            AddFace(nbtGO.nbtMesh, fa, ca);
        }
        if (!chunk.HasOpaqueBlock(pos.x + 1, pos.y, pos.z))
        {
            FaceAttributes fa = GetRightFaceAttributes(chunk, nbtGO.nbtMesh, ca);
            if (topIsSnow)
            {
                fa.faceIndex = TextureArrayManager.GetIndexByName("grass_side_snowed");
            }
            AddFace(nbtGO.nbtMesh, fa, ca);
        }
        if (!chunk.HasOpaqueBlock(pos.x - 1, pos.y, pos.z))
        {
            FaceAttributes fa = GetLeftFaceAttributes(chunk, nbtGO.nbtMesh, ca);
            if (topIsSnow)
            {
                fa.faceIndex = TextureArrayManager.GetIndexByName("grass_side_snowed");
            }
            AddFace(nbtGO.nbtMesh, fa, ca);
        }
        if (!chunk.HasOpaqueBlock(pos.x, pos.y, pos.z + 1))
        {
            FaceAttributes fa = GetBackFaceAttributes(chunk, nbtGO.nbtMesh, ca);
            if (topIsSnow)
            {
                fa.faceIndex = TextureArrayManager.GetIndexByName("grass_side_snowed");
            }
            AddFace(nbtGO.nbtMesh, fa, ca);
        }
        if (!chunk.HasOpaqueBlock(pos.x, pos.y + 1, pos.z))
        {
            FaceAttributes fa = GetTopFaceAttributes(chunk, nbtGO.nbtMesh, ca);
            if (topIsSnow)
            {
                fa.faceIndex = TextureArrayManager.GetIndexByName("snow");
            }
            AddFace(nbtGO.nbtMesh, fa, ca);
        }
        if (!chunk.HasOpaqueBlock(pos.x, pos.y - 1, pos.z))
        {
            FaceAttributes fa = GetBottomFaceAttributes(chunk, nbtGO.nbtMesh, ca);
            AddFace(nbtGO.nbtMesh, fa, ca);
        }
    }
Ejemplo n.º 9
0
    public override void AddCube(NBTChunk chunk, byte blockData, Vector3Int pos, NBTGameObject nbtGO)
    {
        ca.pos       = pos;
        ca.blockData = blockData;

        chunk.GetLights(pos.x, pos.y, pos.z, out float skyLight, out float blockLight);

        FaceAttributes fa = new FaceAttributes();

        fa.faceIndex  = GetPlantIndexByData(chunk, blockData);
        fa.color      = Color.white;
        fa.skyLight   = new float[] { skyLight, skyLight, skyLight, skyLight };
        fa.blockLight = new float[] { blockLight, blockLight, blockLight, blockLight };
        fa.normal     = Vector3.zero;
        fa.uv         = uv_zero;

        try
        {
            fa.pos = face1;
            AddFace(nbtGO.nbtMesh, fa, ca);
            fa.pos = face2;
            AddFace(nbtGO.nbtMesh, fa, ca);

            fa.pos = face3;
            AddFace(nbtGO.nbtMesh, fa, ca);
            fa.pos = face4;
            AddFace(nbtGO.nbtMesh, fa, ca);
        }
        catch (System.Exception e)
        {
            Debug.Log(e.ToString() + "\n" + "pos=" + pos + ",data=" + blockData);
        }
    }
Ejemplo n.º 10
0
        public static string SummarizeFaceAttributes(FaceAttributes attr)
        {
            List <string> attrs = new List <string>();

            if (attr.Gender != null)
            {
                attrs.Add(attr.Gender);
            }
            if (attr.Age > 0)
            {
                attrs.Add(attr.Age.ToString());
            }
            if (attr.HeadPose != null)
            {
                // Simple rule to estimate whether person is facing camera.
                bool facing = Math.Abs(attr.HeadPose.Yaw) < 25;
                attrs.Add(facing ? "facing camera" : "not facing camera");
            }

            attrs.Add(attr.Glasses.ToString());
            //attrs.Add(attr.Hair.Bald.ToString());

            attrs.Add("Beard :" + attr.FacialHair.Beard.ToString() + "," + "Moustache :" + attr.FacialHair.Moustache.ToString() + "," + "Sideburns :" + attr.FacialHair.Sideburns.ToString());

            return(string.Join(", ", attrs));
        }
Ejemplo n.º 11
0
    void FillMesh(NBTChunk chunk, CubeAttributes ca, NBTMesh nbtMesh)
    {
        chunk.GetLights(ca.pos.x, ca.pos.y, ca.pos.z, out float skyLight, out float blockLight);

        FaceAttributes fa = new FaceAttributes();

        fa.faceIndex  = TextureArrayManager.GetIndexByName("ladder");
        fa.color      = Color.white;
        fa.skyLight   = new float[] { skyLight, skyLight, skyLight, skyLight };
        fa.blockLight = new float[] { blockLight, blockLight, blockLight, blockLight };
        fa.normal     = Vector3.zero;
        fa.uv         = uv_zero;

        if (ca.blockData == 2)
        {
            fa.pos = frontFace;
            AddFace(nbtMesh, fa, ca);
        }
        else if (ca.blockData == 3)
        {
            fa.pos = backFace;
            AddFace(nbtMesh, fa, ca);
        }
        else if (ca.blockData == 4)
        {
            fa.pos = leftFace;
            AddFace(nbtMesh, fa, ca);
        }
        else if (ca.blockData == 5)
        {
            fa.pos = rightFace;
            AddFace(nbtMesh, fa, ca);
        }
    }
Ejemplo n.º 12
0
        public static FaceAttributes DisplayPercentage(double smile)
        {
            var facceAttributes = new FaceAttributes {
                Smile = smile * 100
            };

            return(facceAttributes);
        }
Ejemplo n.º 13
0
 private void AssignFaceAttributes(FaceAttributes faceAttributes)
 {
     AssignBasicAttributes(faceAttributes);
     AssignHairAttributes(faceAttributes);
     AssignFacialHairAttributes(faceAttributes);
     AssignAdditionalAttributes(faceAttributes);
     AssignEmotionAttributes(faceAttributes);
 }
Ejemplo n.º 14
0
 public Player(Guid id, FaceRectangle position, FaceAttributes attributes)
 {
     this.Id              = id;
     this.Position        = position;
     this.DominantEmotion = this.GetDominantEmotion(attributes.Emotion);
     this.Attributes      = attributes;
     //this.AccumulateScore();
 }
Ejemplo n.º 15
0
        private string GetImageQualityText(FaceAttributes attributes)
        {
            var noise    = attributes.Noise != null ? "\nNoise: " + attributes.Noise.NoiseLevel.ToString() + " (" + attributes.Noise.Value + ")" : "";
            var exposure = attributes.Exposure != null ? "\nExposure: " + attributes.Exposure.ExposureLevel.ToString() + " (" + attributes.Exposure.Value + ")" : "";
            var blur     = attributes.Blur != null ? "\nBlur: " + attributes.Blur.BlurLevel.ToString() + " (" + attributes.Blur.Value + ")" : "";

            return(noise + exposure + blur);
        }
Ejemplo n.º 16
0
    public override Mesh GetItemMesh(byte data = 0)
    {
        CubeAttributes ca = new CubeAttributes();

        NBTMesh nbtMesh = new NBTMesh(256);

        FaceAttributes fa = new FaceAttributes();

        //fa.skyLight = skylight_default;
        //fa.blockLight = blocklight_default;
        fa.color = Color.white;
        fa.uv    = uv_zero;

        try
        {
            fa.pos       = frontVertices;
            fa.normal    = Vector3.forward;
            fa.faceIndex = TextureArrayManager.GetIndexByName(frontName);
            AddFace(nbtMesh, fa, ca);

            fa.pos       = backVertices;
            fa.normal    = Vector3.back;
            fa.faceIndex = TextureArrayManager.GetIndexByName(backName);
            AddFace(nbtMesh, fa, ca);

            fa.pos       = topVertices;
            fa.normal    = Vector3.up;
            fa.faceIndex = TextureArrayManager.GetIndexByName(topName);
            fa.color     = TintManager.tintColor;
            AddFace(nbtMesh, fa, ca);
            fa.color = Color.white;

            fa.pos       = bottomVertices;
            fa.normal    = Vector3.down;
            fa.faceIndex = TextureArrayManager.GetIndexByName(bottomName);
            AddFace(nbtMesh, fa, ca);

            fa.pos       = leftVertices;
            fa.normal    = Vector3.left;
            fa.faceIndex = TextureArrayManager.GetIndexByName(leftName);
            AddFace(nbtMesh, fa, ca);

            fa.pos       = rightVertices;
            fa.normal    = Vector3.right;
            fa.faceIndex = TextureArrayManager.GetIndexByName(rightName);
            AddFace(nbtMesh, fa, ca);
        }
        catch (System.Exception e)
        {
            Debug.LogError("GetItemMesh error,generator=" + GetType() + ",message=\n" + e.Message);
        }

        nbtMesh.Refresh();

        nbtMesh.Dispose();

        return(nbtMesh.mesh);
    }
Ejemplo n.º 17
0
        private void AssignBasicAttributes(FaceAttributes faceAttributes)
        {
            Age    = faceAttributes.Age;
            Gender = faceAttributes.Gender;

            Roll  = faceAttributes.HeadPose.Roll;
            Yaw   = faceAttributes.HeadPose.Yaw;
            Pitch = faceAttributes.HeadPose.Pitch;
        }
Ejemplo n.º 18
0
 private static void ProcessBeard(FaceAttributes faceAttributes, List <Trait> traits)
 {
     if (faceAttributes.FacialHair.Beard >= 0.4)
     {
         traits.Add(new Trait {
             Name = "beard", Accuracy = faceAttributes.FacialHair.Beard
         });
     }
 }
Ejemplo n.º 19
0
 private static void ProcessBald(FaceAttributes faceAttributes, List <Trait> traits)
 {
     if (faceAttributes.Hair.Bald >= 0.4)
     {
         traits.Add(new Trait {
             Name = "bald", Accuracy = faceAttributes.Hair.Bald
         });
     }
 }
Ejemplo n.º 20
0
 private static void ProcessOldAge(FaceAttributes faceAttributes, List <Trait> traits)
 {
     if (faceAttributes.Age > 40)
     {
         traits.Add(new Trait {
             Name = "old", Accuracy = 1
         });
     }
 }
Ejemplo n.º 21
0
 private static void ProcessGlasses(FaceAttributes faceAttributes, List <Trait> traits)
 {
     if (faceAttributes.Glasses == Glasses.ReadingGlasses)
     {
         traits.Add(new Trait {
             Name = "glasses", Accuracy = 1.0
         });
     }
 }
Ejemplo n.º 22
0
        public static string SummarizeFaceAttributes(FaceAttributes attr)
        {
            List <string> attrs = new List <string>();

            foreach (var a in attr.Accessories.Where(a => a.Confidence > .5))
            {
                attrs.Add(a.Type.ToString());
            }
            if (attr.FacialHair.Beard > .5)
            {
                attrs.Add("Beard");
            }
            if (attr.FacialHair.Moustache > .5)
            {
                attrs.Add("Moustache");
            }
            if (attr.FacialHair.Sideburns > .5)
            {
                attrs.Add("Sideburns");
            }
            attrs.Add(attr.Glasses.ToString());
            if (attr.Hair != null)
            {
                if (attr.Hair.Bald > .5)
                {
                    attrs.Add("Bald");
                }
                ;
                foreach (var hair in attr.Hair.HairColor)
                {
                    if (hair.Confidence > .5)
                    {
                        attrs.Add($"{hair.Color} hair");
                        break;
                    }
                    ;
                }
            }
            if (attr.Smile > .5)
            {
                attrs.Add("Smiling");
            }
            if (attr.Gender != null)
            {
                attrs.Add(attr.Gender);
            }
            if (attr.Age > 0)
            {
                attrs.Add(attr.Age.ToString());
            }
            if (attr.HeadPose != null)
            {
                // Simple rule to estimate whether person is facing camera.
                attrs.Add(Math.Abs(attr.HeadPose.Yaw) < 50 ? "facing camera" : "not facing camera");
            }
            return(string.Join("\n", attrs));
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Generates the data for the attributes
        /// </summary>
        private void GenerateAttributeData(FaceAttributes face)
        {
            Gender      = face.Gender;
            Age         = face.Age;
            GlassesType = face.Glasses;

            Hairtype  = GetHairType(face.Hair);
            Haircolor = GetHairColor(face.Hair.HairColor);
            Emotion   = GetFacialExpression(face.Emotion);
        }
Ejemplo n.º 24
0
 public FaceInfo()
 {
     FaceAttributes = new FaceAttributes()
     {
         Gender  = "N/A",
         Glasses = "N/A",
         Smile   = -1,
         Emotion = null
     };
 }
Ejemplo n.º 25
0
 public static string SetGlasses(this FaceAttributes attributes)
 {
     if (attributes.Glasses != "NoGlasses")
     {
         return("HasGlasses");
     }
     else
     {
         return("NoGlasses");
     }
 }
 public bool isApplicable(FaceAttributes faceAttributes)
 {
     if (faceAttributes.Emotion.Happiness > _happinesScore && faceAttributes.Emotion.Sadness < _sadnessScore)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Ejemplo n.º 27
0
 public bool isApplicable(FaceAttributes faceAttributes)
 {
     if (faceAttributes.Emotion.Anger > _angerScore)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
 public bool isApplicable(FaceAttributes faceAttributes)
 {
     if (faceAttributes.Emotion.Happiness < 0.2f && faceAttributes.Emotion.Sadness > 0.4f)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Ejemplo n.º 29
0
 public bool isApplicable(FaceAttributes faceAttributes)
 {
     if (faceAttributes.Emotion.Surprise > _supriseScore)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Ejemplo n.º 30
0
 public FaceFormatter(Face face)
 {
     attributes = face.FaceAttributes;
     age        = attributes.Age;
     gender     = attributes.Gender;
     smile      = attributes.Smile;
     facialHair = attributes.FacialHair;
     headPose   = attributes.HeadPose;
     glasses    = attributes.Glasses;
     pos        = face.FaceRectangle.Left + face.FaceRectangle.Width / 2;
 }