Beispiel #1
0
        public async Task TagBatchAsync()
        {
            var idService = new IdService();

            var imageService = new ImageService();

            var tagService = new TagService();

            var dir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Images");

            var groupedFiles =
                Directory
                .GetFiles(dir, "*.*", SearchOption.AllDirectories)
                .GroupBy(x => Path.GetFileName(Path.GetDirectoryName(x)));

            foreach (var files in groupedFiles)
            {
                var dirName = files.Key;

                var id = await idService.GetAsync();

                var imagePaths = new List <string>();

                foreach (var imagePath in files)
                {
                    var fileName = Path.GetFileName(imagePath);

                    if (_ignoredFiles.Contains(fileName))
                    {
                        continue;
                    }

                    var faces = await imageService.DetectFaceAsync(imagePath);

                    var biggestFace = faces.OrderByDescending(x => x.Width * x.Height).FirstOrDefault();

                    if (biggestFace == null)
                    {
                        continue;
                    }

                    imagePaths.Add(biggestFace.Path);
                }

                if (imagePaths.Count == 0)
                {
                    continue;
                }

                var socialInfo = new SocialInfo
                {
                    Name = dirName
                };

                await imageService.AddAsync(id, imagePaths, train : false);

                await tagService.AddOrUpdateAsync(id, socialInfo);
            }

            await imageService.TrainAsync();
        }