public void TestProcessChipResults()
        {
            var offset       = new SKPointI(300, 600);
            var observations = new[]
            {
                new Observation(_categoryManager.GetOrCreate(1, "Car"), 0.9, new SKRect(0.1f, 0.2f, 0.3f, 0.4f)),
                new Observation(_categoryManager.GetOrCreate(2, "Building"), 0.78, new SKRect(.2f, 0.3f, 0.5f, 0.8f))
            };

            PostProcessingService.ProcessChipResults(offset, observations);

            AssertUtils.AreEqualIEnumerable(new[]
            {
                new Observation(
                    _categoryManager.GetOrCreate(1, "Car"),
                    0.9,
                    new SKRect(offset.X + 0.1f * SharedConstants.DefaultChipWidth,
                               offset.Y + 0.2f * SharedConstants.DefaultChipHeight,
                               offset.X + 0.3f * SharedConstants.DefaultChipWidth,
                               offset.Y + 0.4f * SharedConstants.DefaultChipHeight)),
                new Observation(
                    _categoryManager.GetOrCreate(2, "Building"),
                    0.78,
                    new SKRect(offset.X + 0.2f * SharedConstants.DefaultChipWidth,
                               offset.Y + 0.3f * SharedConstants.DefaultChipHeight,
                               offset.X + 0.5f * SharedConstants.DefaultChipWidth,
                               offset.Y + 0.8f * SharedConstants.DefaultChipHeight)),
            },
                                            observations,
                                            AssertUtils.AreEqualObservation);
        }
Beispiel #2
0
        /// <summary>
        /// Analyzes the specified <see cref="Chip"/> using the machine learning model.
        /// </summary>
        /// <param name="chip">The specified <see cref="Chip"/> of default size.</param>
        /// <returns>A <see cref="CategoryManager"/> that contains all <see cref="Category"/>s and <see cref="Observation"/>s detected in the specified <see cref="Chip"/>.</returns>
        public static CategoryManager AnalyzeChip(Chip chip)
        {
            if (chip == null)
            {
                throw new ArgumentNullException();
            }

            try
            {
                using (var mlMultiArray = chip.ToMLMultiArray())
                    using (var model = new CoreMLModel())
                    {
                        var categoryManager = model.Predict(mlMultiArray);

                        var observations    = categoryManager.Observations;
                        var observationList = observations.ToList();
                        PostProcessingService.ProcessChipResults(chip.Region.Location, observationList);

                        return(categoryManager);
                    }
            }
            catch (FileNotFoundException)
            {
                return(new CategoryManager());
            }
        }