public void ProcessImageInteractive(string path) { using (var image = new Mat(path)) { var preProcessedImage = image.Clone().CvtColor(ColorConversionCodes.BGR2GRAY); try { var states = new List <dynamic>(); foreach (var preprocessor in _preProcessors) { states.Add(preprocessor.PreProcessImage(ref preProcessedImage, image)); } var contourResults = new List <ContourResult>(); foreach (var boundaryDetector in _contourDetectors) { contourResults.AddRange(boundaryDetector.DetectDocumentContours(preProcessedImage, image)); } for (var i = 0; i < _preProcessors.Length; i++) { foreach (var contourResult in contourResults) { _preProcessors[i].CorrectContours(contourResult, states[i]); } } //foreach (var contourResult in contourResults) //{ // Cv2.DrawContours(image, new List<IEnumerable<Point>> { contourResult.Points }, -1, Scalar.Pink, 2); //} using (new Window(WindowMode.Normal, preProcessedImage)) { Cv2.WaitKey(); } foreach (var scorer in _scorers) { scorer.Score(contourResults, preProcessedImage, image); } var contour = contourResults.OrderByDescending(_ => _.Score) .FirstOrDefault(); if (contour != null) { Cv2.DrawContours(preProcessedImage, new List <IEnumerable <Point> > { contour.Points }, -1, Scalar.White, 2); using (var resultImage = _extractor.Extract(image, contour.Points)) { using (new Window(WindowMode.Normal, image)) using (new Window(WindowMode.Normal, preProcessedImage)) using (new Window(WindowMode.Normal, resultImage)) { Cv2.WaitKey(); } } } } finally { preProcessedImage.Dispose(); } } }