Beispiel #1
0
        static void DeleteEmptyDir(string path)
        {
            var faceRecognition = FaceRecogniser.Build(@"D:\Workspace\FaceRecognition\FaceRecognition\Data\Models");

            var dirs  = Directory.GetDirectories(path);
            var count = dirs.Length;
            int i     = 0;

            foreach (var dir in dirs)
            {
                Console.WriteLine($"Process: {i}/{count} {dir}");
                i++;
                var files = Directory.GetFiles(dir);
                if (files.Length == 0)
                {
                    Directory.Delete(dir);
                }
                //foreach(var file in files)
                //{
                //    var bytes = File.ReadAllBytes(file);
                //    if (faceRecognition.HasFaces(bytes))
                //    {
                //        File.Delete(file);
                //    }
                //}
            }
        }
Beispiel #2
0
        static void PrepareLabelAndFeat(string path, string featSavePath, string labelSavePath)
        {
            var faceRecognition = FaceRecogniser.Build(@"D:\Workspace\FaceRecognition\FaceRecognition\Data\Models");

            var files = Directory.GetFiles(path);

            var count = files.Length;
            var i     = 0;

            foreach (var file in files)
            {
                Console.WriteLine($"Get feature {i}/{count}: file");
                i++;
                var tmps = faceRecognition.GetFaceEncodings(File.ReadAllBytes(file));
                if (tmps == null || tmps.Count == 0)
                {
                    continue;
                }
                var feat = tmps[0];
                labels.Add(file);
                feats.Add(feat);
            }

            BinaryFormatter formatter     = new BinaryFormatter();
            MemoryStream    vectorsStream = new MemoryStream();

            formatter.Serialize(vectorsStream, feats);
            File.WriteAllBytes(featSavePath, vectorsStream.ToArray());

            File.WriteAllLines(labelSavePath, labels);
        }
        private void Init()
        {
            m_faceRecogniser = FaceRecogniser.Build(ServiceOption.ModelPath);
            m_logger.LogInformation($"Init face recogniser success");

            m_index = MemIndex.Create(ServiceOption.FeaturePath);
            m_logger.LogInformation($"Init index success");

            m_faceInfo = LevelFaceInfo.Create(ServiceOption.DBName);
            m_logger.LogInformation($"Init faceInfo database success");
        }
Beispiel #4
0
 public TransfromsAboveZ(
     FaceRecogniser p,
     string name,
     Collider c,
     Transform[] transforms,
     float score,
     bool above = true
     ) : base(p)
 {
     _collider   = c;
     _name       = name;
     _transfroms = transforms;
     _above      = above;
 }
Beispiel #5
0
        static void DeleteMoreThan1(string path)
        {
            var faceRecognition = FaceRecogniser.Build(@"D:\Workspace\FaceRecognition\FaceRecognition\Data\Models");

            var files = Directory.GetFiles(path);

            foreach (var file in files)
            {
                var bytes = File.ReadAllBytes(file);
                if (faceRecognition.HasFaces(bytes))
                {
                    File.Delete(file);
                }
            }
        }
    // Start is called before the first frame update
    void Start()
    {
        if (playerLife == null)
        {
            playerLife = GameObject.FindGameObjectWithTag(CustomTags.Player).GetComponent <LifeAmount>();
        }

        if (gameTimeCountDown == null)
        {
            gameTimeCountDown = GetComponent <GameCountDown>();
        }

        if (faceRecogniser == null)
        {
            faceRecogniser = GetComponent <FaceRecogniser>();
        }

        if (score == null)
        {
            score = GetComponent <Score>();
        }

        if (distance == null)
        {
            distance = GetComponent <Distance>();
        }

        if (backgroundVideo == null)
        {
            backgroundVideo = GameObject.FindGameObjectWithTag(CustomTags.Background).GetComponent <VideoPlayer>();
            Debug.Assert(backgroundVideo != null);
        }

        if (dude == null)
        {
            dude = GameObject.FindGameObjectWithTag(CustomTags.Dude);
        }

        _countDownObvs = new GameCountDownObvs(this);
        _lifeObvs      = new LifeObvs(this);
        playerLife.Subject.AddObvs(_lifeObvs);
        gameTimeCountDown.Subject.AddObvs(_countDownObvs);

        _speed = 0.5f;
    }
Beispiel #7
0
 public EyeDistance(FaceRecogniser p) : base(p)
 {
 }
Beispiel #8
0
 public FaceFeature(FaceRecogniser parent)
 {
     Parent = parent;
 }
Beispiel #9
0
        static void Test(string path, string savePath)
        {
            LoadLabelAndFeat(@"D:\Workspace\FaceRecognition\Images/feat.bin", @"D:\Workspace\FaceRecognition\Images/labels.txt");

            var faceRecognition = FaceRecogniser.Build(@"D:\Workspace\FaceRecognition\FaceRecognition\Data\Models");

            var dirs = Directory.GetDirectories(path);

            int i        = 0;
            int dirCount = dirs.Length;
            int iPro     = 0;

            foreach (var dir in dirs)
            {
                Console.WriteLine($"Process dir {iPro}/{dirCount} {dir}");
                iPro++;
                var files = Directory.GetFiles(dir);
                Console.WriteLine($"Has file: {files.Length}");
                foreach (var file in files)
                {
                    var tmps = faceRecognition.GetFaceEncodings(File.ReadAllBytes(file));
                    if (tmps == null || tmps.Count == 0)
                    {
                        continue;
                    }
                    var feat         = tmps[0];
                    var searchResult = feats
                                       .Zip(Enumerable.Range(0, feats.Count))
                                       .AsParallel()
                                       .Select(item =>
                    {
                        var dis = Distance.Euclidean(feat, item.First);
                        return(new
                        {
                            Index = item.Second,
                            Dis = dis
                        });
                    })
                                       .OrderBy(item => item.Dis)
                                       .Take(20)
                                       .ToList();
                    var dstPath = Path.Join(savePath, $"{i}");
                    Directory.CreateDirectory(dstPath);
                    i++;
                    var targetFileName = Path.GetFileName(file);
                    var targetPath     = Path.Join(dstPath, $"00_{targetFileName}");
                    File.Copy(file, targetPath);
                    int m = 0;
                    foreach (var search in searchResult)
                    {
                        var    dstFile     = labels[search.Index];
                        var    dstFileName = Path.GetFileName(dstFile);
                        var    dis         = search.Dis;
                        string tmpFileName = "";
                        if (dis <= 0.3)
                        {
                            tmpFileName = $"11_{m}_{dis}_{dstFileName}";
                        }
                        else
                        {
                            tmpFileName = $"22_{m}_{dis}_{dstFileName}";
                        }
                        m++;
                        var tmpPath = Path.Join(dstPath, tmpFileName);
                        File.Copy(dstFile, tmpPath);
                    }
                }
            }
        }