// *** CONSTRUCTOR *** /// <summary> /// Initializes a new instance of the SelectionChangedEventArgs class /// </summary> /// <param name="cubePos">Position of the parent cube</param> /// <param name="facePos">Position of the face</param> public SelectionChangedEventArgs(CubeFlag cubePos, FacePosition facePos) { this.Position = new PositionSpec() { CubePosition = cubePos, FacePosition = facePos }; }
/// <summary> /// Returns a FacePosition which is the opposite of the parameter /// </summary> /// <param name="flag">Defines the parameter to be analyzed</param> /// <returns></returns> public static FacePosition GetOppositeFace(FacePosition position) { switch (position) { case FacePosition.Top: return(FacePosition.Bottom); case FacePosition.Bottom: return(FacePosition.Top); case FacePosition.Left: return(FacePosition.Right); case FacePosition.Right: return(FacePosition.Left); case FacePosition.Back: return(FacePosition.Front); case FacePosition.Front: return(FacePosition.Back); default: return(FacePosition.None); } }
// *** CONSTRUCTOR *** /// <summary> /// Initializes a new instance of the Face3D class /// </summary> /// <param name="vertices">Vertices of the 3D face</param> /// <param name="color">Color</param> /// <param name="position">Position</param> /// <param name="masterPosition">Position of the parent 3D cube</param> public Face3D(IEnumerable<Point3D> vertices, Color color, FacePosition position, CubeFlag masterPosition) { this.Vertices = vertices; this.Color = color; this.Position = position; this.MasterPosition = masterPosition; }
/// <summary> /// Converts a FacePosition into a CubeFlag /// </summary> /// <param name="facePos">Defines the FacePostion to be converted</param> /// <returns></returns> public static CubeFlag FromFacePosition(FacePosition facePos) { switch (facePos) { case FacePosition.Top: return(CubeFlag.TopLayer); case FacePosition.Bottom: return(CubeFlag.BottomLayer); case FacePosition.Left: return(CubeFlag.LeftSlice); case FacePosition.Right: return(CubeFlag.RightSlice); case FacePosition.Back: return(CubeFlag.BackSlice); case FacePosition.Front: return(CubeFlag.FrontSlice); default: return(CubeFlag.None); } }
static void Main(string[] args) { // Creating a filter WatsonFilter myFilter = new WatsonFilter(); // Open the bitmap Bitmap fileToAnalize = new Bitmap("path to file. Can be bmp or jpg"); // Analyze Dictionary <int, Dictionary <string, object> > resultadoRostros = myFilter.FindFaces(fileToAnalize); Dictionary <int, Dictionary <string, double> > resultadoClasificacion = myFilter.FindClassifiers(fileToAnalize); // pair.Key are the classes detected by watson and pair.Value are their score foreach (Dictionary <string, double> dic in resultadoClasificacion.Values) { foreach (KeyValuePair <string, double> pair in dic) { Console.WriteLine($"{pair.Key}: {pair.Value}"); } } // same as before, but accessing through objects foreach (Dictionary <string, object> dic in resultadoRostros.Values) { Age edad = (Age)dic["age"]; Gender genero = (Gender)dic["gender"]; FacePosition posicion = (FacePosition)dic["position"]; Console.WriteLine($"{edad.MinAge}, {edad.MaxAge}, {edad.ScoreAge}; {genero.GenderType}, {genero.GenderScore}; {posicion.Top}, {posicion.Left}, {posicion.Width}, {posicion.Height}"); } Console.ReadKey(); }
// *** CONSTRUCTOR *** /// <summary> /// Initializes a new instance of the Face3D class /// </summary> /// <param name="vertices">Vertices of the 3D face</param> /// <param name="color">Color</param> /// <param name="position">Position</param> /// <param name="masterPosition">Position of the parent 3D cube</param> public Face3D(IEnumerable <Point3D> vertices, Color color, FacePosition position, CubeFlag masterPosition) { this.Vertices = vertices; this.Color = color; this.Position = position; this.MasterPosition = masterPosition; }
public static Cube3D.RubikPosition layerAssocToFace(FacePosition Position) { if (Position == FacePosition.Top) { return(Cube3D.RubikPosition.TopLayer); } if (Position == FacePosition.Bottom) { return(Cube3D.RubikPosition.BottomLayer); } if (Position == FacePosition.Left) { return(Cube3D.RubikPosition.LeftSlice); } if (Position == FacePosition.Right) { return(Cube3D.RubikPosition.RightSlice); } if (Position == FacePosition.Front) { return(Cube3D.RubikPosition.FrontSlice); } if (Position == FacePosition.Back) { return(Cube3D.RubikPosition.BackSlice); } return(Cube3D.RubikPosition.None); }
protected void RotateLayer(Cube cube, RotationSense rotationSense, PickType pickType, int index) { FacePosition currentFacePosition = FacePosition.Front; FacePosition nextFacePosition = currentFacePosition.Rotate(rotationSense, pickType); Face curFaceF = cube.GetFaceByPosition(currentFacePosition); Face curFaceU = cube.GetFaceByPosition(nextFacePosition); List <Color> oldColors = curFaceU.GetPiecesColorRange(pickType, index); List <Color> newColors = curFaceF.GetPiecesColorRange(pickType, index); FacePosition endPosition = GetEndingRotation(rotationSense, pickType); do { curFaceU.ChangeColorRange(pickType, index, newColors); newColors.Clear(); newColors.AddRange(oldColors); currentFacePosition = nextFacePosition; nextFacePosition = nextFacePosition.Rotate(rotationSense, pickType); curFaceF = cube.GetFaceByPosition(currentFacePosition); curFaceU = cube.GetFaceByPosition(nextFacePosition); oldColors.Clear(); oldColors.AddRange(curFaceU.GetPiecesColorRange(pickType, index)); } while (nextFacePosition != endPosition); }
public Face3D(IEnumerable <Point3D> edges, Color color, FacePosition position, Cube3D.RubikPosition masterPosition, SelectionMode selection) { Edges = edges; Color = color; Position = position; MasterPosition = masterPosition; Selection = selection; }
public Face(byte[] face_template, FSDK.TFacePosition face_pos, FSDK.TPoint[] facial_features, FSDK.CImage face_image) { this.face_template = face_template; this.face_position = FacePosition.FromFSDK(face_pos); this.facial_features = facial_features; this.image = face_image; this.face_image = face_image; }
public async Task <ActionResult> DeleteConfirmed(int id) { FacePosition facePosition = await db.FacePosition.FindAsync(id); db.FacePosition.Remove(facePosition); await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <ActionResult> Edit([Bind(Include = "FacePositionID,Position")] FacePosition facePosition) { if (ModelState.IsValid) { db.Entry(facePosition).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(facePosition)); }
public async Task <ActionResult> Create([Bind(Include = "FacePositionID,Position")] FacePosition facePosition) { if (ModelState.IsValid) { db.FacePosition.Add(facePosition); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(facePosition)); }
public static FacePosition Rotate(this FacePosition face, RotationSense rotationSense, PickType pickType) { switch (rotationSense) { case RotationSense.Clockwise: return(RotateClockwise(face, pickType)); case RotationSense.Counterclockwise: return(RotateAnticlockwise(face, pickType)); default: return(face); } }
// GET: FacePositions/Details/5 public async Task <ActionResult> Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } FacePosition facePosition = await db.FacePosition.FindAsync(id); if (facePosition == null) { return(HttpNotFound()); } return(View(facePosition)); }
public static FacePosition RotateAnticlockwise(this FacePosition face, PickType pickType) { if (pickType == PickType.Vertical) { switch (face) { case FacePosition.Front: return(FacePosition.Down); case FacePosition.Up: return(FacePosition.Front); case FacePosition.Down: return(FacePosition.Back); case FacePosition.Back: return(FacePosition.Up); case FacePosition.Right: case FacePosition.Left: default: return(face); } } else if (pickType == PickType.Horizontal) { switch (face) { case FacePosition.Left: return(FacePosition.Front); case FacePosition.Front: return(FacePosition.Right); case FacePosition.Right: return(FacePosition.Back); case FacePosition.Back: return(FacePosition.Left); case FacePosition.Up: case FacePosition.Down: default: return(face); } } return(face); }
public void Initialize(int size, Color color, FacePosition position) { Position = position; Pieces = new Piece[size, size]; int index = 1; for (var i = 0; i < size; i++) { for (var j = 0; j < size; j++) { Pieces[i, j] = new Piece(color, i, j); index++; } } }
private bool EnrollFace(Face a_face) { //ASSUMING THAT FACES ARE VERTICAL (HANDLEARBITRARYROTATIONS IS FALSE) TO SPEED UP FACE DETECTION FSDK.SetFaceDetectionParameters(false, true, 384); FSDK.SetFaceDetectionThreshold((int)FaceDetectionThreshold); //GET POSITION OF FACE IN IMAGE a_face.face_position = FacePosition.FromFSDK(a_face.Clone().image.DetectFace()); a_face.face_image = a_face.Clone().image.CopyRect((int)(a_face.face_position.xc - Math.Round(a_face.face_position.w * 0.5)), (int)(a_face.face_position.yc - Math.Round(a_face.face_position.w * 0.5)), (int)(a_face.face_position.xc + Math.Round(a_face.face_position.w * 0.5)), (int)(a_face.face_position.yc + Math.Round(a_face.face_position.w * 0.5))); //GET THE FACIAL FEATURES OF THE FACE FSDK.TFacePosition face_pos = a_face.face_position; a_face.facial_features = a_face.Clone().image.DetectEyesInRegion(ref face_pos); //GET A TEMPLATE OF THE FACE TO BE USED FOR LATER COMPARISON a_face.face_template = a_face.Clone().image.GetFaceTemplateInRegion(ref face_pos); known_faces_list.Add(a_face); return(true); }
/// <summary> /// Constructor with color and position /// </summary> /// <param name="color">Defines the color of this face</param> /// <param name="position">Defines the position of this face</param> public Face(Color color, FacePosition position) { this.Color = color; this.Position = position; }
private void CreateWMOMesh() { loadingWindow.Close(); loadingWindow = null; if (loadedFile == null) { return; } Log.Write("CreateWMOMesh: Created new meshes from WMO data..."); texManager.clear(); // Clear any existing textures from the GL. meshes.Clear(); // Clear existing meshes. UI_MeshList.Items.Clear(); // Load all textures into the texture manager. Chunk_MOTX texChunk = (Chunk_MOTX)loadedFile.getChunk(Chunk_MOTX.Magic); foreach (KeyValuePair <int, string> tex in texChunk.textures.raw()) { texManager.addTexture(tex.Key, Path.Combine(Constants.TEMP_DIRECTORY, tex.Value)); } Chunk_MOGN nameChunk = (Chunk_MOGN)loadedFile.getChunk(Chunk_MOGN.Magic); // Material register. Chunk_MOMT matChunk = (Chunk_MOMT)loadedFile.getChunk(Chunk_MOMT.Magic); foreach (Chunk_Base rawChunk in loadedFile.getChunksByID(Chunk_MOGP.Magic)) { Chunk_MOGP chunk = (Chunk_MOGP)rawChunk; string meshName = nameChunk.data.get((int)chunk.groupNameIndex); // Skip antiportals. if (meshName.ToLower().Equals("antiportal")) { continue; } Mesh mesh = new Mesh(meshName); // Populate mesh with vertices. Chunk_MOVT vertChunk = (Chunk_MOVT)chunk.getChunk(Chunk_MOVT.Magic); foreach (Position vertPos in vertChunk.vertices) { mesh.addVert(vertPos); } // Populate mesh with UVs. Chunk_MOTV uvChunk = (Chunk_MOTV)chunk.getChunk(Chunk_MOTV.Magic); foreach (UV uv in uvChunk.uvData) { mesh.addUV(uv); } // Populate mesh with normals. Chunk_MONR normChunk = (Chunk_MONR)chunk.getChunk(Chunk_MONR.Magic); foreach (Position norm in normChunk.normals) { mesh.addNormal(norm); } // Populate mesh with triangles (faces). Chunk_MOVI faceChunk = (Chunk_MOVI)chunk.getChunk(Chunk_MOVI.Magic); Chunk_MOPY faceMatChunk = (Chunk_MOPY)chunk.getChunk(Chunk_MOPY.Magic); for (int i = 0; i < faceChunk.positions.Length; i++) { FacePosition position = faceChunk.positions[i]; FaceInfo info = faceMatChunk.faceInfo[i]; if (info.materialID != 0xFF) // 0xFF (255) identifies a collision face. { Material mat = matChunk.materials[info.materialID]; uint texID = texManager.getTexture((int)mat.texture1.offset); mesh.addFace(texID, mat.texture2.colour, position.point1, position.point2, position.point3); } } Log.Write("CreateWMOMesh: " + mesh.ToAdvancedString()); meshes.Add(mesh); UI_MeshList.Items.Add(mesh); } for (int i = 0; i < UI_MeshList.Items.Count; i++) { UI_MeshList.SetItemChecked(i, true); } // Reset 3D autoRotate = true; rotationY = 0f; //rotationZ = 0f; zoom = 1f; }
/// <summary> /// Changes the color of the given face of this cube /// </summary> /// <param name="face">Defines the face to be changed</param> /// <param name="color">Defines the color to be set</param> public void SetFaceColor(FacePosition face, Color color) { this.Faces.Where(f => f.Position == face).ToList().ForEach(f => f.Color = color); this.Colors.Clear(); this.Faces.ToList().ForEach(f => Colors.Add(f.Color)); }
/// <summary> /// Returns the color of the face of the first cube with the given CubeFlag /// </summary> /// <param name="position">Defines the CubeFlag which filters this cubes</param> /// <param name="face">Defines the face to be analyzed</param> /// <returns></returns> public Color GetFaceColor(CubeFlag position, FacePosition face) => this.Cubes.First(c => c.Position.Flags == position).GetFaceColor(face);
/// <summary> /// Returns a FacePosition which is the opposite of the parameter /// </summary> /// <param name="flag">Defines the parameter to be analyzed</param> /// <returns></returns> public static FacePosition GetOppositeFace(FacePosition position) { switch (position) { case FacePosition.Top: return FacePosition.Bottom; case FacePosition.Bottom: return FacePosition.Top; case FacePosition.Left: return FacePosition.Right; case FacePosition.Right: return FacePosition.Left; case FacePosition.Back: return FacePosition.Front; case FacePosition.Front: return FacePosition.Back; default: return FacePosition.None; } }
// **** METHODS **** public static Rubik FromPattern(Pattern pattern) { Rubik rubik = new Rubik(); foreach (PatternItem item in pattern.Items) { if (CubePosition.IsCorner(item.CurrentPosition.Flags)) { bool xyzCorrect = !((item.CurrentPosition.Y == CubeFlag.TopLayer ^ (item.CurrentPosition.X == CubeFlag.RightSlice ^ item.CurrentPosition.Z == CubeFlag.FrontSlice)) ^ (CubeFlagService.FirstYFlag(item.TargetPosition) == CubeFlag.TopLayer ^ (CubeFlagService.FirstXFlag(item.TargetPosition) == CubeFlag.RightSlice ^ CubeFlagService.FirstZFlag(item.TargetPosition) == CubeFlag.FrontSlice))); if (item.CurrentOrientation == Orientation.Correct) { rubik.SetFaceColor(item.CurrentPosition.Flags, CubeFlagService.ToFacePosition(item.CurrentPosition.Y), rubik.GetSliceColor(CubeFlagService.FirstYFlag(item.TargetPosition))); FacePosition x = xyzCorrect ? CubeFlagService.ToFacePosition(item.CurrentPosition.X) : CubeFlagService.ToFacePosition(item.CurrentPosition.Z); FacePosition z = xyzCorrect ? CubeFlagService.ToFacePosition(item.CurrentPosition.Z) : CubeFlagService.ToFacePosition(item.CurrentPosition.X); rubik.SetFaceColor(item.CurrentPosition.Flags, x, rubik.GetSliceColor(CubeFlagService.FirstXFlag(item.TargetPosition))); rubik.SetFaceColor(item.CurrentPosition.Flags, z, rubik.GetSliceColor(CubeFlagService.FirstZFlag(item.TargetPosition))); } else { bool corr = (item.CurrentPosition.X == CubeFlag.RightSlice ^ item.CurrentPosition.Z == CubeFlag.BackSlice) ^ item.CurrentPosition.Y == CubeFlag.BottomLayer; FacePosition x = (corr ^ item.CurrentOrientation == Orientation.Clockwise) ? CubeFlagService.ToFacePosition(item.CurrentPosition.X) : CubeFlagService.ToFacePosition(item.CurrentPosition.Y); FacePosition y = (corr ^ item.CurrentOrientation == Orientation.Clockwise) ? CubeFlagService.ToFacePosition(item.CurrentPosition.Z) : CubeFlagService.ToFacePosition(item.CurrentPosition.X); FacePosition z = (corr ^ item.CurrentOrientation == Orientation.Clockwise) ? CubeFlagService.ToFacePosition(item.CurrentPosition.Y) : CubeFlagService.ToFacePosition(item.CurrentPosition.Z); rubik.SetFaceColor(item.CurrentPosition.Flags, x, rubik.GetSliceColor(CubeFlagService.FirstXFlag(item.TargetPosition))); rubik.SetFaceColor(item.CurrentPosition.Flags, y, rubik.GetSliceColor(CubeFlagService.FirstYFlag(item.TargetPosition))); rubik.SetFaceColor(item.CurrentPosition.Flags, z, rubik.GetSliceColor(CubeFlagService.FirstZFlag(item.TargetPosition))); } } if (CubePosition.IsEdge(item.CurrentPosition.Flags)) { CubeFlag flagOne = CubeFlagService.FirstNotInvalidFlag(item.CurrentPosition.Flags, CubeFlag.MiddleLayer | CubeFlag.MiddleSlice | CubeFlag.MiddleSliceSides); FacePosition faceOne = CubeFlagService.ToFacePosition(flagOne); FacePosition faceTwo = CubeFlagService.ToFacePosition(CubeFlagService.FirstNotInvalidFlag(item.CurrentPosition.Flags, CubeFlag.MiddleLayer | CubeFlag.MiddleSlice | CubeFlag.MiddleSliceSides | flagOne)); CubeFlag tFlagOne = CubeFlagService.FirstNotInvalidFlag(item.TargetPosition, CubeFlag.MiddleLayer | CubeFlag.MiddleSlice | CubeFlag.MiddleSliceSides); rubik.SetFaceColor(item.CurrentPosition.Flags, faceOne, rubik.GetSliceColor(tFlagOne)); rubik.SetFaceColor(item.CurrentPosition.Flags, faceTwo, rubik.GetSliceColor(CubeFlagService.FirstNotInvalidFlag(item.TargetPosition, CubeFlag.MiddleLayer | CubeFlag.MiddleSlice | CubeFlag.MiddleSliceSides | tFlagOne))); if (Solvability.GetOrientation(rubik, rubik.Cubes.First(c => c.Position.Flags == item.CurrentPosition.Flags)) != item.CurrentOrientation) { rubik.SetFaceColor(item.CurrentPosition.Flags, faceTwo, rubik.GetSliceColor(tFlagOne)); rubik.SetFaceColor(item.CurrentPosition.Flags, faceOne, rubik.GetSliceColor(CubeFlagService.FirstNotInvalidFlag(item.TargetPosition, CubeFlag.MiddleLayer | CubeFlag.MiddleSlice | CubeFlag.MiddleSliceSides | tFlagOne))); } } if (CubePosition.IsCenter(item.CurrentPosition.Flags)) { CubeFlag flag = CubeFlagService.FirstNotInvalidFlag(item.CurrentPosition.Flags, CubeFlag.MiddleLayer | CubeFlag.MiddleSlice | CubeFlag.MiddleSliceSides); CubeFlag tFlag = CubeFlagService.FirstNotInvalidFlag(item.TargetPosition, CubeFlag.MiddleLayer | CubeFlag.MiddleSlice | CubeFlag.MiddleSliceSides); rubik.SetFaceColor(item.CurrentPosition.Flags, CubeFlagService.ToFacePosition(flag), rubik.GetSliceColor(tFlag)); } } return(rubik); }
/// <summary> /// Returns the color of the face of the first cube with the given CubeFlag /// </summary> /// <param name="position">Defines the CubeFlag which filters this cubes</param> /// <param name="face">Defines the face to be analyzed</param> /// <returns></returns> public Color GetFaceColor(CubeFlag position, FacePosition face) { return(Cubes.First(c => c.Position.Flags == position).GetFaceColor(face)); }
public Face(Color color, int size, FacePosition position) { Size = size; Initialize(size, color, position); }
/// <summary> /// Returns the color of the given face /// </summary> /// <param name="face">Defines the face to be analyzed</param> /// <returns></returns> public Color GetFaceColor(FacePosition face) { return(this.Faces.First(f => f.Position == face).Color); }
public Face3D(IEnumerable <Point3D> vertices, Color color, FacePosition position, List <LayerType> layerType) : base(vertices, color) { Position = position; Positions = layerType; }
public Face GetFaceByPosition(FacePosition position) { return(Faces.First(f => f.Position == position)); }
// *** CONSTRUCTOR *** /// <summary> /// Initializes a new instance of the SelectionChangedEventArgs class /// </summary> /// <param name="cubePos">Position of the parent cube</param> /// <param name="facePos">Position of the face</param> public SelectionChangedEventArgs(CubeFlag cubePos, FacePosition facePos) { this.Position = new PositionSpec { CubePosition = cubePos, FacePosition = facePos }; }
/// <summary> /// Returns the color of the face of the first cube with the given CubeFlag /// </summary> /// <param name="position">Defines the CubeFlag which filters this cubes</param> /// <param name="face">Defines the face to be analyzed</param> /// <returns></returns> public Color GetFaceColor(CubeFlag position, FacePosition face) { return Cubes.First(c => c.Position.Flags == position).GetFaceColor(face); }
/// <summary> /// Sets the facecolor of the given cubes and faces with the given color /// </summary> /// <param name="affected">Defines the cubes to be changed</param> /// <param name="face">Defines the face of the cubes to be changed</param> /// <param name="color">Defines the color to be set</param> public void SetFaceColor(CubeFlag affected, FacePosition face, Color color) { Cubes.Where(c => c.Position.HasFlag(affected)).ToList().ForEach(c => c.SetFaceColor(face, color)); Cubes.ToList().ForEach(c => { c.Colors.Clear(); c.Faces.ToList().ForEach(f => c.Colors.Add(f.Color)); }); }
/// <summary> /// Converts a FacePosition into a CubeFlag /// </summary> /// <param name="facePos">Defines the FacePostion to be converted</param> /// <returns></returns> public static CubeFlag FromFacePosition(FacePosition facePos) { switch (facePos) { case FacePosition.Top: return CubeFlag.TopLayer; case FacePosition.Bottom: return CubeFlag.BottomLayer; case FacePosition.Left: return CubeFlag.LeftSlice; case FacePosition.Right: return CubeFlag.RightSlice; case FacePosition.Back: return CubeFlag.BackSlice; case FacePosition.Front: return CubeFlag.FrontSlice; default: return CubeFlag.None; } }
public FaceRecognitionResult MatchFace(Image <Bgr, byte> a_face) { try { if (a_face == null) { throw new ArgumentNullException(); } //CREATE A FACE OBJECT Face unknown_face = new Face(); unknown_face.face_position = new FacePosition(); unknown_face.facial_features = new FSDK.TPoint[FSDK.FSDK_FACIAL_FEATURE_COUNT]; unknown_face.face_template = new byte[FSDK.TemplateSize]; unknown_face.image = new FSDK.CImage(a_face.ToBitmap()); //GET THE POSITION OF THE FACE IN THE IAGE unknown_face.face_position = FacePosition.FromFSDK(unknown_face.image.DetectFace()); unknown_face.face_image = unknown_face.Clone().image; FSDK.TFacePosition face_pos = unknown_face.face_position.Clone(); //CHECK IF A FACE HAS BEEN DETECTED if (0 == face_pos.w) { face_pos = null; Debug.WriteLine("No Face Found"); return(face_recog_results); } try { FSDK.TFacePosition face_pos_1 = unknown_face.face_position.Clone(); //GET THE FACIAL FEATURES OF THE FACE LIKE EYES NOSE ETC unknown_face.facial_features = unknown_face.Clone().image.DetectEyesInRegion(ref face_pos_1); face_pos_1 = null; } catch (Exception) { } try { FSDK.TFacePosition face_pos_2 = unknown_face.face_position.Clone(); //GET A TEMPLATE OF THE FACE TO BE USED FOR COMPARISON unknown_face.face_template = unknown_face.Clone().image.GetFaceTemplateInRegion(ref face_pos_2); face_pos_2 = null; } catch (Exception) { } //THRESHOLD INDICATING HOW SIMILAR THE TWO FACS MUST BE TO BE CONSIDERED SAME float similarity_threshold = 0.0f; //TO DETERMINE IF THE MATCHED TEMPLATES BELONG TO THE SAME PERSON (WITH A SPECIFIED ERROR POSSIBILITY), //YOU CAN COMPARE THE FACIAL SIMILARITY VALUE WITH A THRESHOLD CALCULATED BY FSDK.GetMatchingThresholdAtFAR(FARValue / 100, ref similarity_threshold); //NUMBER OF MATCHES FOUND int matches_count = 0; //COUNT OF ALL FACES ENROLLED int faces_count = known_faces_list.Count; //HOLDS A FLOAT INDICATING HOW SIMILAR GIVEN FACE IS TO THAT IN THE SAME INDEX IN THE FACE_LIST float[] similarities = new float[faces_count]; int[] numbers = new int[faces_count]; List <KeyValuePair <Face, float> > face_to_similarity_map = new List <KeyValuePair <Face, float> >(); //LOOP THRU THE KNOWN FACES COMPARING EACH FACE WITH THE UNKNOWN FACE for (int i = 0; i < known_faces_list.Count; i++) { //VALUE INDICATING HOW SIMILAR THE 2 FACES ARE float similarity = 0.0f; //GET THE NEXT FACE IN THE FACE_LIST Face next_face = known_faces_list[i]; //GET TEMPLATES FOR BOTH THE UNKNOWN FACE AND NEXT FACE Byte[] unknown_face_template = unknown_face.face_template; Byte[] known_face_template = next_face.face_template; //COMPARE THE 2 FACES FOR SIMILARITY BETWEEN THEM FSDK.MatchFaces(ref unknown_face_template, ref known_face_template, ref similarity); unknown_face_template = null; known_face_template = null; if (similarity >= similarity_threshold) { similarities[matches_count] = similarity; numbers[matches_count] = i; face_to_similarity_map.Add(new KeyValuePair <Face, float>(next_face, similarity)); ++matches_count; } } //Dispose of Face //SORT THE SIMILARITIES IN DESCENDING ORDER INORDERTO FIND THE MOST SIMILAR FACE FloatsDescendingOrder floats_descending_order = new FloatsDescendingOrder(); Array.Sort(similarities, numbers, 0, matches_count, (IComparer <float>)floats_descending_order); //GET THE PERPETRATOR ASSOCIATED WITH THE FACE face_recog_results = new FaceRecognitionResult(); face_recog_results = GetOfMostSimilarFace(similarities, face_to_similarity_map); face_recog_results.original_detected_face = a_face; face_to_similarity_map = null; //RETURN RESULTS OF FACE RECOGNITION OPERATION return(face_recog_results); } catch (Exception e) { Debug.WriteLine(e.Message); } return(face_recog_results); }
/// <summary> /// Returns the color of the given face /// </summary> /// <param name="face">Defines the face to be analyzed</param> /// <returns></returns> public Color GetFaceColor(FacePosition face) { return this.Faces.First(f => f.Position == face).Color; }