public void OnLoadImageFormFilePath(string filePath) { detectImageTaskCancellationToken = new CancellationTokenSource(); detectImageTaskCancellationToken.Token.Register(() => { }); var testingProgressMessage = "Розпізнавання в прогресі. Будь ласка, зачекайте... "; this.DetectionInProgress = true; StatusMessageUpdater(testingProgressMessage); Task task = new Task(() => { Image <Bgr, Byte> image = new Image <Bgr, byte>(filePath); this.OriginalImage = image.Resize(1000, 1000, Inter.Cubic, false); var processedImage = LocalImage.ConvertOriginalImageToGrayScaleAndProcess(this.OriginalImage); this.ProcessedImage = processedImage; (ImageType imageType, List <System.Drawing.Rectangle> rectangles) = Detector.DetectCatInImageFile(NeuralNetwork, this.OriginalImage, this.ProcessedImage, (progress) => { StatusMessageUpdater(testingProgressMessage + " Прогрес - " + progress.ToString("0") + "%"); }); if (imageType == ImageType.CAT) { var rectanglesImage = new Image <Bgr, Byte>(OriginalImage.Width, OriginalImage.Height, new Bgr(0, 0, 0)); foreach (var rectangle in rectangles) { rectanglesImage.Draw(rectangle, new Bgr(150, 0, 0), 2); } OriginalImage = OriginalImage.AddWeighted(rectanglesImage, 1, 1, 0); var mainRectangle = AnchorBox.GetBoundingReactange(rectangles); OriginalImage.Draw(mainRectangle, new Bgr(0, 200, 0), 5); OriginalImage.Draw("Cat", new System.Drawing.Point(30, 120), FontFace.HersheyPlain, 8f, new Bgr(0, 200, 0), 10); } else { OriginalImage.Draw("No cat", new System.Drawing.Point(30, 120), FontFace.HersheyPlain, 8f, new Bgr(0, 0, 255), 10); } var temp = this.OriginalImage; this.OriginalImage = null; this.OriginalImage = temp; this.OriginalImage.ROI = System.Drawing.Rectangle.Empty; }); task.Start(); task.ContinueWith((t) => { this.DetectionInProgress = false; StatusMessageUpdater("Готово"); }); }