This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// build features and labels | |
var features = NetUtil.Var(new int[] { 7 }, DataType.Float); | |
var labels = NetUtil.Var(new int[] { 1 }, DataType.Float); | |
// the rest of the code goes here... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// file paths | |
private const string inputFilePath = "./pillow.jpg"; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// export the modified image | |
Dlib.SaveJpeg(img, "output.jpg"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// create a color palette for plotting | |
var palette = new RgbPixel[] | |
{ | |
new RgbPixel(0xe6, 0x19, 0x4b), | |
new RgbPixel(0xf5, 0x82, 0x31), | |
new RgbPixel(0xff, 0xe1, 0x19), | |
new RgbPixel(0xbc, 0xf6, 0x0c), | |
new RgbPixel(0x3c, 0xb4, 0x4b), | |
new RgbPixel(0x46, 0xf0, 0xf0), | |
new RgbPixel(0x43, 0x63, 0xd8), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// use the chinese whispers algorithm to find all face clusters | |
Dlib.ChineseWhispers(edges, 100, out var clusters, out var labels); | |
Console.WriteLine($" Found {clusters} unique person(s) in the image"); | |
// the rest of the code goes here... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// compare each face with all other faces | |
var edges = new List<SamplePair>(); | |
for (uint i = 0; i < descriptors.Count; ++i) | |
for (var j = i; j < descriptors.Count; ++j) | |
// record every pair of two similar faces | |
// faces are similar if they are less than 0.6 apart in the 128D embedding space | |
if (Dlib.Length(descriptors[i] - descriptors[j]) < 0.6) | |
edges.Add(new SamplePair(i, j)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// compare each face with all other faces | |
var edges = new List<SamplePair>(); | |
for (uint i = 0; i < descriptors.Count; ++i) | |
for (var j = i; j < descriptors.Count; ++j) | |
// record every pair of two similar faces | |
// faces are similar if they are less than 0.6 apart in the 128D embedding space | |
if (Dlib.Length(descriptors[i] - descriptors[j]) < 0.6) | |
edges.Add(new SamplePair(i, j)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// put each fae in a 128D embedding space | |
// similar faces will be placed close together | |
Console.WriteLine("Recognizing faces..."); | |
var descriptors = dnn.Operator(chips); | |
// the rest of the code goes here... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// detect all faces | |
var chips = new List<Matrix<RgbPixel>>(); | |
var faces = new List<Rectangle>(); | |
Console.WriteLine("Detecting faces..."); | |
foreach (var face in detector.Operator(img)) | |
{ | |
// detect landmarks | |
var shape = predictor.Detect(img, face); | |
// extract normalized and rotated 150x150 face chip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using System; | |
using DlibDotNet; | |
namespace FaceClustering | |
{ | |
/// <summary> | |
/// The program class. | |
/// </summary> | |
class Program |
NewerOlder