private void SearchFileContents(FileInfo file) { int lineNumber = 0; MatchResult match = null; using (Stream stream = file.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { using (var reader = new StreamReader(stream, Encoding.UTF8)) { do { lineNumber++; string textLine = reader.ReadLine(); if (string.IsNullOrEmpty(textLine)) { break; } if (textLine.Contains(SearchSpec.SearchText)) { match = new MatchResult(file) { Index = MatchResults.Count }; MatchResults.Add(match); OnFileHit(file, match.Index); } }while (true); } } }
private List <FaceMatch> SearchCollectionForSourceImageFaces() { List <FaceMatch> result = new List <FaceMatch>(); Console.WriteLine("Searching target collection for matching source faces..."); foreach (var entry in DataSet.SourceImages) { Console.WriteLine("Attempting to match image {0}.", entry.Key); MemoryStream stream = new MemoryStream(); entry.Value.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg); Image requestImage = new Image() { Bytes = stream }; SearchFacesByImageRequest request = new SearchFacesByImageRequest() { Image = requestImage, CollectionId = CollectionName }; var watch = Stopwatch.StartNew(); SearchFacesByImageResponse response = Client.SearchFacesByImage(request); watch.Stop(); TimingResults.Add(new TimingModel("SearchCollectionForSourceImageFaces", entry.Key, watch.ElapsedMilliseconds)); MatchResults.Add(response); if (response.FaceMatches.Count > 0) { Console.WriteLine("Matching target face found for {0} with a confidence level of {1}.", entry.Key, response.SearchedFaceConfidence); } else { Console.WriteLine("No matching target face found for {0}.", entry.Key); } result.AddRange(response.FaceMatches); } Console.WriteLine("{0} out of {1} faces successfully matched.", result.Count, DataSet.SourceImages.Count); return(result); }