private async void cmdTrain_ClickAsync(object sender, EventArgs e) { await _options.UpdateMemberVarsFromProperties(); bool internet = _options.Internet; bool containerMode = _options.ContainerMode; string msgType4 = "Internet"; // https://www.fbi.gov/wanted/topten/lamont-stephenson/@@images/image.jpg // https://api.fbi.gov/@wanted // https://api.fbi.gov/@wanted?pageSize=20&page=1&sort_on=modified&sort_order=desc if (!string.IsNullOrWhiteSpace(cmbWebSite.Text)) { if (internet) { string webSiteGroupId = string.Empty; string websiteGroupDisplayName = string.Empty; List <ImageInfo> imagesToTrain = new List <ImageInfo>(); switch (cmbWebSite.Text) { case "FBI Top Ten Most Wanted": webSiteGroupId = FBI_TOP10_GROUP_ID; websiteGroupDisplayName = FBI_TOP10_GROUP_DISPLAY_NAME; imagesToTrain = ScrapeImagesFromFbi("topten"); break; case "FBI Fugitives": webSiteGroupId = FBI_FUGITIVE_GROUP_ID; websiteGroupDisplayName = FBI_FUGITIVE_GROUP_DISPLAY_NAME; imagesToTrain = ScrapeImagesFromFbi("fugitive"); break; case "FBI Most Wanted Terrorist": webSiteGroupId = FBI_TERRORIST_GROUP_ID; websiteGroupDisplayName = FBI_TERRORIST_GROUP_DISPLAY_NAME; imagesToTrain = ScrapeImagesFromFbi("terrorist"); break; } if (MessageBox.Show($@"Are you sure you want to capture the images from '{cmbWebSite.Text}'?", @"Confirmation", MessageBoxButtons.OKCancel) == DialogResult.OK) { await TrainWithImages(imagesToTrain, webSiteGroupId, websiteGroupDisplayName); } } else { if (containerMode) { } else { MessageBox.Show(GenLib.SetMessage(msgType4, string.Empty, string.Empty, null)); } } } }
private async Task UpdatePersonGroupsData() { await _options.UpdateMemberVarsFromProperties(); bool internet = _options.Internet; bool containerMode = _options.ContainerMode; string msgType1 = "PersonGroups"; string msgType2 = "Internet"; await UpdatePersonGroupList(); string groupId = string.Empty; if (!containerMode) { if (internet) { int groupsCount = cmbPersonGroups.Items.Count; if (groupsCount > 1) { string selGroupId = !string.IsNullOrWhiteSpace(cmbPersonGroups.Items[1].ToString()) ? cmbPersonGroups.Items[1].ToString() : string.Empty; groupId = !string.IsNullOrWhiteSpace(cmbPersonGroups.Text) ? cmbPersonGroups.Items.Contains(cmbPersonGroups.Text) ? cmbPersonGroups.Text : selGroupId : selGroupId; } if (!string.IsNullOrWhiteSpace(groupId)) { cmbPersonGroups.Text = groupId; string groupDisplayName = await GetGroupDisplayName(groupId); Color color = await GetColorFromUserData(groupId); txtPersonGroupDisplay.Text = groupDisplayName; cmdSetColor.BackColor = color; } else { cmbPersonGroups.Text = string.Empty; txtPersonGroupDisplay.Text = string.Empty; MessageBox.Show(GenLib.SetMessage(msgType1, string.Empty, string.Empty, null)); } } else // if internet is false { MessageBox.Show(GenLib.SetMessage(msgType2, string.Empty, string.Empty, null)); } } else // If Container mode true { } }
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
public async Task UpdateMemberVarsFromProperties() { // Cognitive Services API's Internet = GenLib.CheckForInternetConnection(); ContainerMode = Properties.Settings.Default.useContainerMode; CSKey = Properties.Settings.Default.cognitiveServicesKey.Trim(); CSEndpoint = Properties.Settings.Default.cognitiveServicesEndpoint.Trim(); FaceEndpoint = $"{CSEndpoint}face/v1.0"; //FaceEndpoint = "https://westus.api.cognitive.microsoft.com/face/v1.0"; VisionEndpoint = $"{CSEndpoint}vision/v1.0"; //VisionEndpoint = "https://westus.api.cognitive.microsoft.com/vision/v1.0"; ContainerEndpoint = "https://localhost:5000"; TextAnalyticsKey = Properties.Settings.Default.textKey; TextAnalyticsEndpoint = Properties.Settings.Default.textEndpoint; TextTransKey = Properties.Settings.Default.translatorKey; TextTransEndpoint = Properties.Settings.Default.translatorEndpoint; // Face API Profiles groupID = Properties.Settings.Default.personGroupID; // API Clients if (!string.IsNullOrWhiteSpace(CSKey) || !string.IsNullOrWhiteSpace(CSEndpoint)) { personGroupFound = false; _faceServiceClient = new FaceServiceClient(CSKey, FaceEndpoint); _visionServiceClient = new VisionServiceClient(CSKey, VisionEndpoint); if (!ContainerMode) { if (Internet) { try { PersonGroup personGroupInfo = await _faceServiceClient.GetPersonGroupAsync(groupID); PersonGroupId = Properties.Settings.Default.personGroupID; PersonGroupName = Properties.Settings.Default.personGroupName; personGroupFound = true; } catch { try { PersonGroup[] personGroups = await _faceServiceClient.ListPersonGroupsAsync(CSKey); PersonGroupId = personGroups[0].PersonGroupId; PersonGroup personGroupInfo = await _faceServiceClient.GetPersonGroupAsync(PersonGroupId); PersonGroupName = personGroupInfo.Name; Properties.Settings.Default.personGroupID = PersonGroupId; Properties.Settings.Default.personGroupName = PersonGroupName; personGroupFound = true; } catch { } } _personGroupDisplayName = !string.IsNullOrWhiteSpace(PersonGroupName) ? PersonGroupName : PersonGroupId; } else { MessageBox.Show(GenLib.SetMessage("Internet", string.Empty, string.Empty, null)); } } } // Camera Information Camoip = Properties.Settings.Default.ipCameraIP; CamoUserName = Properties.Settings.Default.ipCameraUserName; CamoPassword = Properties.Settings.Default.ipCameraPassword; Camoch = Properties.Settings.Default.ipCameraChannels; Camosubch = Properties.Settings.Default.ipCameraSubChannel; Dvrip = Properties.Settings.Default.dvrIP; Dvrch = Properties.Settings.Default.dvrChannels; Dvrsubch = Properties.Settings.Default.dvrSubChannel; DvrUserName = Properties.Settings.Default.dvrUserName; DvrPassword = Properties.Settings.Default.dvrPassword; OtherCamera = Properties.Settings.Default.otherVideoSource; SelCameraNetwork = Properties.Settings.Default.selCameraNetwork; SelCamera = Properties.Settings.Default.selCamera; TimeDelay = Properties.Settings.Default.timeDelay * 1000; }