コード例 #1
0
        public CircleNode(int w, int h, GraphPixelType p = GraphPixelType.RGBA)
        {
            Name = "Circle";

            Id = Guid.NewGuid().ToString();

            Inputs = new List <NodeInput>();

            tileX = tileY = 1;

            previewProcessor = new BasicImageRenderer();

            processor = new CircleProcessor();

            outline = 0;

            internalPixelType = p;

            width  = w;
            height = h;

            Output = new NodeOutput(NodeType.Gray, this);

            radius = 1;

            Outputs = new List <NodeOutput>();
            Outputs.Add(Output);

            Process();
        }
コード例 #2
0
        public override void Dispose()
        {
            base.Dispose();

            if (processor != null)
            {
                processor.Release();
                processor = null;
            }
        }
コード例 #3
0
        public void CircleBOMBuilderTest()
        {
            // Arrange
            Circle circle = new Circle()
            {
                PositionX = 20,
                PositionY = 30,
                Diameter  = 40
            };
            string expectedBOM = "Circle(20,30) size=40";

            CircleProcessor processor = new CircleProcessor();

            // Act
            string returnedBOM = processor.BOMBuilder(circle);

            // Assert
            Assert.AreEqual(expectedBOM, returnedBOM);
        }
コード例 #4
0
        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);
                }
            }
        }
コード例 #5
0
        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);
                }
            }
        }
コード例 #6
0
ファイル: Worker.cs プロジェクト: taybartemes/CardScoring
        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);
        }