public void TestNumberFinder1() { var circleProcessor = new CircleProcessor(); var circles = circleProcessor.FindCircles(TestImg.test_card_1); var nf = new NumberFinder(); for (int i = 0; i < circles.Size; i++) { var circle = circles[i]; var score = nf.FindNumbers(circle, TestImg.test_card_1); if (i == 0) { Assert.AreEqual(score, 1); } if (i == 1) { Assert.AreEqual(score, 4); } } }
public void TestNumberFinder3() { var circleProcessor = new CircleProcessor(); var circles = circleProcessor.FindCircles(TestImg.test_card_3); var nf = new NumberFinder(); for (int i = 0; i < circles.Size; i++) { var circle = circles[i]; var score = nf.FindNumbers(circle, TestImg.test_card_3); if (i == 0) { Assert.AreEqual(score, 2); } if (i == 1) { //there is some bogus stuff going on here //Assert.AreEqual(score, 2); } } }
private IPlotPOLCNTOutput ProcessFile(string path, CircleProcessor imgProcessor) { if (!File.Exists(path)) { Logging.Logger.LogErrorFormat("File does not exist: {0}", path); return(null); } try { if (path.EndsWith(".zip")) { return(null); } if (path.EndsWith(".gz")) { var fs = new FileStream(path, FileMode.Open); var finfo = new FileInfo(path); var currFile = Path.GetFullPath(path); var newFile = currFile.Remove(currFile.Length - finfo.Extension.Length); using (var newFs = new FileStream(newFile, FileMode.OpenOrCreate)) using (var stream = new System.IO.Compression.GZipStream(fs, System.IO.Compression.CompressionMode.Decompress)) { stream.CopyTo(newFs); Logging.Logger.LogInfoFormat("Decompressed {0} to {1}", path, newFs.Name); } if (Directory.Exists(newFile)) { var newFiles = Directory.GetFiles(newFile); foreach (var i in newFiles) { return(ProcessFile(i, imgProcessor)); } } else { return(ProcessFile(newFile, imgProcessor)); } } } catch (Exception ex) { Logging.Logger.LogError("Error while decompressing", ex); } var entry = new PlotPOLCNTOutput(); Logging.Logger.LogInfo(string.Format("Processing File: {0}", path)); int euid = 0; var bc = ReadBarcode(path); if (!int.TryParse(bc, out euid)) { Logging.Logger.LogErrorFormat("Expected Euid in barcode, got: {0}", bc); Logging.Logger.LogInfo("Moving on to next file..."); return(null); } else { entry.EUID = euid; } Logging.Logger.LogInfo(string.Format("Finding circles:", path)); var bm = new Bitmap(path); var circles = imgProcessor.FindCircles(bm); var midPoint = bm.Width / 2; Logging.Logger.LogInfo(string.Format("Finding scores:", path)); var numFinder = new NumberFinder(); for (int i = 0; i < circles.Size; i++) { var circle = circles[i]; var score = numFinder.FindNumbers(circle, bm); if (circle.ToArray().All(x => x.X > midPoint)) { entry.POLCNT = score; } else { entry.Plot = score; } } return(entry); }