public static async Task <EnhancedFace[]> DetectFaces(string imageFilePath, FaceServiceClient FaceClient) { MemoryStream imageStream = new MemoryStream(File.ReadAllBytes(imageFilePath)); return(await GenLib.DetectFaces(imageStream, FaceClient)); }
private async Task CategorizeFiles(string nameToFind) { await _options.UpdateMemberVarsFromProperties(); bool internet = _options.Internet; bool containerMode = _options.ContainerMode; string msgType4 = "Internet"; string rootFolder = GenLib.BrowseForFolder(); int numCategorized = 0; int fileNum = 0; string errStr; string CSKey = _options.CSKey; FaceServiceClient faceClient = _options._faceServiceClient; PersonGroup[] personGroups = Array.Empty <PersonGroup>(); personGroups = await GenLib.GetPersonGroups(CSKey, faceClient); if (!string.IsNullOrEmpty(rootFolder)) { if (internet) { // user selected a folder to scan - start scan string[] files = Directory.GetFiles(rootFolder); SetProgressMax(files.Length); foreach (string fn in files) { fileNum++; //Image workImage = fn.Clone(); if (GenLib.FileIsImage(fn)) { // Image needs to be smaller than 4MB // FIX Currently this following method does not convert img to les than 4MB Image readyImage; System.Drawing.Image selImage; selImage = (Bitmap)Image.FromFile(fn); try { Stream imageFileStream = GenLib.ConvertAndCompressImageFileToStream(selImage, _maxImageSize, out errStr); //readyImage = selImage; readyImage = Image.FromStream(imageFileStream); UpdateStatus($"Detecting faces in file '{fn}'..."); EnhancedFace[] detectedFaces = await GenLib.DetectFaces(readyImage, faceClient); if (detectedFaces.Any()) { List <IdentifiedPerson> foundGroupInfo = await GenLib.GetCandidateNames(detectedFaces, personGroups, faceClient, false); List <string> foundNames = foundGroupInfo.Select(g => g.PersonName).ToList <string>(); if (nameToFind == "" || foundNames.Contains(nameToFind, StringComparer.OrdinalIgnoreCase)) { // we found an image with our desired face in it - copy it out to our target dir CopyImageToCategoryDir(fn, nameToFind, foundNames); numCategorized++; } else { LogInfo($"{detectedFaces.Length} faces found but it's not the one we are looking for in '{fn}'"); } } } catch { LogInfo($"Unable to process the image'{fn}'"); } } // file was an image UpdateProgress(fileNum); } // for each file found in user's directory LogInfo($"Done. Categorized {numCategorized}/{files.Length} files from directory '{rootFolder}' OK"); } // if internet else { if (containerMode) { } else { MessageBox.Show(GenLib.SetMessage(msgType4, string.Empty, string.Empty, null)); } } } // user directory was defined } // categorizeFiles